diff --git a/assets/hbm/lang/de_DE.lang b/assets/hbm/lang/de_DE.lang index 8522d7765..97cf58d78 100644 --- a/assets/hbm/lang/de_DE.lang +++ b/assets/hbm/lang/de_DE.lang @@ -233,6 +233,7 @@ container.nukePrototype=Der Prototyp container.nukeCustom=Anpassbare Bombe container.nukeSolinium=Die Blauspülung container.nukeN2=N²-Mine +container.nukeN45=N45 Seemine container.bombMulti=Mehrzweckbombe @@ -246,6 +247,7 @@ tile.nuke_prototype.name=Der Prototyp tile.nuke_custom.name=Anpassbare Bombe tile.nuke_solinium.name=Die Blauspülung tile.nuke_n2.name=N²-Mine +tile.nuke_n45.name=N45 Seemine tile.turret_light.name=Leichtes MG-Geschütz tile.turret_heavy.name=Schweres MG-Geschütz @@ -318,6 +320,7 @@ container.uf6_tank=UF6 Tank tile.machine_puf6_tank.name=Plutoniumhexafluorit-Tank container.puf6_tank=PuF6 Tank tile.machine_reactor.name=Brutreaktor +tile.machine_reactor_on.name=Brutreaktor container.reactor=Brutreaktor tile.machine_nuke_furnace_off.name=Atombetriebener Ofen tile.machine_nuke_furnace_on.name=Atombetriebener Ofen @@ -624,6 +627,7 @@ item.mechanism_rifle_2.name=Fortgeschrittener Gewehmechanismus item.mechanism_launcher_1.name=Werfermechanismus item.mechanism_launcher_2.name=Fortgeschrittener Werfermechanismus item.mechanism_special.name=High-Tech Waffenmechanismus + item.primer_357.name=.357 Magnum-Zündhütchen (x16) item.primer_44.name=.44 Magnum-Zündhütchen (x16) item.primer_9.name=Kleinkaliber-Zündhütchen (x24) @@ -1879,4 +1883,5 @@ tile.cheater_virus.name=Geliertes Euphemium tile.cheater_virus_seed.name=Instabiler Euphemiumschrabid-Block item.mysteryshovel.name=Brüchiger Spaten +tile.ntm_dirt.name=Erde item.memory.name=item.null.name \ No newline at end of file diff --git a/assets/hbm/lang/en_US.lang b/assets/hbm/lang/en_US.lang index 27f8634dc..0485935b0 100644 --- a/assets/hbm/lang/en_US.lang +++ b/assets/hbm/lang/en_US.lang @@ -320,6 +320,7 @@ container.uf6_tank=UF6 Tank tile.machine_puf6_tank.name=Plutonium Hexafluoride Tank container.puf6_tank=PuF6 Tank tile.machine_reactor.name=Breeding Reactor +tile.machine_reactor_on.name=Breeding Reactor container.reactor=Breeding Reactor tile.machine_nuke_furnace_off.name=Nuclear Powered Furnace tile.machine_nuke_furnace_on.name=Nuclear Powered Furnace diff --git a/com/hbm/blocks/ModBlocks.java b/com/hbm/blocks/ModBlocks.java index 7385067d0..0c34ba6a4 100644 --- a/com/hbm/blocks/ModBlocks.java +++ b/com/hbm/blocks/ModBlocks.java @@ -509,6 +509,9 @@ public class ModBlocks { public static Block machine_reactor_small; public static final int guiID_reactor_small = 65; + public static Block machine_controller; + public static final int guiID_machine_controller = 78; + public static Block machine_spp_bottom; public static Block machine_spp_top; @@ -976,6 +979,7 @@ public class ModBlocks { machine_press = new MachinePress(Material.iron).setBlockName("machine_press").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":machine_press"); machine_selenium = new MachineSeleniumEngine(Material.iron).setBlockName("machine_selenium").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":machine_selenium"); machine_reactor_small = new MachineReactorSmall(Material.iron).setBlockName("machine_reactor_small").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":machine_reactor_small"); + machine_controller = new MachineReactorControl(Material.iron).setBlockName("machine_controller").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":code"); machine_boiler_off = new MachineBoiler(false).setBlockName("machine_boiler_off").setHardness(5.0F).setResistance(10.0F).setCreativeTab(MainRegistry.machineTab).setBlockTextureName(RefStrings.MODID + ":machine_boiler_off"); machine_boiler_on = new MachineBoiler(true).setBlockName("machine_boiler_on").setHardness(5.0F).setResistance(10.0F).setLightLevel(1.0F).setCreativeTab(null).setBlockTextureName(RefStrings.MODID + ":machine_boiler_on"); @@ -1327,6 +1331,7 @@ public class ModBlocks { GameRegistry.registerBlock(machine_diesel, machine_diesel.getUnlocalizedName()); GameRegistry.registerBlock(machine_selenium, machine_selenium.getUnlocalizedName()); GameRegistry.registerBlock(machine_generator, machine_generator.getUnlocalizedName()); + GameRegistry.registerBlock(machine_controller, machine_controller.getUnlocalizedName()); GameRegistry.registerBlock(machine_reactor_small, machine_reactor_small.getUnlocalizedName()); GameRegistry.registerBlock(machine_industrial_generator, machine_industrial_generator.getUnlocalizedName()); GameRegistry.registerBlock(machine_radgen, machine_radgen.getUnlocalizedName()); diff --git a/com/hbm/blocks/machine/MachineReactorControl.java b/com/hbm/blocks/machine/MachineReactorControl.java new file mode 100644 index 000000000..bbe0474af --- /dev/null +++ b/com/hbm/blocks/machine/MachineReactorControl.java @@ -0,0 +1,52 @@ +package com.hbm.blocks.machine; + +import java.util.Random; + +import com.hbm.blocks.ModBlocks; +import com.hbm.main.MainRegistry; +import com.hbm.tileentity.machine.TileEntityReactorControl; + +import cpw.mods.fml.common.network.internal.FMLNetworkHandler; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +public class MachineReactorControl extends BlockContainer { + + public MachineReactorControl(Material p_i45386_1_) { + super(p_i45386_1_); + } + + @Override + public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { + return new TileEntityReactorControl(); + } + + @Override + public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_) + { + return Item.getItemFromBlock(this); + } + + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { + if(world.isRemote) + { + return true; + } else if(!player.isSneaking()) + { + TileEntityReactorControl entity = (TileEntityReactorControl) world.getTileEntity(x, y, z); + if(entity != null) + { + FMLNetworkHandler.openGui(player, MainRegistry.instance, ModBlocks.guiID_machine_controller, world, x, y, z); + } + return true; + } else { + return false; + } + } + +} diff --git a/com/hbm/handler/GUIHandler.java b/com/hbm/handler/GUIHandler.java index 5466061bf..c4e437500 100644 --- a/com/hbm/handler/GUIHandler.java +++ b/com/hbm/handler/GUIHandler.java @@ -693,6 +693,15 @@ public class GUIHandler implements IGuiHandler { } return null; } + + case ModBlocks.guiID_machine_controller: + { + if(entity instanceof TileEntityReactorControl) + { + return new ContainerReactorControl(player.inventory, (TileEntityReactorControl) entity); + } + return null; + } } return null; } @@ -1378,6 +1387,15 @@ public class GUIHandler implements IGuiHandler { } return null; } + + case ModBlocks.guiID_machine_controller: + { + if(entity instanceof TileEntityReactorControl) + { + return new GUIReactorControl(player.inventory, (TileEntityReactorControl) entity); + } + return null; + } } } else { //CLIENTONLY GUIS diff --git a/com/hbm/inventory/container/ContainerReactorControl.java b/com/hbm/inventory/container/ContainerReactorControl.java new file mode 100644 index 000000000..2e1ea7913 --- /dev/null +++ b/com/hbm/inventory/container/ContainerReactorControl.java @@ -0,0 +1,77 @@ +package com.hbm.inventory.container; + +import com.hbm.tileentity.machine.TileEntityReactorControl; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.ICrafting; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class ContainerReactorControl extends Container { + + private TileEntityReactorControl testNuke; + private int heat; + + public ContainerReactorControl(InventoryPlayer invPlayer, TileEntityReactorControl tedf) { + heat = 0; + + testNuke = tedf; + + this.addSlotToContainer(new Slot(tedf, 0, 26, 53)); + + for(int i = 0; i < 3; i++) + { + for(int j = 0; j < 9; j++) + { + this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); + } + } + + for(int i = 0; i < 9; i++) + { + this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2) + { + ItemStack var3 = null; + Slot var4 = (Slot) this.inventorySlots.get(par2); + + if (var4 != null && var4.getHasStack()) + { + ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + if (par2 <= 0) { + if (!this.mergeItemStack(var5, 1, this.inventorySlots.size(), true)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, 0, 1, false)) + { + return null; + } + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack) null); + } + else + { + var4.onSlotChanged(); + } + } + + return var3; + } + + @Override + public boolean canInteractWith(EntityPlayer player) { + return testNuke.isUseableByPlayer(player); + } +} diff --git a/com/hbm/inventory/gui/GUIMachineReactorSmall.java b/com/hbm/inventory/gui/GUIMachineReactorSmall.java index 30a8434a1..d6fa27b6e 100644 --- a/com/hbm/inventory/gui/GUIMachineReactorSmall.java +++ b/com/hbm/inventory/gui/GUIMachineReactorSmall.java @@ -33,6 +33,7 @@ public class GUIMachineReactorSmall extends GuiInfoContainer { this.ySize = 222; } + @SuppressWarnings("incomplete-switch") @Override public void drawScreen(int mouseX, int mouseY, float f) { super.drawScreen(mouseX, mouseY, f); @@ -97,7 +98,8 @@ public class GUIMachineReactorSmall extends GuiInfoContainer { this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); } - protected void mouseClicked(int x, int y, int i) { + @SuppressWarnings("incomplete-switch") + protected void mouseClicked(int x, int y, int i) { super.mouseClicked(x, y, i); if(guiLeft + 52 <= x && guiLeft + 52 + 16 > x && guiTop + 53 < y && guiTop + 53 + 16 >= y) { @@ -121,6 +123,7 @@ public class GUIMachineReactorSmall extends GuiInfoContainer { } } + @SuppressWarnings("incomplete-switch") @Override protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); diff --git a/com/hbm/inventory/gui/GUIReactorControl.java b/com/hbm/inventory/gui/GUIReactorControl.java new file mode 100644 index 000000000..ed7cfbfd2 --- /dev/null +++ b/com/hbm/inventory/gui/GUIReactorControl.java @@ -0,0 +1,145 @@ +package com.hbm.inventory.gui; + +import org.lwjgl.opengl.GL11; + +import com.hbm.inventory.container.ContainerReactorControl; +import com.hbm.lib.RefStrings; +import com.hbm.packet.AuxButtonPacket; +import com.hbm.packet.PacketDispatcher; +import com.hbm.tileentity.machine.TileEntityReactorControl; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.audio.PositionedSoundRecord; +import net.minecraft.client.resources.I18n; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +public class GUIReactorControl extends GuiInfoContainer { + + private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/gui_reactor_control.png"); + private TileEntityReactorControl control; + + public GUIReactorControl(InventoryPlayer invPlayer, TileEntityReactorControl tedf) { + super(new ContainerReactorControl(invPlayer, tedf)); + control = tedf; + + this.xSize = 176; + this.ySize = 166; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float f) { + super.drawScreen(mouseX, mouseY, f); + + this.drawCustomInfo(this, mouseX, mouseY, guiLeft + 80, guiTop + 114, 88, 4, new String[] { "Hull Temperature:", " " + Math.round((control.hullHeat) * 0.00001 * 980 + 20) + "°C" }); + } + + protected void mouseClicked(int x, int y, int i) { + super.mouseClicked(x, y, i); + + if(guiLeft + 7 <= x && guiLeft + 7 + 18 > x && guiTop + 16 < y && guiTop + 16 + 18 >= y) { + + mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + PacketDispatcher.wrapper.sendToServer(new AuxButtonPacket(control.xCoord, control.yCoord, control.zCoord, control.isOn ? 0 : 1, 0)); + } + } + + @Override + protected void drawGuiContainerForegroundLayer( int i, int j) { + String name = this.control.hasCustomInventoryName() ? this.control.getInventoryName() : I18n.format(this.control.getInventoryName()); + + this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752); + this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(texture); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + + if(control.hullHeat > 0) { + int i = (control.hullHeat * 88 / 100000); + + i = (int) Math.min(i, 160); + + drawTexturedModalRect(guiLeft + 80, guiTop + 59, 0, 166, i, 4); + } + + if(control.coreHeat > 0) { + int i = (control.coreHeat * 88 / 50000); + + i = (int) Math.min(i, 160); + + drawTexturedModalRect(guiLeft + 80, guiTop + 65, 0, 170, i, 4); + } + + if(control.steam > 0) { + int i = (control.steam * 88 / control.maxSteam); + + i = (int) Math.min(i, 160); + + drawTexturedModalRect(guiLeft + 80, guiTop + 53, 0, 174 + 4 * control.compression, i, 4); + } + + if(control.cool > 0) { + int i = (control.cool * 88 / control.maxCool); + + i = (int) Math.min(i, 160); + + drawTexturedModalRect(guiLeft + 80, guiTop + 47, 0, 194, i, 4); + } + + if(control.water > 0) { + int i = (control.water * 88 / control.maxWater); + + i = (int) Math.min(i, 160); + + drawTexturedModalRect(guiLeft + 80, guiTop + 41, 0, 190, i, 4); + } + + if(control.fuel > 0) { + int i = (control.fuel * 88 / 100); + + i = (int) Math.min(i, 160); + + drawTexturedModalRect(guiLeft + 80, guiTop + 35, 0, 186, i, 4); + } + + if(control.isOn) { + drawTexturedModalRect(guiLeft + 7, guiTop + 16, 218, 0, 18, 18); + } + + if(control.auto) { + drawTexturedModalRect(guiLeft + 43, guiTop + 16, 236, 0, 18, 18); + } + + drawTexturedModalRect(guiLeft + 63, guiTop + 52, 176 + 14 * control.compression, 0, 14, 18); + + if(!control.isLinked) { + drawTexturedModalRect(guiLeft + 79, guiTop + 16, 88, 166, 18, 18); + } + + if(control.water < control.maxWater * 0.1) { + drawTexturedModalRect(guiLeft + 79 + 18, guiTop + 16, 88 + 18, 166, 18, 18); + } + + if(control.cool < control.maxCool * 0.1) { + drawTexturedModalRect(guiLeft + 79 + 18 * 2, guiTop + 16, 88 + 18 * 2, 166, 18, 18); + } + + if(control.steam > control.maxSteam * 0.9) { + drawTexturedModalRect(guiLeft + 79 + 18 * 3, guiTop + 16, 88 + 18 * 3, 166, 18, 18); + } + + if(control.coreHeat > (50000 * 0.9)) { + drawTexturedModalRect(guiLeft + 79 + 18 * 4, guiTop + 16, 88 + 18 * 4, 166, 18, 18); + } + + if(control.rods == control.maxRods) { + drawTexturedModalRect(guiLeft + 25, guiTop + 16, 176, 18, 18, 18); + } else if(control.rods > 0) { + drawTexturedModalRect(guiLeft + 25, guiTop + 16, 194, 18, 18, 18); + } + } +} diff --git a/com/hbm/main/MainRegistry.java b/com/hbm/main/MainRegistry.java index 1462c986b..73edbb1da 100644 --- a/com/hbm/main/MainRegistry.java +++ b/com/hbm/main/MainRegistry.java @@ -323,6 +323,7 @@ import com.hbm.tileentity.machine.TileEntityMachineUF6Tank; import com.hbm.tileentity.machine.TileEntityNukeFurnace; import com.hbm.tileentity.machine.TileEntityRadioRec; import com.hbm.tileentity.machine.TileEntityRadiobox; +import com.hbm.tileentity.machine.TileEntityReactorControl; import com.hbm.tileentity.machine.TileEntityReactorMultiblock; import com.hbm.tileentity.machine.TileEntityRtgFurnace; import com.hbm.tileentity.machine.TileEntitySafe; @@ -745,6 +746,7 @@ public class MainRegistry GameRegistry.registerTileEntity(TileEntityForceField.class, "tileentity_machine_field"); GameRegistry.registerTileEntity(TileEntityMachineShredderLarge.class, "tileentity_machine_big_shredder"); GameRegistry.registerTileEntity(TileEntityRFDuct.class, "tileentity_hbm_rfduct"); + GameRegistry.registerTileEntity(TileEntityReactorControl.class, "tileentity_reactor_remote_control"); EntityRegistry.registerModEntity(EntityRocket.class, "entity_rocket", 0, this, 250, 1, true); EntityRegistry.registerModEntity(EntityNukeExplosion.class, "entity_nuke_explosion", 1, this, 250, 1, true); diff --git a/com/hbm/packet/AuxButtonPacket.java b/com/hbm/packet/AuxButtonPacket.java index 03eba1274..ae66cc8ee 100644 --- a/com/hbm/packet/AuxButtonPacket.java +++ b/com/hbm/packet/AuxButtonPacket.java @@ -14,6 +14,7 @@ import com.hbm.tileentity.machine.TileEntityMachineDiesel; import com.hbm.tileentity.machine.TileEntityMachineReactorSmall; import com.hbm.tileentity.machine.TileEntityMachineSeleniumEngine; import com.hbm.tileentity.machine.TileEntityRadioRec; +import com.hbm.tileentity.machine.TileEntityReactorControl; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; @@ -120,6 +121,19 @@ public class AuxButtonPacket implements IMessage { field.isOn = !field.isOn; } + if (te instanceof TileEntityReactorControl) { + TileEntityReactorControl control = (TileEntityReactorControl)te; + + TileEntity reac = p.worldObj.getTileEntity(control.linkX, control.linkY, control.linkZ); + + if (reac instanceof TileEntityMachineReactorSmall) { + TileEntityMachineReactorSmall reactor = (TileEntityMachineReactorSmall)reac; + + if(m.id == 0) + reactor.retracting = m.value == 0; + } + } + //} catch (Exception x) { } return null; diff --git a/com/hbm/packet/PacketDispatcher.java b/com/hbm/packet/PacketDispatcher.java index 03d986c84..5336f186e 100644 --- a/com/hbm/packet/PacketDispatcher.java +++ b/com/hbm/packet/PacketDispatcher.java @@ -77,6 +77,8 @@ public class PacketDispatcher { wrapper.registerMessage(LoopedEntitySoundPacket.Handler.class, LoopedEntitySoundPacket.class, i++, Side.CLIENT); //Entity sound packet that keeps client and server separated wrapper.registerMessage(TEFFPacket.Handler.class, TEFFPacket.class, i++, Side.CLIENT); + //Information packet for the reactor control block + wrapper.registerMessage(TEControlPacket.Handler.class, TEControlPacket.class, i++, Side.CLIENT); } } diff --git a/com/hbm/packet/TEControlPacket.java b/com/hbm/packet/TEControlPacket.java new file mode 100644 index 000000000..4b581d5cf --- /dev/null +++ b/com/hbm/packet/TEControlPacket.java @@ -0,0 +1,139 @@ +package com.hbm.packet; + +import com.hbm.tileentity.machine.TileEntityForceField; +import com.hbm.tileentity.machine.TileEntityReactorControl; + +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; +import net.minecraft.tileentity.TileEntity; + +public class TEControlPacket implements IMessage { + + int x; + int y; + int z; + int hullHeat; + int coreHeat; + int fuel; + int water; + int cool; + int steam; + int maxWater; + int maxCool; + int maxSteam; + int compression; + int rods; + int maxRods; + boolean isOn; + boolean auto; + boolean isLinked; + + public TEControlPacket() { + + } + + public TEControlPacket(int x, int y, int z, int hullHeat, int coreHeat, int fuel, int water, int cool, int steam, int maxWater, int maxCool, int maxSteam, int compression, int rods, int maxRods, boolean isOn, boolean auto, boolean isLinked) { + this.x = x; + this.y = y; + this.z = z; + this.hullHeat = hullHeat; + this.coreHeat = coreHeat; + this.fuel = fuel; + this.water = water; + this.cool = cool; + this.steam = steam; + this.maxWater = maxWater; + this.maxCool = maxCool; + this.maxSteam = maxSteam; + this.compression = compression; + this.rods = rods; + this.maxRods = maxRods; + this.isOn = isOn; + this.auto = auto; + this.isLinked = isLinked; + } + + @Override + public void fromBytes(ByteBuf buf) { + x = buf.readInt(); + y = buf.readInt(); + z = buf.readInt(); + hullHeat = buf.readInt(); + coreHeat = buf.readInt(); + fuel = buf.readInt(); + water = buf.readInt(); + cool = buf.readInt(); + steam = buf.readInt(); + maxWater = buf.readInt(); + maxCool = buf.readInt(); + maxSteam = buf.readInt(); + compression = buf.readInt(); + rods = buf.readInt(); + maxRods = buf.readInt(); + isOn = buf.readBoolean(); + auto = buf.readBoolean(); + isLinked = buf.readBoolean(); + } + + @Override + public void toBytes(ByteBuf buf) { + buf.writeInt(x); + buf.writeInt(y); + buf.writeInt(z); + buf.writeInt(hullHeat); + buf.writeInt(coreHeat); + buf.writeInt(fuel); + buf.writeInt(water); + buf.writeInt(cool); + buf.writeInt(steam); + buf.writeInt(maxWater); + buf.writeInt(maxCool); + buf.writeInt(maxSteam); + buf.writeInt(compression); + buf.writeInt(rods); + buf.writeInt(maxRods); + buf.writeBoolean(isOn); + buf.writeBoolean(auto); + buf.writeBoolean(isLinked); + } + + public static class Handler implements IMessageHandler { + + @Override + @SideOnly(Side.CLIENT) + public IMessage onMessage(TEControlPacket m, MessageContext ctx) { + TileEntity te = Minecraft.getMinecraft().theWorld.getTileEntity(m.x, m.y, m.z); + + try { + + if(te instanceof TileEntityReactorControl) { + TileEntityReactorControl control = (TileEntityReactorControl)te; + + control.hullHeat = m.hullHeat; + control.coreHeat = m.coreHeat; + control.fuel = m.fuel; + control.water = m.water; + control.cool = m.cool; + control.steam = m.steam; + control.maxWater = m.maxWater; + control.maxCool = m.maxCool; + control.maxSteam = m.maxSteam; + control.compression = m.compression; + control.rods = m.rods; + control.maxRods = m.maxRods; + control.isOn = m.isOn; + control.auto = m.auto; + control.isLinked = m.isLinked; + } + + } catch (Exception x) { + } + return null; + } + } +} diff --git a/com/hbm/tileentity/machine/TileEntityMachineReactorSmall.java b/com/hbm/tileentity/machine/TileEntityMachineReactorSmall.java index 5b4f63df3..2438210fa 100644 --- a/com/hbm/tileentity/machine/TileEntityMachineReactorSmall.java +++ b/com/hbm/tileentity/machine/TileEntityMachineReactorSmall.java @@ -181,6 +181,8 @@ public class TileEntityMachineReactorSmall extends TileEntity coreHeat = nbt.getInteger("heat"); hullHeat = nbt.getInteger("hullHeat"); + rods = nbt.getInteger("rods"); + retracting = nbt.getBoolean("ret"); slots = new ItemStack[getSizeInventory()]; tanks[0].readFromNBT(nbt, "water"); tanks[1].readFromNBT(nbt, "coolant"); @@ -199,6 +201,8 @@ public class TileEntityMachineReactorSmall extends TileEntity super.writeToNBT(nbt); nbt.setInteger("heat", coreHeat); nbt.setInteger("hullHeat", hullHeat); + nbt.setInteger("rods", rods); + nbt.setBoolean("ret", retracting); NBTTagList list = new NBTTagList(); tanks[0].writeToNBT(nbt, "water"); tanks[1].writeToNBT(nbt, "coolant"); @@ -303,6 +307,25 @@ public class TileEntityMachineReactorSmall extends TileEntity return null; } + + public int getFuelPercent() { + + if(getRodCount() == 0) + return 0; + + int rodMax = 0; + int rod = 0; + + for(int i = 0; i < 12; i++) { + + if(slots[i] != null && slots[i].getItem() instanceof ItemFuelRod) { + rodMax += ((ItemFuelRod)slots[i].getItem()).lifeTime; + rod += ((ItemFuelRod)slots[i].getItem()).lifeTime - ItemFuelRod.getLifeTime(slots[i]); + } + } + + return rod * 100 / rodMax; + } @Override public void updateEntity() { diff --git a/com/hbm/tileentity/machine/TileEntityReactorControl.java b/com/hbm/tileentity/machine/TileEntityReactorControl.java new file mode 100644 index 000000000..a46fd86d8 --- /dev/null +++ b/com/hbm/tileentity/machine/TileEntityReactorControl.java @@ -0,0 +1,271 @@ +package com.hbm.tileentity.machine; + +import com.hbm.blocks.ModBlocks; +import com.hbm.items.ModItems; +import com.hbm.items.tool.ItemKeyPin; +import com.hbm.packet.PacketDispatcher; +import com.hbm.packet.TEControlPacket; + +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; +import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.tileentity.TileEntity; + +public class TileEntityReactorControl extends TileEntity implements ISidedInventory { + + private ItemStack slots[]; + + private static final int[] slots_top = new int[] {0}; + private static final int[] slots_bottom = new int[] {0}; + private static final int[] slots_side = new int[] {0}; + + private String customName; + + public TileEntityReactorControl() { + slots = new ItemStack[1]; + } + + @Override + public int getSizeInventory() { + return slots.length; + } + + @Override + public ItemStack getStackInSlot(int i) { + return slots[i]; + } + + @Override + public ItemStack getStackInSlotOnClosing(int i) { + if(slots[i] != null) + { + ItemStack itemStack = slots[i]; + slots[i] = null; + return itemStack; + } else { + return null; + } + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemStack) { + slots[i] = itemStack; + if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()) + { + itemStack.stackSize = getInventoryStackLimit(); + } + } + + @Override + public String getInventoryName() { + return this.hasCustomInventoryName() ? this.customName : "container.reactorControl"; + } + + @Override + public boolean hasCustomInventoryName() { + return this.customName != null && this.customName.length() > 0; + } + + public void setCustomName(String name) { + this.customName = name; + } + + @Override + public int getInventoryStackLimit() { + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + if(worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) + { + return false; + }else{ + return player.getDistanceSq(xCoord + 0.5D, yCoord + 0.5D, zCoord + 0.5D) <=64; + } + } + + @Override + public void openInventory() {} + @Override + public void closeInventory() {} + + @Override + public boolean isItemValidForSlot(int i, ItemStack stack) { + return false; + } + + @Override + public ItemStack decrStackSize(int i, int j) { + if(slots[i] != null) + { + if(slots[i].stackSize <= j) + { + ItemStack itemStack = slots[i]; + slots[i] = null; + return itemStack; + } + ItemStack itemStack1 = slots[i].splitStack(j); + if (slots[i].stackSize == 0) + { + slots[i] = null; + } + + return itemStack1; + } else { + return null; + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + NBTTagList list = nbt.getTagList("items", 10); + + slots = new ItemStack[getSizeInventory()]; + + for(int i = 0; i < list.tagCount(); i++) + { + NBTTagCompound nbt1 = list.getCompoundTagAt(i); + byte b0 = nbt1.getByte("slot"); + if(b0 >= 0 && b0 < slots.length) + { + slots[b0] = ItemStack.loadItemStackFromNBT(nbt1); + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + NBTTagList list = new NBTTagList(); + + for(int i = 0; i < slots.length; i++) + { + if(slots[i] != null) + { + NBTTagCompound nbt1 = new NBTTagCompound(); + nbt1.setByte("slot", (byte)i); + slots[i].writeToNBT(nbt1); + list.appendTag(nbt1); + } + } + nbt.setTag("items", list); + } + + @Override + public int[] getAccessibleSlotsFromSide(int p_94128_1_) + { + return p_94128_1_ == 0 ? slots_bottom : (p_94128_1_ == 1 ? slots_top : slots_side); + } + + @Override + public boolean canInsertItem(int i, ItemStack itemStack, int j) { + return false; + } + + @Override + public boolean canExtractItem(int i, ItemStack itemStack, int j) { + return false; + } + + public int linkX; + public int linkY; + public int linkZ; + + public int hullHeat; + public int coreHeat; + public int fuel; + public int water; + public int cool; + public int steam; + public int maxWater; + public int maxCool; + public int maxSteam; + public int compression; + public int rods; + public int maxRods; + public boolean isOn; + public boolean auto; + public boolean isLinked; + + @Override + public void updateEntity() { + + if(!worldObj.isRemote) + { + if(slots[0] != null && slots[0].getItem() == ModItems.detonator && + slots[0].stackTagCompound != null) + { + int xCoord = slots[0].stackTagCompound.getInteger("x"); + int yCoord = slots[0].stackTagCompound.getInteger("y"); + int zCoord = slots[0].stackTagCompound.getInteger("z"); + + Block b = worldObj.getBlock(xCoord, yCoord, zCoord); + + if(b == ModBlocks.machine_reactor_small) { + linkX = xCoord; + linkY = yCoord; + linkZ = zCoord; + } else if(b == ModBlocks.dummy_block_reactor_small || b == ModBlocks.dummy_port_reactor_small) { + linkX = ((TileEntityDummy)worldObj.getTileEntity(xCoord, yCoord, zCoord)).targetX; + linkY = ((TileEntityDummy)worldObj.getTileEntity(xCoord, yCoord, zCoord)).targetY; + linkZ = ((TileEntityDummy)worldObj.getTileEntity(xCoord, yCoord, zCoord)).targetZ; + } else { + linkY = -1; + } + } else { + linkY = -1; + } + + if(linkY >= 0 && worldObj.getTileEntity(linkX, linkY, linkZ) instanceof TileEntityMachineReactorSmall) { + TileEntityMachineReactorSmall reactor = (TileEntityMachineReactorSmall)worldObj.getTileEntity(linkX, linkY, linkZ); + + hullHeat = reactor.hullHeat; + coreHeat = reactor.coreHeat; + fuel = reactor.getFuelPercent(); + water = reactor.tanks[0].getFill(); + cool = reactor.tanks[1].getFill(); + steam = reactor.tanks[2].getFill(); + maxWater = reactor.tanks[0].getMaxFill(); + maxCool = reactor.tanks[1].getMaxFill(); + maxSteam = reactor.tanks[2].getMaxFill(); + rods = reactor.rods; + maxRods = reactor.rodsMax; + isOn = !reactor.retracting; + isLinked = true; + + switch(reactor.tanks[2].getTankType()) { + case HOTSTEAM: + compression = 1; break; + case SUPERHOTSTEAM: + compression = 2; break; + default: + compression = 0; break; + } + + } else { + hullHeat = 0; + coreHeat = 0; + fuel = 0; + water = 0; + cool = 0; + steam = 0; + maxWater = 0; + maxCool = 0; + maxSteam = 0; + rods = 0; + maxRods = 0; + isOn = false; + compression = 0; + isLinked = false; + } + + PacketDispatcher.wrapper.sendToAll(new TEControlPacket(xCoord, yCoord, zCoord, hullHeat, coreHeat, fuel, water, cool, steam, maxWater, maxCool, maxSteam, compression, rods, maxRods, isOn, auto, isLinked)); + } + } +}