Fix iron furnace xp button tooltip
This commit is contained in:
parent
08fd9a2e27
commit
9c3ef46665
1 changed files with 53 additions and 37 deletions
|
@ -24,8 +24,10 @@
|
|||
|
||||
package techreborn.client.gui;
|
||||
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.gui.widget.TexturedButtonWidget;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -35,57 +37,32 @@ import reborncore.client.gui.guibuilder.GuiBuilder;
|
|||
import reborncore.common.screen.BuiltScreenHandler;
|
||||
import techreborn.blockentity.machine.iron.IronFurnaceBlockEntity;
|
||||
import techreborn.packets.ServerboundPackets;
|
||||
import techreborn.utils.PlayerUtils;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class GuiIronFurnace extends GuiBase<BuiltScreenHandler> {
|
||||
|
||||
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) {
|
||||
super(player, furnace, furnace.createScreenHandler(syncID, player));
|
||||
this.blockEntity = furnace;
|
||||
}
|
||||
|
||||
public void onClick() {
|
||||
public void onClick(ButtonWidget buttonWidget) {
|
||||
ClientNetworkManager.sendToServer(ServerboundPackets.createPacketExperience(blockEntity));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
super.init();
|
||||
// TODO 1.19.3
|
||||
// ButtonWidget.TooltipSupplier tooltipSupplier = (button, matrices, mouseX, mouseY) -> {
|
||||
// PlayerEntity player = MinecraftClient.getInstance().player;
|
||||
// if (player == null) { return; }
|
||||
// String message = "Experience: ";
|
||||
//
|
||||
// float furnaceExp = blockEntity.experience;
|
||||
// if (furnaceExp <= 0) {
|
||||
// message = message + "0";
|
||||
// } else {
|
||||
// float expTillLevel = (1.0F - player.experienceProgress) * player.getNextLevelExperience();
|
||||
// if (furnaceExp <= expTillLevel) {
|
||||
// int percentage = (int) (blockEntity.experience * 100 / player.getNextLevelExperience());
|
||||
// message = message + "+"
|
||||
// + (percentage > 0 ? String.valueOf(percentage) : "<1")
|
||||
// + "%";
|
||||
// } else {
|
||||
// int levels = 0;
|
||||
// furnaceExp -= expTillLevel;
|
||||
// while (furnaceExp > 0) {
|
||||
// furnaceExp -= PlayerUtils.getLevelExperience(player.experienceLevel);
|
||||
// ++levels;
|
||||
// }
|
||||
// message = message + "+" + levels + "L";
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// renderTooltip(matrices, Text.literal(message), mouseX, mouseY);
|
||||
// };
|
||||
addDrawableChild(new XpButtonWidget(this::onClick));
|
||||
}
|
||||
|
||||
addDrawableChild(new TexturedButtonWidget(
|
||||
getGuiLeft() + 116,
|
||||
private class XpButtonWidget extends TexturedButtonWidget {
|
||||
public XpButtonWidget(PressAction pressAction) {
|
||||
super(getGuiLeft() + 116,
|
||||
getGuiTop() + 58,
|
||||
16,
|
||||
16,
|
||||
|
@ -95,8 +72,47 @@ public class GuiIronFurnace extends GuiBase<BuiltScreenHandler> {
|
|||
EXP_BUTTON_TEXTURE,
|
||||
16,
|
||||
16,
|
||||
b -> onClick(),
|
||||
Text.empty()));
|
||||
pressAction,
|
||||
Text.empty());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
|
||||
if (hovered) {
|
||||
context.drawTooltip(getTextRenderer(), getTooltipText(), mouseX, mouseY);
|
||||
}
|
||||
}
|
||||
|
||||
private Text getTooltipText() {
|
||||
PlayerEntity player = MinecraftClient.getInstance().player;
|
||||
Objects.requireNonNull(player);
|
||||
String message = "Experience: ";
|
||||
|
||||
float furnaceExp = blockEntity.experience;
|
||||
if (furnaceExp <= 0) {
|
||||
message = message + "0";
|
||||
} else {
|
||||
float expTillLevel = (1.0F - player.experienceProgress) * player.getNextLevelExperience();
|
||||
if (furnaceExp <= expTillLevel) {
|
||||
int percentage = (int) (blockEntity.experience * 100 / player.getNextLevelExperience());
|
||||
message = message + "+"
|
||||
+ (percentage > 0 ? String.valueOf(percentage) : "<1")
|
||||
+ "%";
|
||||
} else {
|
||||
int levels = 0;
|
||||
furnaceExp -= expTillLevel;
|
||||
while (furnaceExp > 0) {
|
||||
furnaceExp -= PlayerUtils.getLevelExperience(player.experienceLevel);
|
||||
++levels;
|
||||
}
|
||||
message = message + "+" + levels + "L";
|
||||
}
|
||||
}
|
||||
|
||||
return Text.literal(message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue