Skip to content

Commit

Permalink
Added diagnostics code to conduit neighbor updating
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryLoenwind committed Dec 28, 2016
1 parent 968f989 commit abab279
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.List;

import crazypants.enderio.Log;
import net.minecraft.block.state.IBlockState;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
Expand Down Expand Up @@ -83,14 +84,45 @@ public List<I> getConduits() {
}

public void sendBlockUpdatesForEntireNetwork() {
for (I con : conduits) {
long[] times = new long[conduits.size()];
try {
for (int i = 0; i < conduits.size(); i++) {
times[i] = System.nanoTime();
I con = conduits.get(i);
TileEntity te = con.getBundle().getEntity();
if (te.getWorld().isBlockLoaded(te.getPos())) {
IBlockState bs = te.getWorld().getBlockState(te.getPos());
te.getWorld().notifyBlockUpdate(te.getPos(), bs, bs, 3);
te.getWorld().notifyNeighborsOfStateChange(te.getPos(), te.getBlockType());
}
}
} catch (Error e) { // Watchdog?
try {
diagnostics(times);
} catch (Throwable t) {
// prefer to throw the original error
}
throw e;
}
}

private void diagnostics(long[] times) {
long end = System.nanoTime();
Log.error("Conduit network " + this.getClass() + " interrupted while notifying neighbors of changes");
for (int i = times.length - 1; i >= 0; i--) {
if (times[i] != 0) {
long tmp = times[i];
times[i] = end - times[i];
end = tmp;
}
}
for (int i = 0; i < conduits.size(); i++) {
if (times[i] != 0) {
I con = conduits.get(i);
TileEntity te = con.getBundle().getEntity();
Log.error("Updating neigbors at " + te.getPos() + " took " + times[i] + "ns");
}
}
}

@Override
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/crazypants/enderio/conduit/BlockConduitBundle.java
Expand Up @@ -896,17 +896,21 @@ private RaytraceResult getHitForConduitType(List<RaytraceResult> all, Class<? ex
@Deprecated
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block neighborBlock) {
TileConduitBundle conduit = getTileEntity(world, pos);
if (conduit != null) {
conduit.onNeighborBlockChange(neighborBlock);
if (neighborBlock != this) {
TileConduitBundle conduit = getTileEntity(world, pos);
if (conduit != null) {
conduit.onNeighborBlockChange(neighborBlock);
}
}
}

@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor) {
TileConduitBundle conduit = getTileEntity(world, pos);
if (conduit != null) {
conduit.onNeighborChange(world, pos, neighbor);
if (world.getBlockState(neighbor).getBlock() != this) {
TileConduitBundle conduit = getTileEntity(world, pos);
if (conduit != null) {
conduit.onNeighborChange(world, pos, neighbor);
}
}
}

Expand Down

0 comments on commit abab279

Please sign in to comment.