diff --git a/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java b/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java index 80293478d..a8c537a5e 100644 --- a/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java +++ b/src/main/java/techreborn/blockentity/data/DataDrivenSlot.java @@ -82,7 +82,7 @@ public class DataDrivenSlot { } @Environment(EnvType.CLIENT) - public void draw(GuiBase guiBase, GuiBase.Layer layer){ + public void draw(GuiBase guiBase, GuiBase.Layer layer){ //TODO find a better way to do this if(getType() == SlotType.OUTPUT){ guiBase.drawOutputSlot(getX(), getY(), layer); diff --git a/src/main/java/techreborn/blockentity/machine/iron/IronAlloyFurnaceBlockEntity.java b/src/main/java/techreborn/blockentity/machine/iron/IronAlloyFurnaceBlockEntity.java index 138145794..3b5cb5b62 100644 --- a/src/main/java/techreborn/blockentity/machine/iron/IronAlloyFurnaceBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/iron/IronAlloyFurnaceBlockEntity.java @@ -24,6 +24,7 @@ package techreborn.blockentity.machine.iron; +import net.minecraft.block.BlockState; import net.minecraft.block.entity.AbstractFurnaceBlockEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -34,6 +35,7 @@ import reborncore.client.containerBuilder.IContainerProvider; import reborncore.client.containerBuilder.builder.BuiltContainer; import reborncore.client.containerBuilder.builder.ContainerBuilder; import reborncore.common.blockentity.MachineBaseBlockEntity; +import reborncore.common.blocks.BlockMachineBase; import reborncore.common.crafting.RebornRecipe; import reborncore.common.crafting.ingredient.RebornIngredient; import reborncore.common.util.RebornInventory; @@ -47,7 +49,7 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity public int tickTime; public RebornInventory inventory = new RebornInventory<>(4, "IronAlloyFurnaceBlockEntity", 64, this); public int burnTime; - public int currentItemBurnTime; + public int totalBurnTime; public int cookTime; int input1 = 0; int input2 = 1; @@ -74,43 +76,47 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity @Override public void tick() { super.tick(); - final boolean flag = this.burnTime > 0; - boolean flag1 = false; - if (this.burnTime > 0) { - --this.burnTime; + if(world.isClient){ + return; } - if (!this.world.isClient) { - if (this.burnTime != 0 || !inventory.getInvStack(this.input1).isEmpty()&& !inventory.getInvStack(this.fuel).isEmpty()) { - if (this.burnTime == 0 && this.canSmelt()) { - this.currentItemBurnTime = this.burnTime = IronAlloyFurnaceBlockEntity.getItemBurnTime(inventory.getInvStack(this.fuel)); - if (this.burnTime > 0) { - flag1 = true; - if (!inventory.getInvStack(this.fuel).isEmpty()) { - inventory.shrinkSlot(this.fuel, 1); - } + + boolean isBurning = isBurning(); + boolean updateInventory = false; + if (isBurning) { + --burnTime; + } + if (burnTime != 0 || !inventory.getInvStack(input1).isEmpty() && !inventory.getInvStack(fuel).isEmpty()) { + if (burnTime == 0 && canSmelt()) { + totalBurnTime = burnTime = getItemBurnTime(inventory.getInvStack(fuel)); + if (burnTime > 0) { + updateInventory = true; + if (!inventory.getInvStack(fuel).isEmpty()) { + inventory.shrinkSlot(fuel, 1); } } - if (this.isBurning() && this.canSmelt()) { - ++this.cookTime; - if (this.cookTime == 200) { - this.cookTime = 0; - this.smeltItem(); - flag1 = true; - } - } else { - this.cookTime = 0; - } } - if (flag != this.burnTime > 0) { - flag1 = true; + if (isBurning() && canSmelt()) { + ++cookTime; + if (cookTime == 200) { + cookTime = 0; + smeltItem(); + updateInventory = true; + } + } else { + cookTime = 0; } } - if (flag1) { - this.markDirty(); + if (isBurning != isBurning()) { + updateInventory = true; + updateState(); + } + + if (updateInventory) { + markDirty(); } } - public boolean hasAllInputs(final RebornRecipe recipeType) { + public boolean hasAllInputs(RebornRecipe recipeType) { if (recipeType == null) { return false; } @@ -128,12 +134,12 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity } private boolean canSmelt() { - if (inventory.getInvStack(this.input1).isEmpty() || inventory.getInvStack(this.input2).isEmpty()) { + if (inventory.getInvStack(input1).isEmpty() || inventory.getInvStack(input2).isEmpty()) { return false; } ItemStack itemstack = null; - for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) { - if (this.hasAllInputs(recipeType)) { + for (RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) { + if (hasAllInputs(recipeType)) { itemstack = recipeType.getOutputs().get(0); break; } @@ -141,12 +147,12 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity if (itemstack == null) return false; - if (inventory.getInvStack(this.output).isEmpty()) + if (inventory.getInvStack(output).isEmpty()) return true; - if (!inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack)) + if (!inventory.getInvStack(output).isItemEqualIgnoreDamage(itemstack)) return false; - final int result = inventory.getInvStack(this.output).getCount() + itemstack.getCount(); - return result <= inventory.getStackLimit() && result <= inventory.getInvStack(this.output).getMaxCount(); + int result = inventory.getInvStack(output).getCount() + itemstack.getCount(); + return result <= inventory.getStackLimit() && result <= inventory.getInvStack(output).getMaxCount(); } /** @@ -154,44 +160,39 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity * item in the furnace result stack */ public void smeltItem() { - if (this.canSmelt()) { - ItemStack itemstack = ItemStack.EMPTY; - for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) { - if (this.hasAllInputs(recipeType)) { - itemstack = recipeType.getOutputs().get(0); - break; - } - if (!itemstack.isEmpty()) { - break; - } - } - - if (inventory.getInvStack(this.output).isEmpty()) { - inventory.setInvStack(this.output, itemstack.copy()); - } else if (inventory.getInvStack(this.output).getItem() == itemstack.getItem()) { - inventory.shrinkSlot(this.output, -itemstack.getCount()); - } - - for (final RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) { - boolean hasAllRecipes = true; - if (this.hasAllInputs(recipeType)) { - - } else { - hasAllRecipes = false; - } - if (hasAllRecipes) { - for (RebornIngredient ingredient : recipeType.getRebornIngredients()) { - for (int inputSlot = 0; inputSlot < 2; inputSlot++) { - if (ingredient.test(this.inventory.getInvStack(inputSlot))) { - inventory.shrinkSlot(inputSlot, ingredient.getCount()); - break; - } - } - } - } - } - + if (!canSmelt()) { + return; } + + ItemStack outputStack = ItemStack.EMPTY; + RebornRecipe currentRecipe = null; + for (RebornRecipe recipeType : ModRecipes.ALLOY_SMELTER.getRecipes(world)) { + if (hasAllInputs(recipeType)) { + currentRecipe = recipeType; + break; + } + } + if (currentRecipe == null) { + return; + } + outputStack = currentRecipe.getOutputs().get(0); + if (outputStack.isEmpty()) { + return; + } + if (inventory.getInvStack(output).isEmpty()) { + inventory.setInvStack(output, outputStack.copy()); + } else if (inventory.getInvStack(output).getItem() == outputStack.getItem()) { + inventory.shrinkSlot(output, -outputStack.getCount()); + } + + for (RebornIngredient ingredient : currentRecipe.getRebornIngredients()) { + for (int inputSlot = 0; inputSlot < 2; inputSlot++) { + if (ingredient.test(inventory.getInvStack(inputSlot))) { + inventory.shrinkSlot(inputSlot, ingredient.getCount()); + break; + } + } + } } /** @@ -199,57 +200,66 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity * @return Boolean True if furnace is burning */ public boolean isBurning() { - return this.burnTime > 0; + return burnTime > 0; } - public int getBurnTimeRemainingScaled(final int scale) { - if (this.currentItemBurnTime == 0) { - this.currentItemBurnTime = 200; + public int getBurnTimeRemainingScaled(int scale) { + if (totalBurnTime == 0) { + totalBurnTime = 200; } - return this.burnTime * scale / this.currentItemBurnTime; + return burnTime * scale / totalBurnTime; } - public int getCookProgressScaled(final int scale) { - return this.cookTime * scale / 200; + public int getCookProgressScaled(int scale) { + return cookTime * scale / 200; + } + + public void updateState() { + BlockState state = world.getBlockState(pos); + if (state.getBlock() instanceof BlockMachineBase) { + BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock(); + if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0) + blockMachineBase.setActive(burnTime > 0, world, pos); + } } @Override public Direction getFacing() { - return this.getFacingEnum(); + return getFacingEnum(); } @Override - public ItemStack getToolDrop(final PlayerEntity entityPlayer) { + public ItemStack getToolDrop(PlayerEntity entityPlayer) { return TRContent.Machine.IRON_ALLOY_FURNACE.getStack(); } @Override public RebornInventory getInventory() { - return this.inventory; + return inventory; } public int getBurnTime() { - return this.burnTime; + return burnTime; } - public void setBurnTime(final int burnTime) { + public void setBurnTime(int burnTime) { this.burnTime = burnTime; } - public int getCurrentItemBurnTime() { - return this.currentItemBurnTime; + public int getTotalBurnTime() { + return totalBurnTime; } - public void setCurrentItemBurnTime(final int currentItemBurnTime) { - this.currentItemBurnTime = currentItemBurnTime; + public void setTotalBurnTime(int currentItemBurnTime) { + this.totalBurnTime = currentItemBurnTime; } public int getCookTime() { - return this.cookTime; + return cookTime; } - public void setCookTime(final int cookTime) { + public void setCookTime(int cookTime) { this.cookTime = cookTime; } @@ -261,7 +271,7 @@ public class IronAlloyFurnaceBlockEntity extends MachineBaseBlockEntity .slot(1, 65, 17) .outputSlot(2, 116, 35).fuelSlot(3, 56, 53).syncIntegerValue(this::getBurnTime, this::setBurnTime) .syncIntegerValue(this::getCookTime, this::setCookTime) - .syncIntegerValue(this::getCurrentItemBurnTime, this::setCurrentItemBurnTime).addInventory().create(this, syncID); + .syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID); } @Override diff --git a/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java b/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java index 71a1dd9ac..b563ef584 100644 --- a/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java @@ -46,31 +46,31 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity public int tickTime; public RebornInventory inventory = new RebornInventory<>(3, "IronFurnaceBlockEntity", 64, this, getInvetoryAccess()); - public int fuel; - public int fuelGague; + public int burnTime; + public int totalBurnTime; public int progress; public int fuelScale = 160; - int input1 = 0; - int output = 1; - int fuelslot = 2; + int inputSlot = 0; + int outputSlot = 1; + int fuelSlot = 2; boolean active = false; public IronFurnaceBlockEntity() { super(TRBlockEntities.IRON_FURNACE); } - public int gaugeProgressScaled(final int scale) { - return this.progress * scale / this.fuelScale; + public int gaugeProgressScaled(int scale) { + return progress * scale / fuelScale; } - public int gaugeFuelScaled(final int scale) { - if (this.fuelGague == 0) { - this.fuelGague = this.fuel; - if (this.fuelGague == 0) { - this.fuelGague = this.fuelScale; + public int gaugeFuelScaled(int scale) { + if (totalBurnTime == 0) { + totalBurnTime = burnTime; + if (totalBurnTime == 0) { + totalBurnTime = fuelScale; } } - return this.fuel * scale / this.fuelGague; + return burnTime * scale / totalBurnTime; } @Override @@ -79,94 +79,96 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity if(world.isClient){ return; } - final boolean burning = this.isBurning(); + boolean isBurning = isBurning(); boolean updateInventory = false; - if (this.fuel > 0) { - fuel--; + if (isBurning) { + --burnTime; } - updateState(); - if (this.fuel <= 0 && this.canSmelt()) { - this.fuel = this.fuelGague = (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(inventory.getInvStack(this.fuelslot).getItem(), 0) * 1.25); - if (this.fuel > 0) { + + if (burnTime <= 0 && canSmelt()) { + burnTime = totalBurnTime = (int) (AbstractFurnaceBlockEntity.createFuelTimeMap().getOrDefault(inventory.getInvStack(fuelSlot).getItem(), 0) * 1.25); + if (burnTime > 0) { // Fuel slot - ItemStack fuelStack = inventory.getInvStack(this.fuelslot); + ItemStack fuelStack = inventory.getInvStack(fuelSlot); if (fuelStack.getItem().hasRecipeRemainder()) { - inventory.setInvStack(this.fuelslot, new ItemStack(fuelStack.getItem().getRecipeRemainder())); + inventory.setInvStack(fuelSlot, new ItemStack(fuelStack.getItem().getRecipeRemainder())); } else if (fuelStack.getCount() > 1) { - inventory.shrinkSlot(this.fuelslot, 1); + inventory.shrinkSlot(fuelSlot, 1); } else if (fuelStack.getCount() == 1) { - inventory.setInvStack(this.fuelslot, ItemStack.EMPTY); + inventory.setInvStack(fuelSlot, ItemStack.EMPTY); } updateInventory = true; } } - if (this.isBurning() && this.canSmelt()) { - this.progress++; - if (this.progress >= this.fuelScale) { - this.progress = 0; - this.cookItems(); + if (isBurning() && canSmelt()) { + progress++; + if (progress >= fuelScale) { + progress = 0; + cookItems(); updateInventory = true; } } else { - this.progress = 0; + progress = 0; } - if (burning != this.isBurning()) { + if (isBurning != isBurning()) { updateInventory = true; + updateState(); } if (updateInventory) { - this.markDirty(); + markDirty(); } } public void cookItems() { - if (this.canSmelt()) { - final ItemStack itemstack = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(this.input1)); - - if (inventory.getInvStack(this.output).isEmpty()) { - inventory.setInvStack(this.output, itemstack.copy()); - } else if (inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack)) { - inventory.getInvStack(this.output).increment(itemstack.getCount()); - } - if (inventory.getInvStack(this.input1).getCount() > 1) { - inventory.shrinkSlot(this.input1, 1); - } else { - inventory.setInvStack(this.input1, ItemStack.EMPTY); - } + if (!canSmelt()) { + return; + } + ItemStack outputStack = getResultFor(inventory.getInvStack(inputSlot)); + if (inventory.getInvStack(outputSlot).isEmpty()) { + inventory.setInvStack(outputSlot, outputStack.copy()); + } else if (inventory.getInvStack(outputSlot).isItemEqualIgnoreDamage(outputStack)) { + inventory.getInvStack(outputSlot).increment(outputStack.getCount()); + } + if (inventory.getInvStack(inputSlot).getCount() > 1) { + inventory.shrinkSlot(inputSlot, 1); + } else { + inventory.setInvStack(inputSlot, ItemStack.EMPTY); } } public boolean canSmelt() { - if (inventory.getInvStack(this.input1).isEmpty()) + if (inventory.getInvStack(inputSlot).isEmpty()) { return false; - final ItemStack itemstack = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, inventory.getInvStack(this.input1)); - if (itemstack.isEmpty()) + } + ItemStack outputStack = getResultFor(inventory.getInvStack(inputSlot)); + if (outputStack.isEmpty()) return false; - if (inventory.getInvStack(this.output).isEmpty()) + if (inventory.getInvStack(outputSlot).isEmpty()) return true; - if (!inventory.getInvStack(this.output).isItemEqualIgnoreDamage(itemstack)) + if (!inventory.getInvStack(outputSlot).isItemEqualIgnoreDamage(outputStack)) return false; - final int result = inventory.getInvStack(this.output).getCount() + itemstack.getCount(); - return result <= inventory.getStackLimit() && result <= itemstack.getMaxCount(); + int result = inventory.getInvStack(outputSlot).getCount() + outputStack.getCount(); + return result <= inventory.getStackLimit() && result <= outputStack.getMaxCount(); } public boolean isBurning() { - return this.fuel > 0; + return burnTime > 0; } - public ItemStack getResultFor(final ItemStack stack) { - final ItemStack result = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, stack); + private ItemStack getResultFor(ItemStack stack) { + ItemStack result = RecipeUtils.getMatchingRecipes(world, RecipeType.SMELTING, stack); if (!result.isEmpty()) { return result.copy(); } return ItemStack.EMPTY; } - public void updateState() { - BlockState state = world.getBlockState(this.pos); + private void updateState() { + BlockState state = world.getBlockState(pos); if (state.getBlock() instanceof BlockMachineBase) { BlockMachineBase blockMachineBase = (BlockMachineBase) state.getBlock(); - if (state.get(BlockMachineBase.ACTIVE) != this.fuel > 0) - blockMachineBase.setActive(this.fuel > 0, this.world, this.pos); + if (state.get(BlockMachineBase.ACTIVE) != burnTime > 0) + blockMachineBase.setActive(burnTime > 0, world, pos); } } @@ -180,12 +182,12 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity if(direction == IInventoryAccess.AccessDirection.INSERT){ boolean isFuel = AbstractFurnaceBlockEntity.canUseAsFuel(stack); if(isFuel){ - ItemStack fuelSlotStack = blockEntity.inventory.getInvStack(blockEntity.fuelslot); + ItemStack fuelSlotStack = blockEntity.inventory.getInvStack(blockEntity.fuelSlot); if(fuelSlotStack.isEmpty() || ItemUtils.isItemEqual(stack, fuelSlotStack, true, true) && fuelSlotStack.getMaxCount() != fuelSlotStack.getCount()){ - return slotID == blockEntity.fuelslot; + return slotID == blockEntity.fuelSlot; } } - return slotID != blockEntity.output; + return slotID != blockEntity.outputSlot; } return true; }; @@ -197,19 +199,19 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity } public int getBurnTime() { - return this.fuel; + return this.burnTime; } - public void setBurnTime(final int burnTime) { - this.fuel = burnTime; + public void setBurnTime(int burnTime) { + this.burnTime = burnTime; } public int getTotalBurnTime() { - return this.fuelGague; + return this.totalBurnTime; } - public void setTotalBurnTime(final int totalBurnTime) { - this.fuelGague = totalBurnTime; + public void setTotalBurnTime(int totalBurnTime) { + this.totalBurnTime = totalBurnTime; } public int getProgress() { @@ -222,7 +224,7 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity @Override public BuiltContainer createContainer(int syncID, final PlayerEntity player) { - return new ContainerBuilder("ironfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142) + return new ContainerBuilder("ironfurnace").player(player.inventory).inventory().hotbar() .addInventory().blockEntity(this).fuelSlot(2, 56, 53).slot(0, 56, 17).outputSlot(1, 116, 35) .syncIntegerValue(this::getBurnTime, this::setBurnTime) .syncIntegerValue(this::getProgress, this::setProgress) diff --git a/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java b/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java index e4d1d13c3..cc1d7a3d7 100644 --- a/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java +++ b/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java @@ -32,39 +32,40 @@ import techreborn.blockentity.machine.iron.IronAlloyFurnaceBlockEntity; public class GuiAlloyFurnace extends GuiBase { - IronAlloyFurnaceBlockEntity alloyfurnace; + IronAlloyFurnaceBlockEntity blockEntity; - public GuiAlloyFurnace(int syncID, final PlayerEntity player, final IronAlloyFurnaceBlockEntity alloyFurnace) { + public GuiAlloyFurnace(int syncID, PlayerEntity player, IronAlloyFurnaceBlockEntity alloyFurnace) { super(player, alloyFurnace, alloyFurnace.createContainer(syncID, player)); - this.alloyfurnace = alloyFurnace; + this.blockEntity = alloyFurnace; } @Override - protected void drawBackground(final float f, final int mouseX, final int mouseY) { - super.drawBackground(f, mouseX, mouseY); + protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) { + super.drawBackground(lastFrameDuration, mouseX, mouseY); - final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; + GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; + // Input slots drawSlot(47, 17, layer); drawSlot(65, 17, layer); - + // Fuel slot drawSlot(56, 53, layer); drawOutputSlot(116, 35, layer); } @Override - protected void drawForeground(final int mouseX, final int mouseY) { + protected void drawForeground(int mouseX, int mouseY) { super.drawForeground(mouseX, mouseY); - final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; + GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; - builder.drawProgressBar(this, alloyfurnace.getCookProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); - builder.drawBurnBar(this, alloyfurnace.getBurnTimeRemainingScaled(100), 100, 56, 36, mouseX, mouseY, layer); + builder.drawProgressBar(this, blockEntity.getCookProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); + builder.drawBurnBar(this, blockEntity.getBurnTimeRemainingScaled(100), 100, 56, 36, mouseX, mouseY, layer); } @Override - public void render(int mouseX, int mouseY, float partialTicks) { - super.render(mouseX, mouseY, partialTicks); + public void render(int mouseX, int mouseY, float lastFrameDuration) { + super.render(mouseX, mouseY, lastFrameDuration); this.drawMouseoverTooltip(mouseX, mouseY); } } diff --git a/src/main/java/techreborn/client/gui/GuiIronFurnace.java b/src/main/java/techreborn/client/gui/GuiIronFurnace.java index 75445c832..ea6c3c4eb 100644 --- a/src/main/java/techreborn/client/gui/GuiIronFurnace.java +++ b/src/main/java/techreborn/client/gui/GuiIronFurnace.java @@ -24,47 +24,46 @@ package techreborn.client.gui; -import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Identifier; import reborncore.client.containerBuilder.builder.BuiltContainer; import reborncore.client.gui.builder.GuiBase; -import techreborn.init.TRContent; +import reborncore.client.gui.guibuilder.GuiBuilder; import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity; public class GuiIronFurnace extends GuiBase { - public static final Identifier texture = new Identifier("minecraft", - "textures/gui/container/furnace.png"); - IronFurnaceBlockEntity blockEntity; - public GuiIronFurnace(int syncID, final PlayerEntity player, final IronFurnaceBlockEntity furnace) { + public GuiIronFurnace(int syncID, PlayerEntity player, IronFurnaceBlockEntity furnace) { super(player, furnace, furnace.createContainer(syncID, player)); this.blockEntity = furnace; } + + @Override + protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) { + super.drawBackground(lastFrameDuration, mouseX, mouseY); + final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; + + // Input slot + drawSlot(56, 17, layer); + // Fuel slot + drawSlot(56, 53, layer); + + drawOutputSlot(116, 35, layer); + } + + @Override + protected void drawForeground(final int mouseX, final int mouseY) { + super.drawForeground(mouseX, mouseY); + final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; + + builder.drawProgressBar(this, blockEntity.gaugeProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); + builder.drawBurnBar(this, blockEntity.gaugeFuelScaled(100), 100, 56, 36, mouseX, mouseY, layer); + } @Override - protected void drawBackground(float partialTicks, int mouseX, int mouseY) { - renderBackground(); - GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); - builder.drawSlotTab(this, left - 24, top + 6, new ItemStack(TRContent.WRENCH)); - minecraft.getTextureManager().bindTexture(GuiIronFurnace.texture); - final int k = (this.width - containerWidth) / 2; - final int l = (this.height - containerHeight) / 2; - blit(k, l, 0, 0, containerWidth, containerHeight); - - int j = 0; - - j = blockEntity.gaugeProgressScaled(24); - if (j > 0) { - blit(k + 78, l + 35, 176, 14, j + 1, 16); - } - - j = blockEntity.gaugeFuelScaled(12); - if (j > 0) { - blit(k + 57, l + 36 + 12 - j, 176, 12 - j, 14, j + 2); - } + public void render(int mouseX, int mouseY, float lastFrameDuration) { + super.render(mouseX, mouseY, lastFrameDuration); + this.drawMouseoverTooltip(mouseX, mouseY); } }