Skip to content

Commit

Permalink
Fixed incorrect display of energy capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
khaskelbergTAU committed Apr 26, 2024
1 parent 6538a1a commit 8996062
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ protected void renderBg(@NotNull PoseStack matrixStack, float f, int i, int j) {
RenderSystem.setShaderTexture(0, TEXTURE);
RenderSystem.setShaderColor(1, 1, 1, 1f);
blit(matrixStack, leftPos, topPos, 0, 0, imageWidth, imageHeight);
int energyBarHeight = Mth.clamp((int) (66F * (getEnergyLevel().get() / (float) 1000000)), 0, 66);
int energyBarHeight = Mth.clamp((int) (66F * (getEnergyLevel().get() / (float) getEnergyCapacity().get())), 0,
66);
blit(matrixStack, leftPos + 133, topPos + 19 + (66 - energyBarHeight), 176, 66 - energyBarHeight, 12, energyBarHeight);
int tickBarHeight = Mth.clamp((int) (66F * (getTicks().get() / (getMaxTicks().get() + 0.001f))), 0, 66);
blit(matrixStack, leftPos + 119, topPos + 19 + (66 - tickBarHeight), 188, 66 - tickBarHeight, 6, tickBarHeight);
Expand All @@ -57,6 +58,10 @@ public Supplier<Integer> getEnergyLevel() {
return () -> menu.getContainerData().get(ReaperGeneratorData.ENERGY);
}

public Supplier<Integer> getEnergyCapacity() {
return () -> menu.getContainerData().get(ReaperGeneratorData.CAPACITY);
}

public Supplier<Integer> getTicks() {
return () -> menu.getContainerData().get(ReaperGeneratorData.COOLDOWN);
}
Expand All @@ -78,7 +83,12 @@ public void render(@NotNull PoseStack poseStack, int mouseX, int mouseY, float f
super.render(poseStack, mouseX, mouseY, f);
this.renderTooltip(poseStack, mouseX, mouseY);
if(mouseX > leftPos + 130 && mouseX < 147 + leftPos && mouseY > 16 + topPos && mouseY < 87 + topPos) {
this.renderTooltip(poseStack, Component.translatable("gui." + Reaper.MODID + ".energy_tooltip", Component.literal(String.valueOf(getEnergyLevel().get())).withStyle(ChatFormatting.GOLD), Component.literal("1000000").withStyle(ChatFormatting.GOLD)).withStyle(ChatFormatting.AQUA), mouseX, mouseY);
this.renderTooltip(poseStack,
Component.translatable("gui." + Reaper.MODID + ".energy_tooltip",
Component.literal(String.valueOf(getEnergyLevel().get())).withStyle(ChatFormatting.GOLD),
Component.literal(String.valueOf(getEnergyCapacity().get())).withStyle(ChatFormatting.GOLD))
.withStyle(ChatFormatting.AQUA),
mouseX, mouseY);
} else if(mouseX > leftPos + 116 && mouseX < 127 + leftPos && mouseY > 16 + topPos && mouseY < 87 + topPos) {
this.renderTooltip(poseStack, Component.translatable("gui." + Reaper.MODID + ".work_tooltip", Component.literal(String.valueOf(getTicks().get())).withStyle(ChatFormatting.GOLD), Component.literal(String.valueOf(getMaxTicks().get())).withStyle(ChatFormatting.GOLD)).withStyle(ChatFormatting.AQUA), mouseX, mouseY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ReaperGeneratorData implements ContainerData {
public static final int PRODUCTION = 3;
public static final int MAX_COOLDOWN = 4;
public static final int RANGE = 5;
public static final int CAPACITY = 6;
public static final int COUNT = 7;

public ReaperGeneratorData(ReaperGeneratorBlockEntity reaperGeneratorBlockEntity) {
this.gen = reaperGeneratorBlockEntity;
Expand All @@ -25,6 +27,7 @@ public int get(int i) {
case PRODUCTION -> gen.getEnergyGeneration();
case MAX_COOLDOWN -> gen.getMaxCooldown();
case RANGE -> gen.getMaxRange();
case CAPACITY -> (int) gen.getEnergyStorage().getMaxCapacity();
default -> 0;
};
}
Expand All @@ -35,6 +38,6 @@ public void set(int i, int j) {

@Override
public int getCount() {
return 6;
return COUNT;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package earth.terrarium.reaper.common.block;

import earth.terrarium.reaper.Reaper;
import earth.terrarium.reaper.common.blockentity.ReaperGeneratorBlockEntity;
import earth.terrarium.reaper.common.registry.ReaperRegistry;
import net.minecraft.network.FriendlyByteBuf;
Expand Down Expand Up @@ -38,7 +39,8 @@ public ReaperGeneratorMenu(Container container, ContainerData data, int i, Inven
}

public ReaperGeneratorMenu(int syncId, Inventory inventory, FriendlyByteBuf buf) {
this(new SimpleContainer(8), new SimpleContainerData(6), syncId, inventory, (ReaperGeneratorBlockEntity) inventory.player.level.getBlockEntity(buf.readBlockPos()));
this(new SimpleContainer(8), new SimpleContainerData(ReaperGeneratorData.COUNT), syncId, inventory,
(ReaperGeneratorBlockEntity) inventory.player.level.getBlockEntity(buf.readBlockPos()));
}

@Override
Expand Down

0 comments on commit 8996062

Please sign in to comment.