From 392b2d58fe56b8d6b8484c6c3dd57f0739ccce6c Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Wed, 22 May 2024 19:26:11 +0200 Subject: [PATCH] fix level progression serialization --- .../overlay/WerewolfFormDurationOverlay.java | 21 +++++++++++++------ .../player/werewolf/LevelHandler.java | 10 ++------- .../actions/BeastWerewolfFormAction.java | 2 +- .../werewolf/actions/WerewolfFormAction.java | 2 +- 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/teamlapen/werewolves/client/gui/overlay/WerewolfFormDurationOverlay.java b/src/main/java/de/teamlapen/werewolves/client/gui/overlay/WerewolfFormDurationOverlay.java index eee64976..8744f21e 100644 --- a/src/main/java/de/teamlapen/werewolves/client/gui/overlay/WerewolfFormDurationOverlay.java +++ b/src/main/java/de/teamlapen/werewolves/client/gui/overlay/WerewolfFormDurationOverlay.java @@ -20,14 +20,16 @@ public class WerewolfFormDurationOverlay implements IGuiOverlay { private final Minecraft mc = Minecraft.getInstance(); - public static final ResourceLocation ICONS = new ResourceLocation("textures/gui/icons.png"); + protected static final ResourceLocation EXPERIENCE_BAR_BACKGROUND_SPRITE = new ResourceLocation("hud/experience_bar_background"); + protected static final ResourceLocation EXPERIENCE_BAR_PROGRESS_SPRITE = new ResourceLocation("hud/experience_bar_progress"); @Override public void render(@NotNull ExtendedGui gui, @NotNull GuiGraphics graphics, float partialTicks, int width, int height) { Player player = this.mc.player; if (Helper.isWerewolf(player)) { WerewolfPlayer werewolf = WerewolfPlayer.get(player); - if (werewolf.getSpecialAttributes().transformationTime > 0) { + WerewolfFormAction lastFormAction = werewolf.getLastFormAction(); + if (werewolf.getSpecialAttributes().transformationTime > 0 && lastFormAction != null && lastFormAction.consumesWerewolfTime(werewolf)) { double perc = 1 - werewolf.getSpecialAttributes().transformationTime; float trans = FormHelper.getActiveFormAction(werewolf).map(werewolfFormAction -> werewolfFormAction.consumesWerewolfTime(werewolf)).orElse(false) ? 1f : 0.7f; renderExpBar(graphics, perc, trans); @@ -41,10 +43,17 @@ private void renderExpBar(GuiGraphics graphics, double perc, float transparency) int x = scaledWidth / 2 - 91; graphics.setColor(1f, 0.1f, 0f, transparency); + RenderSystem.disableBlend(); - int k = (int) ((1 - perc) * 183.0F); - int l = scaledHeight - 32 + 3; - graphics.blit(ICONS, x, l, 0, 64, 182, 5); - graphics.blit(ICONS, x + k, l, k, 69, 182 - k, 5); + int j = 182; + int k = (int)((1-perc) * 183.0F); + int l = scaledHeight - 32 + 3; + graphics.blitSprite(EXPERIENCE_BAR_BACKGROUND_SPRITE, x, l, j, 5); + if (k > 0) { + graphics.blitSprite(EXPERIENCE_BAR_PROGRESS_SPRITE, j, 5, k, 0, x+k, l, k, 5); + } + + RenderSystem.enableBlend(); + graphics.setColor(1.0F, 1.0F, 1.0F, 1.0F); } } diff --git a/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/LevelHandler.java b/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/LevelHandler.java index e6430669..3700967a 100644 --- a/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/LevelHandler.java +++ b/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/LevelHandler.java @@ -24,12 +24,6 @@ public float getLevelPerc() { return Mth.clamp((float) this.levelProgress / getNeededProgress(), 0, 1); } - public void loadFromNbt(@Nonnull CompoundTag compound) { - if (compound.contains("level")) { - this.levelProgress = compound.getCompound("level").getInt("progress"); - } - } - public int getLevelProgress() { return this.levelProgress; } @@ -55,8 +49,8 @@ public void reset() { @Override public void deserializeNBT(@NotNull CompoundTag compoundTag) { - if (compoundTag.contains("level")) { - this.levelProgress = compoundTag.getCompound("level").getInt("progress"); + if (compoundTag.contains("progress")) { + levelProgress = compoundTag.getInt("progress"); } } diff --git a/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/BeastWerewolfFormAction.java b/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/BeastWerewolfFormAction.java index 963274dc..0bc51f89 100644 --- a/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/BeastWerewolfFormAction.java +++ b/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/BeastWerewolfFormAction.java @@ -54,7 +54,7 @@ public int getTimeModifier(IWerewolfPlayer werewolf) { } @Override - protected boolean usesTransformationTime(IWerewolfPlayer werewolf) { + public boolean usesTransformationTime(IWerewolfPlayer werewolf) { return super.usesTransformationTime(werewolf) && !(werewolf.getSkillHandler().isSkillEnabled(ModSkills.BEAST_RAGE.get()) && werewolf.getActionHandler().isActionActive(ModActions.RAGE.get())); } diff --git a/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/WerewolfFormAction.java b/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/WerewolfFormAction.java index 9bf9616d..c5b8d37c 100644 --- a/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/WerewolfFormAction.java +++ b/src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/WerewolfFormAction.java @@ -137,7 +137,7 @@ public boolean onUpdate(IWerewolfPlayer werewolfPlayer) { return increaseWerewolfTime(werewolfPlayer) || (werewolfPlayer.asEntity() instanceof ServerPlayer && !PermissionAPI.getPermission((ServerPlayer) werewolfPlayer.asEntity(), Permissions.FORM)); } - protected boolean usesTransformationTime(IWerewolfPlayer werewolf) { + public boolean usesTransformationTime(IWerewolfPlayer werewolf) { Player player = werewolf.asEntity(); return !Helper.isNight(player.level()) && !FormHelper.isInWerewolfBiome(player.level(), player.blockPosition()); }