Iron furnace drops experience. Still need to save fuel time to tag

This commit is contained in:
drcrazy 2019-08-28 02:46:56 +03:00
parent 09b59d6c87
commit 0d68f794ae
4 changed files with 57 additions and 25 deletions

View file

@ -60,7 +60,7 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
int outputSlot = 1; int outputSlot = 1;
int fuelSlot = 2; int fuelSlot = 2;
boolean active = false; boolean active = false;
private float experience; public float experience;
public IronFurnaceBlockEntity() { public IronFurnaceBlockEntity() {
super(TRBlockEntities.IRON_FURNACE); super(TRBlockEntities.IRON_FURNACE);
@ -161,10 +161,10 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
totalExperience -= expToDrop; totalExperience -= expToDrop;
player.world.spawnEntity(new ExperienceOrbEntity(player.world, player.x, player.y + 0.5D, player.z + 0.5D, 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() { private void updateState() {
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);
if (state.getBlock() instanceof BlockMachineBase) { if (state.getBlock() instanceof BlockMachineBase) {
@ -269,6 +269,14 @@ public class IronFurnaceBlockEntity extends MachineBaseBlockEntity
public void setProgress(int progress) { public void setProgress(int progress) {
this.progress = progress; this.progress = progress;
} }
public float getExperience() {
return experience;
}
public void setExperience(float experience) {
this.experience = experience;
}
@Override @Override
public BuiltContainer createContainer(int syncID, final PlayerEntity player) { 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) .addInventory().blockEntity(this).fuelSlot(2, 56, 53).slot(0, 56, 17).outputSlot(1, 116, 35)
.syncIntegerValue(this::getBurnTime, this::setBurnTime) .syncIntegerValue(this::getBurnTime, this::setBurnTime)
.syncIntegerValue(this::getProgress, this::setProgress) .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);
} }
} }

View file

@ -43,6 +43,14 @@ public class GuiAESU extends GuiBase<BuiltContainer> {
super(player, aesu, aesu.createContainer(syncID, player)); super(player, aesu, aesu.createContainer(syncID, player));
this.blockEntity = aesu; 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 @Override
protected void drawBackground(final float f, final int mouseX, final int mouseY) { protected void drawBackground(final float f, final int mouseX, final int mouseY) {
@ -71,13 +79,6 @@ public class GuiAESU extends GuiBase<BuiltContainer> {
} }
builder.drawMultiEnergyBar(this, 81, 28, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); 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){ public void onClick(int amount){

View file

@ -42,7 +42,6 @@ public class GuiAlloyFurnace extends GuiBase<BuiltContainer> {
@Override @Override
protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) { protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) {
super.drawBackground(lastFrameDuration, mouseX, mouseY); super.drawBackground(lastFrameDuration, mouseX, mouseY);
GuiBase.Layer layer = GuiBase.Layer.BACKGROUND; GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
// Input slots // Input slots
@ -62,10 +61,4 @@ public class GuiAlloyFurnace extends GuiBase<BuiltContainer> {
builder.drawProgressBar(this, blockEntity.getCookProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, 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); 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);
}
} }

View file

@ -24,9 +24,17 @@
package techreborn.client.gui; 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 net.minecraft.entity.player.PlayerEntity;
import reborncore.client.containerBuilder.builder.BuiltContainer; import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.gui.builder.GuiBase; import reborncore.client.gui.builder.GuiBase;
import reborncore.client.gui.builder.widget.GuiButtonSimple;
import reborncore.client.gui.guibuilder.GuiBuilder; import reborncore.client.gui.guibuilder.GuiBuilder;
import reborncore.common.network.NetworkManager; import reborncore.common.network.NetworkManager;
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity; import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
@ -41,10 +49,27 @@ public class GuiIronFurnace extends GuiBase<BuiltContainer> {
this.blockEntity = furnace; this.blockEntity = furnace;
} }
public void onClick(int amount){ public void onClick(){
NetworkManager.sendToServer(ServerboundPackets.createPacketExperience(blockEntity)); 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<String> list = new ArrayList<>();
list.add("Expirience accumulated: " + blockEntity.experience);
renderTooltip(list, mouseX - getGuiLeft(), mouseY - getGuiTop());
GlStateManager.disableLighting();
GlStateManager.color4f(1, 1, 1, 1);
}
});
}
@Override @Override
protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) { protected void drawBackground(float lastFrameDuration, int mouseX, int mouseY) {
super.drawBackground(lastFrameDuration, mouseX, mouseY); super.drawBackground(lastFrameDuration, mouseX, mouseY);
@ -59,17 +84,20 @@ public class GuiIronFurnace extends GuiBase<BuiltContainer> {
} }
@Override @Override
protected void drawForeground(final int mouseX, final int mouseY) { protected void drawForeground(int mouseX, int mouseY) {
super.drawForeground(mouseX, mouseY); super.drawForeground(mouseX, mouseY);
final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND; final GuiBase.Layer layer = GuiBase.Layer.FOREGROUND;
builder.drawProgressBar(this, blockEntity.gaugeProgressScaled(100), 100, 85, 36, mouseX, mouseY, GuiBuilder.ProgressDirection.RIGHT, layer); 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); builder.drawBurnBar(this, blockEntity.gaugeFuelScaled(100), 100, 56, 36, mouseX, mouseY, layer);
} Iterator<AbstractButtonWidget> buttonsList = this.buttons.iterator();
@Override while (buttonsList.hasNext()) {
public void render(int mouseX, int mouseY, float lastFrameDuration) { AbstractButtonWidget abstractButtonWidget = (AbstractButtonWidget) buttonsList.next();
super.render(mouseX, mouseY, lastFrameDuration); if (abstractButtonWidget.isHovered()) {
this.drawMouseoverTooltip(mouseX, mouseY); abstractButtonWidget.renderToolTip(mouseX, mouseY);
break;
}
}
} }
} }