diff --git a/src/main/java/cr0s/warpdrive/block/energy/BlockIC2reactorLaserMonitor.java b/src/main/java/cr0s/warpdrive/block/energy/BlockIC2reactorLaserMonitor.java index 2a67b7a9..68016128 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/BlockIC2reactorLaserMonitor.java +++ b/src/main/java/cr0s/warpdrive/block/energy/BlockIC2reactorLaserMonitor.java @@ -1,27 +1,22 @@ package cr0s.warpdrive.block.energy; import cpw.mods.fml.common.FMLCommonHandler; -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import cr0s.warpdrive.WarpDrive; +import cr0s.warpdrive.block.BlockAbstractContainer; -public class BlockIC2reactorLaserMonitor extends BlockContainer { - public BlockIC2reactorLaserMonitor() { - super(Material.rock); - setHardness(0.5F); - setStepSound(Block.soundTypeMetal); - setCreativeTab(WarpDrive.creativeTabWarpDrive); - this.setBlockName("warpdrive.energy.IC2ReactorLaserMonitor"); - } +public class BlockIC2reactorLaserMonitor extends BlockAbstractContainer {// TODO BlockAbstractContainer + static IIcon[] iconBuffer = new IIcon[3]; - @Override - public void registerBlockIcons(IIconRegister par1IconRegister) { - blockIcon = par1IconRegister.registerIcon("warpdrive:energy/IC2reactorLaserMonitor"); + public BlockIC2reactorLaserMonitor() { + super(Material.iron); + setBlockName("warpdrive.energy.IC2ReactorLaserMonitor"); } @Override @@ -29,6 +24,37 @@ public class BlockIC2reactorLaserMonitor extends BlockContainer { return new TileEntityIC2reactorLaserMonitor(); } + @Override + public void registerBlockIcons(IIconRegister par1IconRegister) { + iconBuffer[0] = par1IconRegister.registerIcon("warpdrive:energy/IC2reactorLaserMonitorNotConnected"); + iconBuffer[1] = par1IconRegister.registerIcon("warpdrive:energy/IC2reactorLaserMonitorConnectedNotPowered"); + iconBuffer[2] = par1IconRegister.registerIcon("warpdrive:energy/IC2reactorLaserMonitorConnectedPowered"); + } + + @Override + public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { + int meta = world.getBlockMetadata(x, y, z); + TileEntity tileEntity = world.getTileEntity(x, y, z); + if (tileEntity == null || !(tileEntity instanceof TileEntityIC2reactorLaserMonitor)) { + return iconBuffer[0]; + } + + if (((TileEntityIC2reactorLaserMonitor)tileEntity).isSideActive(side)) { + if ((meta & 8) == 0) { + return iconBuffer[1]; + } else { + return iconBuffer[2]; + } + } + + return iconBuffer[0]; + } + + @Override + public IIcon getIcon(int side, int metadata) { + return iconBuffer[1]; + } + /** * Called upon block activation (right click on the block.) */ diff --git a/src/main/java/cr0s/warpdrive/block/energy/TileEntityIC2reactorLaserMonitor.java b/src/main/java/cr0s/warpdrive/block/energy/TileEntityIC2reactorLaserMonitor.java index e44fa0f3..4cf216ab 100644 --- a/src/main/java/cr0s/warpdrive/block/energy/TileEntityIC2reactorLaserMonitor.java +++ b/src/main/java/cr0s/warpdrive/block/energy/TileEntityIC2reactorLaserMonitor.java @@ -8,6 +8,9 @@ import java.util.Set; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraft.network.play.server.S35PacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChunkCoordinates; import net.minecraftforge.common.util.ForgeDirection; @@ -21,6 +24,8 @@ import cr0s.warpdrive.network.PacketHandler; public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy { private int ticks = WarpDriveConfig.IC2_REACTOR_COOLING_INTERVAL_TICKS; + private byte activeSides = 0; + private boolean updateFlag = false; public TileEntityIC2reactorLaserMonitor() { super(); @@ -31,12 +36,26 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy { private static int[] deltaX = {-2, 2, 0, 0, 0, 0}; private static int[] deltaY = { 0, 0,-2, 2, 0, 0}; private static int[] deltaZ = { 0, 0, 0, 0,-2, 2}; + private static byte[] deltaSides = { 1, 2, 4, 8, 16, 32 }; + + protected boolean isSideActive(int side) { + switch (side) { + case 4: return (deltaSides[0] & activeSides) != 0; + case 5: return (deltaSides[1] & activeSides) != 0; + case 0: return (deltaSides[2] & activeSides) != 0; + case 1: return (deltaSides[3] & activeSides) != 0; + case 2: return (deltaSides[4] & activeSides) != 0; + case 3: return (deltaSides[5] & activeSides) != 0; + default: return false; + } + } // returns IReactor tile entities @Optional.Method(modid = "IC2") private Set findReactors() { Set output = new HashSet(); + byte newActiveSides = 0; for(int i = 0; i < deltaX.length; i++) { TileEntity tileEntity = worldObj.getTileEntity(xCoord + deltaX[i], yCoord + deltaY[i], zCoord + deltaZ[i]); if (tileEntity == null) { @@ -44,6 +63,7 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy { } if (tileEntity instanceof IReactor) { + newActiveSides |= deltaSides[i]; output.add((IReactor)tileEntity); } else if (tileEntity instanceof IReactorChamber) { @@ -60,9 +80,14 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy { continue; } + newActiveSides |= deltaSides[i]; output.add(reactor); } } + if (activeSides != newActiveSides) { + updateFlag = !updateFlag; + activeSides = newActiveSides; + } return output; } @@ -103,6 +128,7 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy { ticks = WarpDriveConfig.IC2_REACTOR_COOLING_INTERVAL_TICKS; Vector3 myPos = new Vector3(this).translate(0.5); Set reactors = findReactors(); + setMetadata(); if (reactors.size() == 0) { return; } @@ -115,14 +141,39 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy { } } + private void setMetadata() { + int metadata = (updateFlag ? 0 : 1) | (activeSides != 0 ? 2 : 0); + if (getEnergyStored() >= WarpDriveConfig.IC2_REACTOR_ENERGY_PER_HEAT) { + metadata |= 8; + } + if (getBlockMetadata() != metadata) { + worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 3); + } + } + @Override public void writeToNBT(NBTTagCompound tag) { super.writeToNBT(tag); + tag.setByte("activeSides", activeSides); } @Override public void readFromNBT(NBTTagCompound tag) { super.readFromNBT(tag); + activeSides = tag.getByte("activeSides"); + } + + @Override + public Packet getDescriptionPacket() { + NBTTagCompound tagCompound = new NBTTagCompound(); + writeToNBT(tagCompound); + return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tagCompound); + } + + @Override + public void onDataPacket(NetworkManager networkManager, S35PacketUpdateTileEntity packet) { + NBTTagCompound tag = packet.func_148857_g(); + readFromNBT(tag); } @Override @@ -130,8 +181,8 @@ public class TileEntityIC2reactorLaserMonitor extends TileEntityAbstractEnergy { public String getStatus() { Set reactors = findReactors(); return getBlockType().getLocalizedName() - + String.format(" energy level is %.0f/%.0f EU.", convertInternalToEU(getEnergyStored()), convertInternalToEU(getMaxEnergyStored())) - + ((reactors == null || reactors.size() == 0) ? " No reactor found!" : " " + reactors.size() + " reactor(s) connected."); + + String.format("\nEnergy level is %.0f/%.0f EU.", convertInternalToEU(getEnergyStored()), convertInternalToEU(getMaxEnergyStored())) + + "\n" + ((reactors == null || reactors.size() == 0) ? "No reactor found!" : reactors.size() + " reactor(s) connected."); } @Override diff --git a/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitor.png b/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitor.png deleted file mode 100644 index 40d4b62a..00000000 Binary files a/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitor.png and /dev/null differ diff --git a/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorConnectedNotPowered.png b/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorConnectedNotPowered.png new file mode 100644 index 00000000..56311a9a Binary files /dev/null and b/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorConnectedNotPowered.png differ diff --git a/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorConnectedPowered.png b/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorConnectedPowered.png new file mode 100644 index 00000000..69f1436c Binary files /dev/null and b/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorConnectedPowered.png differ diff --git a/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorNotConnected.png b/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorNotConnected.png new file mode 100644 index 00000000..364e1f86 Binary files /dev/null and b/src/main/resources/assets/warpdrive/textures/blocks/energy/IC2reactorLaserMonitorNotConnected.png differ diff --git a/wiki/IC2reactorLaser.png b/wiki/IC2reactorLaser.png new file mode 100644 index 00000000..3d966c85 Binary files /dev/null and b/wiki/IC2reactorLaser.png differ