diff --git a/src/main/java/com/hbm/blocks/machine/ReactorZirnox.java b/src/main/java/com/hbm/blocks/machine/ReactorZirnox.java index b9b448ef5..1316a02eb 100644 --- a/src/main/java/com/hbm/blocks/machine/ReactorZirnox.java +++ b/src/main/java/com/hbm/blocks/machine/ReactorZirnox.java @@ -9,6 +9,7 @@ import com.hbm.tileentity.TileEntityProxyCombo; import com.hbm.tileentity.machine.TileEntityReactorZirnox; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.entity.player.EntityPlayer; @@ -39,7 +40,7 @@ public class ReactorZirnox extends BlockDummyable { return true; } else if(!player.isSneaking()) { BossSpawnHandler.markFBI(player); - + int[] pos = this.findCore(world, x, y, z); if(pos == null) @@ -54,7 +55,7 @@ public class ReactorZirnox extends BlockDummyable { @Override public int[] getDimensions() { - return new int[] {1, 0, 2, 2, 2, 2,}; + return new int[] {1, 0, 2, 2, 2, 2,}; } @Override @@ -87,4 +88,43 @@ public class ReactorZirnox extends BlockDummyable { this.makeExtra(world, x + dir.offsetX * o, y + 4, z + dir.offsetZ * o); } -} \ No newline at end of file + @Override + public void onNeighborBlockChange(World world, int x, int y, int z, Block neighbor) { + super.onNeighborBlockChange(world, x, y, z, neighbor); + if (world.isRemote) return; + int[] core = this.findCore(world, x, y, z); + if (core == null) return; + int cx = core[0]; + int cy = core[1]; + int cz = core[2]; + TileEntity te = world.getTileEntity(cx, cy, cz); + if (!(te instanceof TileEntityReactorZirnox)) return; + TileEntityReactorZirnox reactor = (TileEntityReactorZirnox) te; + boolean powered = false; + // 2. Scan multiblock + for (int dx = -2; dx <= 2 && !powered; dx++) { + for (int dy = 0; dy <= 4 && !powered; dy++) { + for (int dz = -2; dz <= 2 && !powered; dz++) { + // Get only surface blocks + if (dx == -2 || dx == 2 || + dy == 0 || dy == 4 || + dz == -2 || dz == 2) { + + int sx = cx + dx; + int sy = cy + dy; + int sz = cz + dz; + + if (world.isBlockIndirectlyGettingPowered(sx, sy, sz) || + world.getBlockPowerInput(sx, sy, sz) > 0) { + + powered = true; + break; + } + } + } + } + } + reactor.setRedstonePowered(powered); + } + +} diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityReactorZirnox.java b/src/main/java/com/hbm/tileentity/machine/TileEntityReactorZirnox.java index a7ec9973f..fe412b503 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityReactorZirnox.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityReactorZirnox.java @@ -53,6 +53,7 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC public int heat; public static final int maxHeat = 100000; + public boolean redstonePowered = false; public int pressure; public static final int maxPressure = 100000; public boolean isOn = false; @@ -85,6 +86,12 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC carbonDioxide = new FluidTank(Fluids.CARBONDIOXIDE, 16000); water = new FluidTank(Fluids.WATER, 32000); } + public void setRedstonePowered(boolean powered) { + if (!powered && this.redstonePowered) { + isOn = false; + } + this.redstonePowered = powered; + } @Override public String getName() { @@ -115,6 +122,7 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC steam.readFromNBT(nbt, "steam"); carbonDioxide.readFromNBT(nbt, "carbondioxide"); water.readFromNBT(nbt, "water"); + redstonePowered = nbt.getBoolean("redstonePowered"); } @Override @@ -126,6 +134,7 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC steam.writeToNBT(nbt, "steam"); carbonDioxide.writeToNBT(nbt, "carbondioxide"); water.writeToNBT(nbt, "water"); + nbt.setBoolean("redstonePowered", redstonePowered); } @@ -176,7 +185,9 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC public void updateEntity() { if(!worldObj.isRemote) { - + if (redstonePowered) { + isOn = true; + } this.output = 0; if(worldObj.getTotalWorldTime() % 20 == 0) { @@ -228,6 +239,7 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC buf.writeInt(this.heat); buf.writeInt(this.pressure); buf.writeBoolean(this.isOn); + buf.writeBoolean(this.redstonePowered); steam.serialize(buf); carbonDioxide.serialize(buf); water.serialize(buf); @@ -239,6 +251,7 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC this.heat = buf.readInt(); this.pressure = buf.readInt(); this.isOn = buf.readBoolean(); + this.redstonePowered = buf.readBoolean(); steam.deserialize(buf); carbonDioxide.deserialize(buf); water.deserialize(buf); @@ -429,7 +442,7 @@ public class TileEntityReactorZirnox extends TileEntityMachineBase implements IC @Override public void receiveControl(NBTTagCompound data) { - if(data.hasKey("control")) { + if(data.hasKey("control") && !redstonePowered) { this.isOn = !this.isOn; }