Skip to content

Commit 392b2d5

Browse files
committed
fix level progression serialization
1 parent 5ec9db2 commit 392b2d5

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

src/main/java/de/teamlapen/werewolves/client/gui/overlay/WerewolfFormDurationOverlay.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020
public class WerewolfFormDurationOverlay implements IGuiOverlay {
2121

2222
private final Minecraft mc = Minecraft.getInstance();
23-
public static final ResourceLocation ICONS = new ResourceLocation("textures/gui/icons.png");
23+
protected static final ResourceLocation EXPERIENCE_BAR_BACKGROUND_SPRITE = new ResourceLocation("hud/experience_bar_background");
24+
protected static final ResourceLocation EXPERIENCE_BAR_PROGRESS_SPRITE = new ResourceLocation("hud/experience_bar_progress");
2425

2526
@Override
2627
public void render(@NotNull ExtendedGui gui, @NotNull GuiGraphics graphics, float partialTicks, int width, int height) {
2728
Player player = this.mc.player;
2829
if (Helper.isWerewolf(player)) {
2930
WerewolfPlayer werewolf = WerewolfPlayer.get(player);
30-
if (werewolf.getSpecialAttributes().transformationTime > 0) {
31+
WerewolfFormAction lastFormAction = werewolf.getLastFormAction();
32+
if (werewolf.getSpecialAttributes().transformationTime > 0 && lastFormAction != null && lastFormAction.consumesWerewolfTime(werewolf)) {
3133
double perc = 1 - werewolf.getSpecialAttributes().transformationTime;
3234
float trans = FormHelper.getActiveFormAction(werewolf).map(werewolfFormAction -> werewolfFormAction.consumesWerewolfTime(werewolf)).orElse(false) ? 1f : 0.7f;
3335
renderExpBar(graphics, perc, trans);
@@ -41,10 +43,17 @@ private void renderExpBar(GuiGraphics graphics, double perc, float transparency)
4143
int x = scaledWidth / 2 - 91;
4244

4345
graphics.setColor(1f, 0.1f, 0f, transparency);
46+
RenderSystem.disableBlend();
4447

45-
int k = (int) ((1 - perc) * 183.0F);
46-
int l = scaledHeight - 32 + 3;
47-
graphics.blit(ICONS, x, l, 0, 64, 182, 5);
48-
graphics.blit(ICONS, x + k, l, k, 69, 182 - k, 5);
48+
int j = 182;
49+
int k = (int)((1-perc) * 183.0F);
50+
int l = scaledHeight - 32 + 3;
51+
graphics.blitSprite(EXPERIENCE_BAR_BACKGROUND_SPRITE, x, l, j, 5);
52+
if (k > 0) {
53+
graphics.blitSprite(EXPERIENCE_BAR_PROGRESS_SPRITE, j, 5, k, 0, x+k, l, k, 5);
54+
}
55+
56+
RenderSystem.enableBlend();
57+
graphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);
4958
}
5059
}

src/main/java/de/teamlapen/werewolves/entities/player/werewolf/LevelHandler.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ public float getLevelPerc() {
2424
return Mth.clamp((float) this.levelProgress / getNeededProgress(), 0, 1);
2525
}
2626

27-
public void loadFromNbt(@Nonnull CompoundTag compound) {
28-
if (compound.contains("level")) {
29-
this.levelProgress = compound.getCompound("level").getInt("progress");
30-
}
31-
}
32-
3327
public int getLevelProgress() {
3428
return this.levelProgress;
3529
}
@@ -55,8 +49,8 @@ public void reset() {
5549

5650
@Override
5751
public void deserializeNBT(@NotNull CompoundTag compoundTag) {
58-
if (compoundTag.contains("level")) {
59-
this.levelProgress = compoundTag.getCompound("level").getInt("progress");
52+
if (compoundTag.contains("progress")) {
53+
levelProgress = compoundTag.getInt("progress");
6054
}
6155
}
6256

src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/BeastWerewolfFormAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public int getTimeModifier(IWerewolfPlayer werewolf) {
5454
}
5555

5656
@Override
57-
protected boolean usesTransformationTime(IWerewolfPlayer werewolf) {
57+
public boolean usesTransformationTime(IWerewolfPlayer werewolf) {
5858
return super.usesTransformationTime(werewolf) && !(werewolf.getSkillHandler().isSkillEnabled(ModSkills.BEAST_RAGE.get()) && werewolf.getActionHandler().isActionActive(ModActions.RAGE.get()));
5959
}
6060

src/main/java/de/teamlapen/werewolves/entities/player/werewolf/actions/WerewolfFormAction.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public boolean onUpdate(IWerewolfPlayer werewolfPlayer) {
137137
return increaseWerewolfTime(werewolfPlayer) || (werewolfPlayer.asEntity() instanceof ServerPlayer && !PermissionAPI.getPermission((ServerPlayer) werewolfPlayer.asEntity(), Permissions.FORM));
138138
}
139139

140-
protected boolean usesTransformationTime(IWerewolfPlayer werewolf) {
140+
public boolean usesTransformationTime(IWerewolfPlayer werewolf) {
141141
Player player = werewolf.asEntity();
142142
return !Helper.isNight(player.level()) && !FormHelper.isInWerewolfBiome(player.level(), player.blockPosition());
143143
}

0 commit comments

Comments
 (0)