Fixes #155 "External Storage disconnecting on world reload"

This commit is contained in:
Raoul Van den Berge
2016-07-05 17:05:21 +02:00
parent f1a03b226e
commit b3aa078f56
5 changed files with 17 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
### 0.8.6 ### 0.8.6
**Bugfixes** **Bugfixes**
- Fixed External Storage disconnecting on world reload
- Huge performance improvements to large networks - Huge performance improvements to large networks
### 0.8.5 ### 0.8.5

View File

@@ -245,6 +245,7 @@ public final class RefinedStorageUtils {
} }
public static void updateBlock(World world, BlockPos pos) { public static void updateBlock(World world, BlockPos pos) {
System.out.println("Updating block @ " + pos);
world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 1 | 2); world.notifyBlockUpdate(pos, world.getBlockState(pos), world.getBlockState(pos), 1 | 2);
} }

View File

@@ -98,8 +98,6 @@ public class BlockController extends BlockBase {
if (tag != null && tag.hasKey(TileController.NBT_ENERGY)) { if (tag != null && tag.hasKey(TileController.NBT_ENERGY)) {
controller.getEnergy().receiveEnergy(tag.getInteger(TileController.NBT_ENERGY), false); controller.getEnergy().receiveEnergy(tag.getInteger(TileController.NBT_ENERGY), false);
} }
controller.rebuildNodes();
} }
super.onBlockPlacedBy(world, pos, state, player, stack); super.onBlockPlacedBy(world, pos, state, player, stack);
@@ -108,7 +106,7 @@ public class BlockController extends BlockBase {
@Override @Override
public void breakBlock(World world, BlockPos pos, IBlockState state) { public void breakBlock(World world, BlockPos pos, IBlockState state) {
if (!world.isRemote) { if (!world.isRemote) {
((TileController) world.getTileEntity(pos)).onBreak(); ((TileController) world.getTileEntity(pos)).disconnectAll();
} }
super.breakBlock(world, pos, state); super.breakBlock(world, pos, state);

View File

@@ -195,7 +195,11 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
if (couldRun != canRun()) { if (couldRun != canRun()) {
couldRun = canRun(); couldRun = canRun();
worldObj.notifyNeighborsOfStateChange(pos, RefinedStorageBlocks.CONTROLLER); if (!couldRun && !nodes.isEmpty()) {
disconnectAll();
} else if (couldRun) {
rebuildNodes();
}
} }
if (getEnergyScaledForDisplay() != lastEnergyDisplay) { if (getEnergyScaledForDisplay() != lastEnergyDisplay) {
@@ -214,10 +218,12 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
super.update(); super.update();
} }
public void onBreak() { public void disconnectAll() {
for (INetworkNode node : nodes) { for (INetworkNode node : nodes) {
node.onDisconnected(); node.onDisconnected();
} }
nodes.clear();
} }
@Override @Override
@@ -376,6 +382,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
@Override @Override
public void rebuildNodes() { public void rebuildNodes() {
System.out.println("Rebuilding Nodes");
List<INetworkNode> newNodes = new ArrayList<INetworkNode>(); List<INetworkNode> newNodes = new ArrayList<INetworkNode>();
Set<BlockPos> newNodesPos = new HashSet<BlockPos>(); Set<BlockPos> newNodesPos = new HashSet<BlockPos>();

View File

@@ -61,13 +61,15 @@ public class TileExternalStorage extends TileNode implements IStorageProvider, I
@Override @Override
public void update() { public void update() {
super.update(); if (ticks == 0) {
updateStorage();
if (getFacingTile() instanceof IDrawerGroup && lastDrawerCount != ((IDrawerGroup) getFacingTile()).getDrawerCount()) { } else if (getFacingTile() instanceof IDrawerGroup && lastDrawerCount != ((IDrawerGroup) getFacingTile()).getDrawerCount()) {
lastDrawerCount = ((IDrawerGroup) getFacingTile()).getDrawerCount(); lastDrawerCount = ((IDrawerGroup) getFacingTile()).getDrawerCount();
updateStorage(); updateStorage();
} }
super.update();
} }
@Override @Override