diff --git a/src/main/java/techreborn/client/GuiHandler.java b/src/main/java/techreborn/client/GuiHandler.java index 7b498ad4f..649b52eab 100644 --- a/src/main/java/techreborn/client/GuiHandler.java +++ b/src/main/java/techreborn/client/GuiHandler.java @@ -149,8 +149,13 @@ public class GuiHandler implements IGuiHandler { } else if (ID == GuiHandler.compressorID) { return new ContainerCompressor((TileCompressor) world.getTileEntity(new BlockPos(x, y, z)), player); } else if (ID == GuiHandler.electricFurnaceID) { - return new ContainerElectricFurnace((TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)), - player); + return new ContainerBuilder().player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory() + .tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 56, 34) + .outputSlot(1, 116, 34).upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26).upgradeSlot(4, 152, 44) + .upgradeSlot(5, 152, 62).syncEnergyValue() + .syncIntegerValue(((TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)))::getBurnTime, + ((TileElectricFurnace) world.getTileEntity(new BlockPos(x, y, z)))::setBurnTime) + .addInventory().create(); } else if (ID == GuiHandler.ironFurnace) { return new ContainerBuilder().player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory() .tile((IInventory) world.getTileEntity(new BlockPos(x, y, z))).slot(0, 56, 17) diff --git a/src/main/java/techreborn/client/container/ContainerElectricFurnace.java b/src/main/java/techreborn/client/container/ContainerElectricFurnace.java deleted file mode 100644 index 14c3488bb..000000000 --- a/src/main/java/techreborn/client/container/ContainerElectricFurnace.java +++ /dev/null @@ -1,59 +0,0 @@ -package techreborn.client.container; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; -import reborncore.client.gui.slots.BaseSlot; -import reborncore.client.gui.slots.SlotOutput; -import reborncore.common.container.RebornContainer; -import techreborn.api.gui.SlotUpgrade; -import techreborn.tiles.teir1.TileElectricFurnace; - -public class ContainerElectricFurnace extends RebornContainer { - - public int connectionStatus; - EntityPlayer player; - TileElectricFurnace tile; - - public ContainerElectricFurnace(TileElectricFurnace tileGrinder, EntityPlayer player) { - super(); - tile = tileGrinder; - this.player = player; - - // input - this.addSlotToContainer(new BaseSlot(tileGrinder.inventory, 0, 56, 34)); - this.addSlotToContainer(new SlotOutput(tileGrinder.inventory, 1, 116, 34)); - - // upgrades - this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 2, 152, 8)); - this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 3, 152, 26)); - this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 4, 152, 44)); - this.addSlotToContainer(new SlotUpgrade(tileGrinder.inventory, 5, 152, 62)); - - int i; - - for (i = 0; i < 3; ++i) { - for (int j = 0; j < 9; ++j) { - this.addSlotToContainer(new BaseSlot(player.inventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); - } - } - - for (i = 0; i < 9; ++i) { - this.addSlotToContainer(new BaseSlot(player.inventory, i, 8 + i * 18, 142)); - } - } - - @Override - public boolean canInteractWith(EntityPlayer p_75145_1_) { - return true; - } - - @SideOnly(Side.CLIENT) - @Override - public void updateProgressBar(int id, int value) { - if (id == 10) { - this.connectionStatus = value; - } - } - -} diff --git a/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java b/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java index e6f6ca0e9..e962b7865 100644 --- a/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java +++ b/src/main/java/techreborn/client/container/builder/ContainerTileInventoryBuilder.java @@ -17,6 +17,7 @@ import reborncore.common.powerSystem.TilePowerAcceptor; import techreborn.Core; import techreborn.client.container.builder.slot.FilteredSlot; +import techreborn.utils.upgrade.IMachineUpgrade; import java.util.function.IntConsumer; import java.util.function.IntSupplier; @@ -69,6 +70,12 @@ public class ContainerTileInventoryBuilder { return this; } + public ContainerTileInventoryBuilder upgradeSlot(final int index, final int x, final int y) { + this.parent.slots.add(new FilteredSlot(this.tile, index, x, y) + .setFilter(stack -> stack.getItem() instanceof IMachineUpgrade)); + return this; + } + /** * * @param supplier diff --git a/src/main/java/techreborn/client/gui/GuiElectricFurnace.java b/src/main/java/techreborn/client/gui/GuiElectricFurnace.java index 5c80cbbd6..c9d4f8285 100644 --- a/src/main/java/techreborn/client/gui/GuiElectricFurnace.java +++ b/src/main/java/techreborn/client/gui/GuiElectricFurnace.java @@ -5,7 +5,8 @@ import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.translation.I18n; -import techreborn.client.container.ContainerElectricFurnace; + +import techreborn.client.container.builder.ContainerBuilder; import techreborn.tiles.teir1.TileElectricFurnace; public class GuiElectricFurnace extends GuiContainer { @@ -13,43 +14,44 @@ public class GuiElectricFurnace extends GuiContainer { public static final ResourceLocation texture = new ResourceLocation("techreborn", "textures/gui/compressor.png"); TileElectricFurnace furnace; - ContainerElectricFurnace containerGrinder; - public GuiElectricFurnace(EntityPlayer player, TileElectricFurnace tilegrinder) { - super(new ContainerElectricFurnace(tilegrinder, player)); + public GuiElectricFurnace(final EntityPlayer player, final TileElectricFurnace furnace) { + super(new ContainerBuilder().player(player.inventory).inventory(8, 84).hotbar(8, 142).addInventory() + .tile(furnace).slot(0, 56, 34).outputSlot(1, 116, 34).upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26) + .upgradeSlot(4, 152, 44).upgradeSlot(5, 152, 62).syncEnergyValue() + .syncIntegerValue(furnace::getBurnTime, furnace::setBurnTime).addInventory().create()); this.xSize = 176; this.ySize = 167; - furnace = tilegrinder; - containerGrinder = (ContainerElectricFurnace) this.inventorySlots; + this.furnace = furnace; } @Override - protected void drawGuiContainerBackgroundLayer(float p_146976_1_, int p_146976_2_, int p_146976_3_) { + protected void drawGuiContainerBackgroundLayer(final float p_146976_1_, final int p_146976_2_, final int p_146976_3_) { GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); - this.mc.getTextureManager().bindTexture(texture); - int k = (this.width - this.xSize) / 2; - int l = (this.height - this.ySize) / 2; + this.mc.getTextureManager().bindTexture(GuiElectricFurnace.texture); + final int k = (this.width - this.xSize) / 2; + final int l = (this.height - this.ySize) / 2; this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize); int j = 0; - j = furnace.gaugeProgressScaled(24); + j = this.furnace.gaugeProgressScaled(24); if (j > 0) { this.drawTexturedModalRect(k + 78, l + 34, 176, 14, j + 1, 16); } - j = furnace.getEnergyScaled(12); + j = this.furnace.getEnergyScaled(12); if (j > 0) { this.drawTexturedModalRect(k + 24, l + 36 + 12 - j, 176, 12 - j, 14, j + 2); } } - protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) { - String name = I18n.translateToLocal("tile.techreborn.electricfurnace.name"); + @Override + protected void drawGuiContainerForegroundLayer(final int p_146979_1_, final int p_146979_2_) { + final String name = I18n.translateToLocal("tile.techreborn.electricfurnace.name"); this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, - 4210752); + 4210752); this.fontRendererObj.drawString(I18n.translateToLocalFormatted("container.inventory", new Object[0]), 8, - this.ySize - 96 + 2, 4210752); + this.ySize - 96 + 2, 4210752); } - } diff --git a/src/main/java/techreborn/tiles/teir1/TileElectricFurnace.java b/src/main/java/techreborn/tiles/teir1/TileElectricFurnace.java index 217500567..397fd99da 100644 --- a/src/main/java/techreborn/tiles/teir1/TileElectricFurnace.java +++ b/src/main/java/techreborn/tiles/teir1/TileElectricFurnace.java @@ -6,12 +6,14 @@ import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.util.EnumFacing; + import reborncore.api.power.EnumPowerTier; import reborncore.api.tile.IInventoryProvider; import reborncore.common.IWrenchable; import reborncore.common.blocks.BlockMachineBase; import reborncore.common.powerSystem.TilePowerAcceptor; import reborncore.common.util.Inventory; + import techreborn.init.ModBlocks; public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory { @@ -31,78 +33,78 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl super(1); } - public int gaugeProgressScaled(int scale) { - return (progress * scale) / fuelScale; + public int gaugeProgressScaled(final int scale) { + return this.progress * scale / this.fuelScale; } @Override public void update() { super.update(); - boolean burning = isBurning(); + final boolean burning = this.isBurning(); boolean updateInventory = false; - if (isBurning() && canSmelt()) { - updateState(); + if (this.isBurning() && this.canSmelt()) { + this.updateState(); - progress++; - if (progress % 10 == 0) { - useEnergy(cost); + this.progress++; + if (this.progress % 10 == 0) { + this.useEnergy(this.cost); } - if (progress >= fuelScale) { - progress = 0; - cookItems(); + if (this.progress >= this.fuelScale) { + this.progress = 0; + this.cookItems(); updateInventory = true; } } else { - progress = 0; - updateState(); + this.progress = 0; + this.updateState(); } - if (burning != isBurning()) { + if (burning != this.isBurning()) { updateInventory = true; } if (updateInventory) { - markDirty(); + this.markDirty(); } } public void cookItems() { if (this.canSmelt()) { - ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1)); + final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1)); - if (getStackInSlot(output) == ItemStack.EMPTY) { - setInventorySlotContents(output, itemstack.copy()); - } else if (getStackInSlot(output).isItemEqual(itemstack)) { - getStackInSlot(output).grow(itemstack.getCount()); + if (this.getStackInSlot(this.output) == ItemStack.EMPTY) { + this.setInventorySlotContents(this.output, itemstack.copy()); + } else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) { + this.getStackInSlot(this.output).grow(itemstack.getCount()); } - if (getStackInSlot(input1).getCount() > 1) { - this.decrStackSize(input1, 1); + if (this.getStackInSlot(this.input1).getCount() > 1) { + this.decrStackSize(this.input1, 1); } else { - setInventorySlotContents(input1, ItemStack.EMPTY); + this.setInventorySlotContents(this.input1, ItemStack.EMPTY); } } } public boolean canSmelt() { - if (getStackInSlot(input1) == ItemStack.EMPTY) { + if (this.getStackInSlot(this.input1) == ItemStack.EMPTY) { return false; } else { - ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1)); + final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1)); if (itemstack == ItemStack.EMPTY) return false; - if (getStackInSlot(output) == ItemStack.EMPTY) + if (this.getStackInSlot(this.output) == ItemStack.EMPTY) return true; - if (!getStackInSlot(output).isItemEqual(itemstack)) + if (!this.getStackInSlot(this.output).isItemEqual(itemstack)) return false; - int result = getStackInSlot(output).getCount() + itemstack.getCount(); - return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize()); + final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount(); + return result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize(); } } public boolean isBurning() { - return getEnergy() > cost; + return this.getEnergy() > this.cost; } - public ItemStack getResultFor(ItemStack stack) { - ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack); + public ItemStack getResultFor(final ItemStack stack) { + final ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack); if (result != ItemStack.EMPTY) { return result.copy(); } @@ -110,26 +112,26 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl } public void updateState() { - IBlockState BlockStateContainer = world.getBlockState(pos); + final IBlockState BlockStateContainer = this.world.getBlockState(this.pos); if (BlockStateContainer.getBlock() instanceof BlockMachineBase) { - BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock(); - if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0) - blockMachineBase.setActive(progress > 0, world, pos); + final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock(); + if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0) + blockMachineBase.setActive(this.progress > 0, this.world, this.pos); } } @Override - public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) { + public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) { return false; } @Override public EnumFacing getFacing() { - return getFacingEnum(); + return this.getFacingEnum(); } @Override - public boolean wrenchCanRemove(EntityPlayer entityPlayer) { + public boolean wrenchCanRemove(final EntityPlayer entityPlayer) { return entityPlayer.isSneaking(); } @@ -139,7 +141,7 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl } @Override - public ItemStack getWrenchDrop(EntityPlayer entityPlayer) { + public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) { return new ItemStack(ModBlocks.ELECTRIC_FURNACE, 1); } @@ -149,34 +151,34 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl // ISidedInventory @Override - public int[] getSlotsForFace(EnumFacing side) { - return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES); + public int[] getSlotsForFace(final EnumFacing side) { + return side == EnumFacing.DOWN ? TileElectricFurnace.SLOTS_BOTTOM : side == EnumFacing.UP ? TileElectricFurnace.SLOTS_TOP : TileElectricFurnace.SLOTS_SIDES; } @Override - public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) { + public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) { if (slotIndex == 2) return false; - return isItemValidForSlot(slotIndex, itemStack); + return this.isItemValidForSlot(slotIndex, itemStack); } @Override - public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) { + public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) { return slotIndex == 1; } @Override public double getMaxPower() { - return capacity; + return this.capacity; } @Override - public boolean canAcceptEnergy(EnumFacing direction) { + public boolean canAcceptEnergy(final EnumFacing direction) { return true; } @Override - public boolean canProvideEnergy(EnumFacing direction) { + public boolean canProvideEnergy(final EnumFacing direction) { return false; } @@ -197,6 +199,14 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl @Override public Inventory getInventory() { - return inventory; + return this.inventory; + } + + public int getBurnTime() { + return this.progress; + } + + public void setBurnTime(final int burnTime) { + this.progress = burnTime; } }