Skip to content

Commit

Permalink
fix level progression serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheaterpaul committed May 22, 2024
1 parent 5ec9db2 commit 392b2d5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 392b2d5

Please sign in to comment.