diff --git a/src/main/java/com/hbm/inventory/container/ContainerMachineWoodBurner.java b/src/main/java/com/hbm/inventory/container/ContainerMachineWoodBurner.java new file mode 100644 index 000000000..9814bb422 --- /dev/null +++ b/src/main/java/com/hbm/inventory/container/ContainerMachineWoodBurner.java @@ -0,0 +1,103 @@ +package com.hbm.inventory.container; + +import com.hbm.inventory.SlotTakeOnly; +import com.hbm.items.machine.IItemFluidIdentifier; +import com.hbm.tileentity.machine.TileEntityMachineWoodBurner; + +import api.hbm.energy.IBatteryItem; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntityFurnace; + +public class ContainerMachineWoodBurner extends Container { + + protected TileEntityMachineWoodBurner burner; + + public ContainerMachineWoodBurner(InventoryPlayer invPlayer, TileEntityMachineWoodBurner burner) { + this.burner = burner; + this.burner.openInventory(); + + //Fuel + this.addSlotToContainer(new Slot(burner, 0, 26, 18)); + //Ashes + this.addSlotToContainer(new SlotTakeOnly(burner, 1, 26, 54)); + //Fluid ID + this.addSlotToContainer(new Slot(burner, 2, 98, 54)); + //Fluid Container + this.addSlotToContainer(new Slot(burner, 3, 98, 18)); + this.addSlotToContainer(new SlotTakeOnly(burner, 4, 98, 36)); + //Battery + this.addSlotToContainer(new Slot(burner, 5, 143, 54)); + + 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, 104 + i * 18)); + } + } + + for(int i = 0; i < 9; i++) { + this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 162)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int index) { + ItemStack stack = null; + Slot slot = (Slot) this.inventorySlots.get(index); + + if(slot != null && slot.getHasStack()) { + ItemStack originalStack = slot.getStack(); + stack = originalStack.copy(); + + if(index <= 5) { + if(!this.mergeItemStack(originalStack, 6, this.inventorySlots.size(), true)) { + return null; + } + + slot.onSlotChange(originalStack, stack); + + } else { + + if(stack.getItem() instanceof IBatteryItem) { + if(!this.mergeItemStack(originalStack, 5, 6, false)) { + return null; + } + } else if(stack.getItem() instanceof IItemFluidIdentifier) { + if(!this.mergeItemStack(originalStack, 2, 3, false)) { + return null; + } + } else if(TileEntityFurnace.isItemFuel(stack)) { + if(!this.mergeItemStack(originalStack, 2, 3, false)) { + return null; + } + } else { + if(!this.mergeItemStack(originalStack, 3, 4, false)) { + return null; + } + } + } + + if(originalStack.stackSize == 0) { + slot.putStack((ItemStack) null); + } else { + slot.onSlotChanged(); + } + } + + return stack; + } + + @Override + public boolean canInteractWith(EntityPlayer player) { + return burner.isUseableByPlayer(player); + } + + @Override + public void onContainerClosed(EntityPlayer player) { + super.onContainerClosed(player); + this.burner.closeInventory(); + } +} diff --git a/src/main/java/com/hbm/inventory/gui/GUIMachineWoodBurner.java b/src/main/java/com/hbm/inventory/gui/GUIMachineWoodBurner.java new file mode 100644 index 000000000..8395bef67 --- /dev/null +++ b/src/main/java/com/hbm/inventory/gui/GUIMachineWoodBurner.java @@ -0,0 +1,79 @@ +package com.hbm.inventory.gui; + +import org.lwjgl.opengl.GL11; + +import com.hbm.inventory.container.ContainerMachineWoodBurner; +import com.hbm.lib.RefStrings; +import com.hbm.packet.NBTControlPacket; +import com.hbm.packet.PacketDispatcher; +import com.hbm.tileentity.machine.TileEntityMachineWoodBurner; + +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.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; + +public class GUIMachineWoodBurner extends GuiInfoContainer { + + private TileEntityMachineWoodBurner burner; + private final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/generators/gui_wood_burner_alt.png"); + + public GUIMachineWoodBurner(InventoryPlayer invPlayer, TileEntityMachineWoodBurner tedf) { + super(new ContainerMachineWoodBurner(invPlayer, tedf)); + burner = tedf; + + this.xSize = 176; + this.ySize = 186; + } + + @Override + public void drawScreen(int mouseX, int mouseY, float f) { + super.drawScreen(mouseX, mouseY, f); + this.drawElectricityInfo(this, mouseX, mouseY, guiLeft + 143, guiTop + 18, 16, 34, burner.power, burner.maxPower); + } + + @Override + protected void mouseClicked(int x, int y, int i) { + super.mouseClicked(x, y, i); + + if(guiLeft + 53 <= x && guiLeft + 53 + 16 > x && guiTop + 17 < y && guiTop + 17 + 15 >= y) { + mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + NBTTagCompound data = new NBTTagCompound(); + data.setBoolean("toggle", false); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, burner.xCoord, burner.yCoord, burner.zCoord)); + } + + if(guiLeft + 46 <= x && guiLeft + 46 + 30 > x && guiTop + 37 < y && guiTop + 37 + 14 >= y) { + mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F)); + NBTTagCompound data = new NBTTagCompound(); + data.setBoolean("switch", false); + PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, burner.xCoord, burner.yCoord, burner.zCoord)); + } + } + + @Override + protected void drawGuiContainerForegroundLayer(int i, int j) { + String name = this.burner.hasCustomInventoryName() ? this.burner.getInventoryName() : I18n.format(this.burner.getInventoryName()); + + this.fontRendererObj.drawString(name, 70 - this.fontRendererObj.getStringWidth(name) / 2, 6, 0xffffff); + this.fontRendererObj.drawString(I18n.format("container.inventory"), 8, this.ySize - 96 + 2, 4210752); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float interp, int x, int y) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + Minecraft.getMinecraft().getTextureManager().bindTexture(texture); + drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); + + if(burner.liquidBurn) { + drawTexturedModalRect(guiLeft + 16, guiTop + 17, 176, 52, 60, 54); + drawTexturedModalRect(guiLeft + 79, guiTop + 17, 176, 106, 36, 54); + } + + if(burner.isOn) { + drawTexturedModalRect(guiLeft + 53, guiTop + 17, 196, 0, 16, 15); + } + } +} diff --git a/src/main/java/com/hbm/inventory/recipes/ArcWelderRecipes.java b/src/main/java/com/hbm/inventory/recipes/ArcWelderRecipes.java index 5a6152721..5aea7661e 100644 --- a/src/main/java/com/hbm/inventory/recipes/ArcWelderRecipes.java +++ b/src/main/java/com/hbm/inventory/recipes/ArcWelderRecipes.java @@ -30,9 +30,9 @@ public class ArcWelderRecipes extends SerializableRecipe { @Override public void registerDefaults() { - recipes.add(new ArcWelderRecipe(new ItemStack(ModItems.motor), 100, 200L, + recipes.add(new ArcWelderRecipe(new ItemStack(ModItems.motor, 2), 100, 200L, new OreDictStack(IRON.plate(), 2), new ComparableStack(ModItems.coil_copper), new ComparableStack(ModItems.coil_copper_torus))); - recipes.add(new ArcWelderRecipe(new ItemStack(ModItems.motor), 100, 400L, + recipes.add(new ArcWelderRecipe(new ItemStack(ModItems.motor, 2), 100, 400L, new OreDictStack(STEEL.plate(), 1), new ComparableStack(ModItems.coil_copper), new ComparableStack(ModItems.coil_copper_torus))); recipes.add(new ArcWelderRecipe(new ItemStack(ModItems.circuit_copper), 100, 1_000L, new FluidStack(Fluids.GAS, 250), diff --git a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineWoodBurner.java b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineWoodBurner.java index 57c6bf6c1..3fb872181 100644 --- a/src/main/java/com/hbm/tileentity/machine/TileEntityMachineWoodBurner.java +++ b/src/main/java/com/hbm/tileentity/machine/TileEntityMachineWoodBurner.java @@ -1,8 +1,11 @@ package com.hbm.tileentity.machine; +import com.hbm.interfaces.IControlReceiver; +import com.hbm.inventory.container.ContainerMachineWoodBurner; import com.hbm.inventory.fluid.Fluids; import com.hbm.inventory.fluid.tank.FluidTank; import com.hbm.inventory.fluid.trait.FT_Flammable; +import com.hbm.inventory.gui.GUIMachineWoodBurner; import com.hbm.module.ModuleBurnTime; import com.hbm.tileentity.IGUIProvider; import com.hbm.tileentity.TileEntityMachinePolluting; @@ -16,7 +19,7 @@ import net.minecraft.inventory.Container; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; -public class TileEntityMachineWoodBurner extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IGUIProvider { +public class TileEntityMachineWoodBurner extends TileEntityMachinePolluting implements IFluidStandardTransceiver, IControlReceiver, IGUIProvider { public long power; public static final long maxPower = 100_000; @@ -80,19 +83,50 @@ public class TileEntityMachineWoodBurner extends TileEntityMachinePolluting impl } NBTTagCompound data = new NBTTagCompound(); + data.setLong("power", power); + data.setInteger("burnTime", burnTime); + data.setInteger("maxBurnTime", maxBurnTime); + data.setBoolean("isOn", isOn); + data.setBoolean("liquidBurn", liquidBurn); this.networkPack(data, 25); } } + @Override + public void networkUnpack(NBTTagCompound nbt) { + this.power = nbt.getLong("power"); + this.burnTime = nbt.getInteger("burnTime"); + this.maxBurnTime = nbt.getInteger("maxBurnTime"); + this.isOn = nbt.getBoolean("isOn"); + this.liquidBurn = nbt.getBoolean("liquidBurn"); + } + + @Override + public void receiveControl(NBTTagCompound data) { + if(data.hasKey("toggle")) { + this.isOn = !this.isOn; + this.markChanged(); + } + if(data.hasKey("switch")) { + this.liquidBurn = !this.liquidBurn; + this.markChanged(); + } + } + + @Override + public boolean hasPermission(EntityPlayer player) { + return this.isUseableByPlayer(player); + } + @Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { - return null; + return new ContainerMachineWoodBurner(player.inventory, this); } @Override @SideOnly(Side.CLIENT) public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) { - return null; + return new GUIMachineWoodBurner(player.inventory, this); } @Override diff --git a/src/main/resources/assets/hbm/textures/gui/generators/gui_wood_burner.png b/src/main/resources/assets/hbm/textures/gui/generators/gui_wood_burner.png index 9189989e7..08d2f02dd 100644 Binary files a/src/main/resources/assets/hbm/textures/gui/generators/gui_wood_burner.png and b/src/main/resources/assets/hbm/textures/gui/generators/gui_wood_burner.png differ diff --git a/src/main/resources/assets/hbm/textures/gui/generators/gui_wood_burner_alt.png b/src/main/resources/assets/hbm/textures/gui/generators/gui_wood_burner_alt.png new file mode 100644 index 000000000..51c355b50 Binary files /dev/null and b/src/main/resources/assets/hbm/textures/gui/generators/gui_wood_burner_alt.png differ