Correctly save stuff, should work for Funky Locomotion integration

This commit is contained in:
Raoul Van den Berge
2016-11-05 16:49:45 +01:00
parent 556e6d4e3a
commit f6b983f0b4
11 changed files with 68 additions and 81 deletions

View File

@@ -80,7 +80,7 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
continue;
}
if (!(tile instanceof INetworkNode)) {
if (!(tile instanceof INetworkNode) || (tile != null && tile.isInvalid())) {
continue;
}

View File

@@ -270,35 +270,13 @@ public class BlockCable extends BlockCoverable {
if (getPlacementType() != null) {
((TileBase) world.getTileEntity(pos)).setDirection(state.getValue(DIRECTION));
}
attemptConnect(world, pos);
}
public void attemptConnect(World world, BlockPos pos) {
if (!world.isRemote) {
for (EnumFacing facing : EnumFacing.VALUES) {
TileEntity tile = world.getTileEntity(pos.offset(facing));
if (tile instanceof TileNode && ((TileNode) tile).isConnected()) {
((TileNode) tile).getNetwork().getNodeGraph().rebuild();
break;
}
}
}
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
INetworkMaster network = null;
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileNode) {
network = ((TileNode) tile).getNetwork();
}
if (tile instanceof TileBase && ((TileBase) tile).getDrops() != null) {
IItemHandler handler = ((TileBase) tile).getDrops();
@@ -311,10 +289,6 @@ public class BlockCable extends BlockCoverable {
}
super.breakBlock(world, pos, state);
if (network != null) {
network.getNodeGraph().rebuild();
}
}
@Override

View File

@@ -102,15 +102,6 @@ public class BlockController extends BlockBase {
super.onBlockPlacedBy(world, pos, state, player, stack);
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
if (!world.isRemote) {
((TileController) world.getTileEntity(pos)).onDestroyed();
}
super.breakBlock(world, pos, state);
}
@Override
@SuppressWarnings("deprecation")
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block) {

View File

@@ -1,17 +1,11 @@
package com.raoulvdberge.refinedstorage.block;
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.tile.TileNode;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public abstract class BlockNode extends BlockBase {
public static final PropertyBool CONNECTED = PropertyBool.create("connected");
@@ -50,42 +44,6 @@ public abstract class BlockNode extends BlockBase {
return super.getActualState(state, world, pos);
}
@Override
public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack) {
super.onBlockPlacedBy(world, pos, state, player, stack);
if (!world.isRemote) {
for (EnumFacing facing : EnumFacing.VALUES) {
TileEntity tile = world.getTileEntity(pos.offset(facing));
if (tile instanceof TileNode && ((TileNode) tile).isConnected()) {
((TileNode) tile).getNetwork().getNodeGraph().rebuild();
break;
}
}
}
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
INetworkMaster network = null;
if (!world.isRemote) {
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileNode) {
network = ((TileNode) tile).getNetwork();
}
}
super.breakBlock(world, pos, state);
if (network != null) {
network.getNodeGraph().rebuild();
}
}
public boolean hasConnectivityState() {
return false;
}

View File

@@ -327,6 +327,10 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
super.invalidate();
energyEU.invalidate();
if (!worldObj.isRemote) {
onBreak();
}
}
@Override
@@ -351,7 +355,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
energyEU.onChunkUnload();
}
public void onDestroyed() {
public void onBreak() {
nodeGraph.disconnectAll();
}

View File

@@ -241,6 +241,13 @@ public class TileDiskDrive extends TileNode implements IItemStorageProvider, IFl
}
}
@Override
public void invalidate() {
onBreak();
super.invalidate();
}
@Override
public void onConnectionChange(INetworkMaster network, boolean state) {
super.onConnectionChange(network, state);

View File

@@ -613,4 +613,11 @@ public class TileDiskManipulator extends TileNode implements IComparable, IFilte
}
}
}
@Override
public void invalidate() {
onBreak();
super.invalidate();
}
}

View File

@@ -124,6 +124,13 @@ public class TileFluidStorage extends TileNode implements IFluidStorageProvider,
}
}
@Override
public void invalidate() {
onBreak();
super.invalidate();
}
@Override
public void onConnectionChange(INetworkMaster network, boolean state) {
super.onConnectionChange(network, state);

View File

@@ -1,6 +1,5 @@
package com.raoulvdberge.refinedstorage.tile;
import com.raoulvdberge.refinedstorage.RSBlocks;
import mcmultipart.capabilities.ISlottedCapabilityProvider;
import mcmultipart.capabilities.MultipartCapabilityHelper;
import mcmultipart.microblock.IMicroblock;
@@ -72,7 +71,7 @@ public abstract class TileMultipartNode extends TileNode implements IMicroblockC
if (network != null) {
network.getNodeGraph().rebuild();
} else if (worldObj != null) {
RSBlocks.CABLE.attemptConnect(worldObj, pos);
rebuildNearbyGraph();
}
}

View File

@@ -28,6 +28,7 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
protected INetworkMaster network;
protected boolean rebuildOnUpdateChange;
private boolean rebuildNearbyGraph;
public TileNode() {
dataManager.addWatchedParameter(REDSTONE_MODE);
@@ -57,6 +58,10 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
}
networkPos = null;
} else if (rebuildNearbyGraph) {
rebuildNearbyGraph = false;
rebuildNearbyGraph();
}
if (update != canUpdate() && network != null) {
@@ -83,6 +88,18 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
super.update();
}
protected void rebuildNearbyGraph() {
for (EnumFacing facing : EnumFacing.VALUES) {
TileEntity tile = worldObj.getTileEntity(pos.offset(facing));
if (tile instanceof TileNode && ((TileNode) tile).isConnected()) {
((TileNode) tile).getNetwork().getNodeGraph().rebuild();
break;
}
}
}
@Override
public void onConnected(INetworkMaster network) {
this.connected = true;
@@ -201,4 +218,20 @@ public abstract class TileNode extends TileBase implements INetworkNode, IRedsto
public boolean hasConnectivityState() {
return false;
}
@Override
public void invalidate() {
super.invalidate();
if (!worldObj.isRemote && network != null) {
network.getNodeGraph().rebuild();
}
}
@Override
public void validate() {
super.validate();
rebuildNearbyGraph = true;
}
}

View File

@@ -125,6 +125,13 @@ public class TileStorage extends TileNode implements IItemStorageProvider, IStor
}
}
@Override
public void invalidate() {
onBreak();
super.invalidate();
}
@Override
public void onConnectionChange(INetworkMaster network, boolean state) {
super.onConnectionChange(network, state);