fix crash on explosion in machines
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package storagecraft.tile;
|
package storagecraft.tile;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import storagecraft.block.BlockMachine;
|
import storagecraft.block.BlockMachine;
|
||||||
@@ -14,27 +15,32 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
|
|
||||||
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
private RedstoneMode redstoneMode = RedstoneMode.IGNORE;
|
||||||
|
|
||||||
private BlockPos controllerPos;
|
private BlockPos controllerPosition;
|
||||||
|
|
||||||
|
private Block originalBlock;
|
||||||
|
|
||||||
public void onConnected(TileController controller)
|
public void onConnected(TileController controller)
|
||||||
|
{
|
||||||
|
if (worldObj.getBlockState(pos).getBlock() == originalBlock)
|
||||||
{
|
{
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
connected = true;
|
connected = true;
|
||||||
|
|
||||||
controllerPos = controller.getPos();
|
|
||||||
|
|
||||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, true));
|
||||||
|
|
||||||
|
controllerPosition = controller.getPos();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDisconnected()
|
public void onDisconnected()
|
||||||
|
{
|
||||||
|
if (worldObj.getBlockState(pos).getBlock() == originalBlock)
|
||||||
{
|
{
|
||||||
markDirty();
|
markDirty();
|
||||||
|
|
||||||
connected = false;
|
connected = false;
|
||||||
|
|
||||||
if (!worldObj.isAirBlock(pos))
|
|
||||||
{
|
|
||||||
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
|
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,6 +48,11 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
|
if (ticks == 0)
|
||||||
|
{
|
||||||
|
originalBlock = worldObj.getBlockState(pos).getBlock();
|
||||||
|
}
|
||||||
|
|
||||||
super.update();
|
super.update();
|
||||||
|
|
||||||
if (!worldObj.isRemote && isConnected())
|
if (!worldObj.isRemote && isConnected())
|
||||||
@@ -86,7 +97,7 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
|
|
||||||
public TileController getController()
|
public TileController getController()
|
||||||
{
|
{
|
||||||
return (TileController) worldObj.getTileEntity(controllerPos);
|
return (TileController) worldObj.getTileEntity(controllerPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -98,7 +109,7 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
|
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
controllerPos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
|
controllerPosition = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
redstoneMode = RedstoneMode.getById(buf.readInt());
|
redstoneMode = RedstoneMode.getById(buf.readInt());
|
||||||
@@ -116,9 +127,9 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed
|
|||||||
|
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
buf.writeInt(controllerPos.getX());
|
buf.writeInt(controllerPosition.getX());
|
||||||
buf.writeInt(controllerPos.getY());
|
buf.writeInt(controllerPosition.getY());
|
||||||
buf.writeInt(controllerPos.getZ());
|
buf.writeInt(controllerPosition.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.writeInt(redstoneMode.id);
|
buf.writeInt(redstoneMode.id);
|
||||||
|
|||||||
Reference in New Issue
Block a user