Fix experience button in Iron Furnace. Closes #2692
This commit is contained in:
parent
d6dfe57963
commit
5f7570cfff
4 changed files with 54 additions and 46 deletions
|
@ -29,7 +29,7 @@ import net.minecraft.text.Text;
|
||||||
import org.apache.logging.log4j.util.TriConsumer;
|
import org.apache.logging.log4j.util.TriConsumer;
|
||||||
|
|
||||||
|
|
||||||
public class GuiButtonExtended extends GuiButtonSimple {
|
public class GuiButtonExtended extends ButtonWidget {
|
||||||
|
|
||||||
private TriConsumer<GuiButtonExtended, Double, Double> clickHandler;
|
private TriConsumer<GuiButtonExtended, Double, Double> clickHandler;
|
||||||
|
|
||||||
|
@ -51,6 +51,6 @@ public class GuiButtonExtended extends GuiButtonSimple {
|
||||||
if (clickHandler != null) {
|
if (clickHandler != null) {
|
||||||
clickHandler.accept(this, mouseX, mouseY);
|
clickHandler.accept(this, mouseX, mouseY);
|
||||||
}
|
}
|
||||||
super.onClick(mouseY, mouseY);
|
super.onClick(mouseX, mouseY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,10 +28,19 @@ import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
|
|
||||||
public class GuiButtonSimple extends ButtonWidget {
|
public class GuiButtonSimple extends ButtonWidget {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Please use {@link ButtonWidget}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public GuiButtonSimple(int x, int y, Text buttonText, ButtonWidget.PressAction pressAction) {
|
public GuiButtonSimple(int x, int y, Text buttonText, ButtonWidget.PressAction pressAction) {
|
||||||
super(x, y, 20, 200, buttonText, pressAction);
|
super(x, y, 20, 200, buttonText, pressAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated Please use {@link ButtonWidget}
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public GuiButtonSimple(int x, int y, int widthIn, int heightIn, Text buttonText, ButtonWidget.PressAction pressAction) {
|
public GuiButtonSimple(int x, int y, int widthIn, int heightIn, Text buttonText, ButtonWidget.PressAction pressAction) {
|
||||||
super(x, y, widthIn, heightIn, buttonText, pressAction);
|
super(x, y, widthIn, heightIn, buttonText, pressAction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,13 +24,13 @@
|
||||||
|
|
||||||
package techreborn.client.gui;
|
package techreborn.client.gui;
|
||||||
|
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import reborncore.client.ClientChunkManager;
|
import reborncore.client.ClientChunkManager;
|
||||||
import reborncore.client.gui.builder.GuiBase;
|
import reborncore.client.gui.builder.GuiBase;
|
||||||
import reborncore.client.gui.builder.widget.GuiButtonSimple;
|
|
||||||
import reborncore.client.gui.builder.widget.GuiButtonUpDown;
|
import reborncore.client.gui.builder.widget.GuiButtonUpDown;
|
||||||
import reborncore.client.gui.builder.widget.GuiButtonUpDown.UpDownButtonType;
|
import reborncore.client.gui.builder.widget.GuiButtonUpDown.UpDownButtonType;
|
||||||
import reborncore.client.screen.builder.BuiltScreenHandler;
|
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||||
|
@ -54,7 +54,7 @@ public class GuiChunkLoader extends GuiBase<BuiltScreenHandler> {
|
||||||
addDrawableChild(new GuiButtonUpDown(x + 64 + 24, y + 40, this, b -> onClick(-1), UpDownButtonType.REWIND));
|
addDrawableChild(new GuiButtonUpDown(x + 64 + 24, y + 40, this, b -> onClick(-1), UpDownButtonType.REWIND));
|
||||||
addDrawableChild(new GuiButtonUpDown(x + 64 + 36, y + 40, this, b -> onClick(-5), UpDownButtonType.FASTREWIND));
|
addDrawableChild(new GuiButtonUpDown(x + 64 + 36, y + 40, this, b -> onClick(-5), UpDownButtonType.FASTREWIND));
|
||||||
|
|
||||||
addDrawableChild(new GuiButtonSimple(x + 10, y + 70, 155, 20, new LiteralText("Toggle Loaded Chunks"), b -> ClientChunkManager.toggleLoadedChunks(blockEntity.getPos())));
|
addDrawableChild(new ButtonWidget(x + 10, y + 70, 155, 20, new LiteralText("Toggle Loaded Chunks"), b -> ClientChunkManager.toggleLoadedChunks(blockEntity.getPos())));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -24,16 +24,14 @@
|
||||||
|
|
||||||
package techreborn.client.gui;
|
package techreborn.client.gui;
|
||||||
|
|
||||||
import com.mojang.blaze3d.systems.RenderSystem;
|
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||||
|
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.item.ItemStack;
|
|
||||||
import net.minecraft.item.Items;
|
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.util.Identifier;
|
||||||
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.client.screen.builder.BuiltScreenHandler;
|
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||||
import reborncore.common.network.NetworkManager;
|
import reborncore.common.network.NetworkManager;
|
||||||
|
@ -41,12 +39,10 @@ import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
|
||||||
import techreborn.packets.ServerboundPackets;
|
import techreborn.packets.ServerboundPackets;
|
||||||
import techreborn.utils.PlayerUtils;
|
import techreborn.utils.PlayerUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class GuiIronFurnace extends GuiBase<BuiltScreenHandler> {
|
public class GuiIronFurnace extends GuiBase<BuiltScreenHandler> {
|
||||||
|
|
||||||
IronFurnaceBlockEntity blockEntity;
|
IronFurnaceBlockEntity blockEntity;
|
||||||
|
private static final Identifier EXP_BUTTON_TEXTURE = new Identifier("minecraft", "textures/item/experience_bottle.png");
|
||||||
|
|
||||||
|
|
||||||
public GuiIronFurnace(int syncID, PlayerEntity player, IronFurnaceBlockEntity furnace) {
|
public GuiIronFurnace(int syncID, PlayerEntity player, IronFurnaceBlockEntity furnace) {
|
||||||
|
@ -61,46 +57,49 @@ public class GuiIronFurnace extends GuiBase<BuiltScreenHandler> {
|
||||||
@Override
|
@Override
|
||||||
public void init() {
|
public void init() {
|
||||||
super.init();
|
super.init();
|
||||||
addSelectableChild(new GuiButtonSimple(getGuiLeft() + 116, getGuiTop() + 57, 18, 18, LiteralText.EMPTY, b -> onClick()) {
|
ButtonWidget.TooltipSupplier tooltipSupplier = (button, matrices, mouseX, mouseY) -> {
|
||||||
|
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||||
|
if (player == null) { return; }
|
||||||
|
String message = "Experience: ";
|
||||||
|
|
||||||
@Override
|
float furnaceExp = blockEntity.experience;
|
||||||
public void renderTooltip(MatrixStack matrixStack, int mouseX, int mouseY) {
|
if (furnaceExp <= 0) {
|
||||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
message = message + "0";
|
||||||
String message = "Experience: ";
|
} else {
|
||||||
|
float expTillLevel = (1.0F - player.experienceProgress) * player.getNextLevelExperience();
|
||||||
float furnaceExp = blockEntity.experience;
|
if (furnaceExp <= expTillLevel) {
|
||||||
if (furnaceExp <= 0) {
|
int percentage = (int) (blockEntity.experience * 100 / player.getNextLevelExperience());
|
||||||
message = message + "0";
|
message = message + "+"
|
||||||
|
+ (percentage > 0 ? String.valueOf(percentage) : "<1")
|
||||||
|
+ "%";
|
||||||
} else {
|
} else {
|
||||||
float expTillLevel = (1.0F - player.experienceProgress) * player.getNextLevelExperience();
|
int levels = 0;
|
||||||
if (furnaceExp <= expTillLevel) {
|
furnaceExp -= expTillLevel;
|
||||||
int percentage = (int) (blockEntity.experience * 100 / player.getNextLevelExperience());
|
while (furnaceExp > 0) {
|
||||||
message = message + "+"
|
furnaceExp -= PlayerUtils.getLevelExperience(player.experienceLevel);
|
||||||
+ (percentage > 0 ? String.valueOf(percentage) : "<1")
|
++levels;
|
||||||
+ "%";
|
|
||||||
} else {
|
|
||||||
int levels = 0;
|
|
||||||
furnaceExp -= expTillLevel;
|
|
||||||
while (furnaceExp > 0) {
|
|
||||||
furnaceExp -= PlayerUtils.getLevelExperience(player.experienceLevel);
|
|
||||||
++levels;
|
|
||||||
}
|
|
||||||
message = message + "+" + levels + "L";
|
|
||||||
}
|
}
|
||||||
|
message = message + "+" + levels + "L";
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Text> list = new ArrayList<>();
|
|
||||||
list.add(new LiteralText(message));
|
|
||||||
GuiIronFurnace.this.renderTooltip(matrixStack, list, mouseX, mouseY);
|
|
||||||
RenderSystem.setShaderColor(1, 1, 1, 1);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
renderTooltip(matrices, new LiteralText(message), mouseX, mouseY);
|
||||||
protected void renderBackground(MatrixStack matrices, MinecraftClient client, int mouseX, int mouseY) {
|
};
|
||||||
client.getItemRenderer().renderInGuiWithOverrides(new ItemStack(Items.EXPERIENCE_BOTTLE), x, y);
|
|
||||||
}
|
addDrawableChild(new TexturedButtonWidget(
|
||||||
});
|
getGuiLeft() + 116,
|
||||||
|
getGuiTop() + 58,
|
||||||
|
16,
|
||||||
|
16,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
1,
|
||||||
|
EXP_BUTTON_TEXTURE,
|
||||||
|
16,
|
||||||
|
16,
|
||||||
|
b -> onClick(),
|
||||||
|
tooltipSupplier,
|
||||||
|
LiteralText.EMPTY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue