Skip to content

Commit

Permalink
Prevent ghostloading (#116)
Browse files Browse the repository at this point in the history
* prevent ghostloading by MEConduit

* prevent more ghostloading by MEConduit

* spottlessApply

* prevent ghostloading by ConduitUtil

---------

Co-authored-by: Pilzinsel64 <[email protected]>
  • Loading branch information
Dream-Master and Pilzinsel64 authored Mar 29, 2023
1 parent 4e40230 commit 985b0f1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/crazypants/enderio/conduit/ConduitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public static <T extends IConduit> T getConduit(World world, TileEntity te, Forg

public static <T extends IConduit> Collection<T> getConnectedConduits(World world, int x, int y, int z,
Class<T> type) {
TileEntity te = world.getTileEntity(x, y, z);
TileEntity te = world.blockExists(x, y, z) ? world.getTileEntity(x, y, z) : null;
if (!(te instanceof IConduitBundle)) {
return Collections.emptyList();
}
Expand Down
24 changes: 21 additions & 3 deletions src/main/java/crazypants/enderio/conduit/me/MEConduit.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,16 @@ public int getChannelsInUse() {
public boolean canConnectToExternal(ForgeDirection dir, boolean ignoreDisabled) {
World world = getBundle().getWorld();
BlockCoord pos = getLocation();
TileEntity te = world.getTileEntity(pos.x + dir.offsetX, pos.y + dir.offsetY, pos.z + dir.offsetZ);

final int exactPosX = pos.x + dir.offsetX;
final int exactPosY = pos.y + dir.offsetY;
final int exactPosZ = pos.z + dir.offsetZ;

if (!world.blockExists(exactPosX, exactPosY, exactPosZ)) {
return false;
}

TileEntity te = world.getTileEntity(exactPosX, exactPosY, exactPosZ);

if (te instanceof TileConduitBundle) {
return false;
Expand Down Expand Up @@ -305,7 +314,11 @@ public boolean onBlockActivated(EntityPlayer player, RaytraceResult res, List<Ra
private void onNodeChanged(BlockCoord location) {
World world = getBundle().getWorld();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = location.getLocation(dir).getTileEntity(world);
BlockCoord dirLocation = location.getLocation(dir);
TileEntity te = null;
if (world.blockExists(dirLocation.x, dirLocation.y, dirLocation.z)) {
te = location.getLocation(dir).getTileEntity(world);
}
if (te != null && te instanceof IGridHost && !(te instanceof IConduitBundle)) {
IGridNode node = ((IGridHost) te).getGridNode(ForgeDirection.UNKNOWN);
if (node == null) {
Expand All @@ -321,7 +334,12 @@ private void onNodeChanged(BlockCoord location) {
@Override
public void onAddedToBundle() {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity te = getLocation().getLocation(dir).getTileEntity(getBundle().getWorld());
World world = getBundle().getWorld();
BlockCoord dirLocation = getLocation().getLocation(dir);
TileEntity te = null;
if (world.blockExists(dirLocation.x, dirLocation.y, dirLocation.z)) {
te = dirLocation.getTileEntity(world);
}
if (te instanceof TileConduitBundle) {
IMEConduit cond = ((TileConduitBundle) te).getConduit(IMEConduit.class);
if (cond != null) {
Expand Down

0 comments on commit 985b0f1

Please sign in to comment.