From 0d68f794ae2049aff3023fac3c3a5ddf7eba5ed0 Mon Sep 17 00:00:00 2001 From: drcrazy Date: Wed, 28 Aug 2019 02:46:56 +0300 Subject: [PATCH] Iron furnace drops experience. Still need to save fuel time to tag --- .../machine/iron/IronFurnaceBlockEntity.java | 18 ++++++-- .../java/techreborn/client/gui/GuiAESU.java | 15 +++---- .../client/gui/GuiAlloyFurnace.java | 7 ---- .../techreborn/client/gui/GuiIronFurnace.java | 42 +++++++++++++++---- 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java b/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java index 8eadfb800..33ba02a08 100644 --- a/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java +++ b/src/main/java/techreborn/blockentity/machine/iron/IronFurnaceBlockEntity.java @@ -60,7 +60,7 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity int outputSlot = 1; int fuelSlot = 2; boolean active = false; - private float experience; + public float experience; public IronFurnaceBlockEntity() { super(TRBlockEntities.IRON_FURNACE); @@ -161,10 +161,10 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity totalExperience -= expToDrop; player.world.spawnEntity(new ExperienceOrbEntity(player.world, player.x, player.y + 0.5D, player.z + 0.5D, expToDrop)); } - experience = 0; } + experience = 0; } - + private void updateState() { BlockState state = world.getBlockState(pos); if (state.getBlock() instanceof BlockMachineBase) { @@ -269,6 +269,14 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity public void setProgress(int progress) { this.progress = progress; } + + public float getExperience() { + return experience; + } + + public void setExperience(float experience) { + this.experience = experience; + } @Override public BuiltContainer createContainer(int syncID, final PlayerEntity player) { @@ -276,6 +284,8 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity .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) - .syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create(this, syncID); + .syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime) + .sync(this::getExperience, this::setExperience) + .addInventory().create(this, syncID); } } diff --git a/src/main/java/techreborn/client/gui/GuiAESU.java b/src/main/java/techreborn/client/gui/GuiAESU.java index d57c858df..15896c11d 100644 --- a/src/main/java/techreborn/client/gui/GuiAESU.java +++ b/src/main/java/techreborn/client/gui/GuiAESU.java @@ -43,6 +43,14 @@ public class GuiAESU extends GuiBase { super(player, aesu, aesu.createContainer(syncID, player)); this.blockEntity = aesu; } + + @Override + public void init() { + addButton(new GuiButtonUpDown(left + 121, top + 79, this, b -> onClick(256))); + addButton(new GuiButtonUpDown(left + 121 + 12, top + 79, this, b -> onClick(64))); + addButton(new GuiButtonUpDown(left + 121 + 24, top + 79, this, b -> onClick(-64))); + addButton(new GuiButtonUpDown(left + 121 + 36, top + 79, this, b -> onClick(-256))); + } @Override protected void drawBackground(final float f, final int mouseX, final int mouseY) { @@ -71,13 +79,6 @@ public class GuiAESU extends GuiBase { } builder.drawMultiEnergyBar(this, 81, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); - - addButton(new GuiButtonUpDown(left + 121, top + 79, this, b -> onClick(256))); - addButton(new GuiButtonUpDown(left + 121 + 12, top + 79, this, b -> onClick(64))); - addButton(new GuiButtonUpDown(left + 121 + 24, top + 79, this, b -> onClick(-64))); - addButton(new GuiButtonUpDown(left + 121 + 36, top + 79, this, b -> onClick(-256))); - - } public void onClick(int amount){ diff --git a/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java b/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java index cc1d7a3d7..7368f538f 100644 --- a/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java +++ b/src/main/java/techreborn/client/gui/GuiAlloyFurnace.java @@ -42,7 +42,6 @@ public class GuiAlloyFurnace extends GuiBase { @Override protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) { super.drawBackground(lastFrameDuration, mouseX, mouseY); - GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; // Input slots @@ -62,10 +61,4 @@ public class GuiAlloyFurnace extends GuiBase { 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 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 9d75a528b..76679d7f1 100644 --- a/src/main/java/techreborn/client/gui/GuiIronFurnace.java +++ b/src/main/java/techreborn/client/gui/GuiIronFurnace.java @@ -24,9 +24,17 @@ package techreborn.client.gui; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import com.mojang.blaze3d.platform.GlStateManager; + +import net.minecraft.client.gui.widget.AbstractButtonWidget; import net.minecraft.entity.player.PlayerEntity; import reborncore.client.containerBuilder.builder.BuiltContainer; import reborncore.client.gui.builder.GuiBase; +import reborncore.client.gui.builder.widget.GuiButtonSimple; import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.common.network.NetworkManager; import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity; @@ -41,10 +49,27 @@ public class GuiIronFurnace extends GuiBase { this.blockEntity = furnace; } - public void onClick(int amount){ + public void onClick(){ NetworkManager.sendToServer(ServerboundPackets.createPacketExperience(blockEntity)); } + @Override + public void init() { + super.init(); + addButton(new GuiButtonSimple(getGuiLeft() + 116, getGuiTop() + 57, 18, 18, "Exp", b -> onClick()) { + + + @Override + public void renderToolTip(int mouseX, int mouseY) { + List list = new ArrayList<>(); + list.add("Expirience accumulated: " + blockEntity.experience); + renderTooltip(list, mouseX - getGuiLeft(), mouseY - getGuiTop()); + GlStateManager.disableLighting(); + GlStateManager.color4f(1, 1, 1, 1); + } + }); + } + @Override protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) { super.drawBackground(lastFrameDuration, mouseX, mouseY); @@ -59,17 +84,20 @@ public class GuiIronFurnace extends GuiBase { } @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; 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); - } + Iterator buttonsList = this.buttons.iterator(); - @Override - public void render(int mouseX, int mouseY, float lastFrameDuration) { - super.render(mouseX, mouseY, lastFrameDuration); - this.drawMouseoverTooltip(mouseX, mouseY); + while (buttonsList.hasNext()) { + AbstractButtonWidget abstractButtonWidget = (AbstractButtonWidget) buttonsList.next(); + if (abstractButtonWidget.isHovered()) { + abstractButtonWidget.renderToolTip(mouseX, mouseY); + break; + } + } } }