Skip to content

Commit

Permalink
fix crash on explosion in machines
Browse files Browse the repository at this point in the history
  • Loading branch information
raoulvdberge committed Feb 3, 2016
1 parent eadfc09 commit 4d5dd6f
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/main/java/storagecraft/tile/TileMachine.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package storagecraft.tile;

import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.BlockPos;
import storagecraft.block.BlockMachine;
Expand All @@ -14,34 +15,44 @@ public abstract class TileMachine extends TileBase implements INetworkTile, IRed

private RedstoneMode redstoneMode = RedstoneMode.IGNORE;

private BlockPos controllerPos;
private BlockPos controllerPosition;

private Block originalBlock;

public void onConnected(TileController controller)
{
markDirty();
if (worldObj.getBlockState(pos).getBlock() == originalBlock)
{
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()
{
markDirty();
if (worldObj.getBlockState(pos).getBlock() == originalBlock)
{
markDirty();

connected = false;
connected = false;

if (!worldObj.isAirBlock(pos))
{
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockMachine.CONNECTED, false));
}
}

@Override
public void update()
{
if (ticks == 0)
{
originalBlock = worldObj.getBlockState(pos).getBlock();
}

super.update();

if (!worldObj.isRemote && isConnected())
Expand Down Expand Up @@ -86,7 +97,7 @@ public BlockPos getTilePos()

public TileController getController()
{
return (TileController) worldObj.getTileEntity(controllerPos);
return (TileController) worldObj.getTileEntity(controllerPosition);
}

@Override
Expand All @@ -98,7 +109,7 @@ public void fromBytes(ByteBuf buf)

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());
Expand All @@ -116,9 +127,9 @@ public void toBytes(ByteBuf buf)

if (connected)
{
buf.writeInt(controllerPos.getX());
buf.writeInt(controllerPos.getY());
buf.writeInt(controllerPos.getZ());
buf.writeInt(controllerPosition.getX());
buf.writeInt(controllerPosition.getY());
buf.writeInt(controllerPosition.getZ());
}

buf.writeInt(redstoneMode.id);
Expand Down

0 comments on commit 4d5dd6f

Please sign in to comment.