Skip to content

Commit

Permalink
Food fix and some PlayerData changes (#3996)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHell228 authored Apr 28, 2024
1 parent b9e3cab commit d31a2f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
@Mixin(FoodData.class)
public interface FoodDataAccessor {

@Accessor("saturationLevel") void accessor$saturationLevel(final float saturationLevel);
@Accessor("foodLevel") void accessor$foodLevel(final int foodLevel);

@Accessor("exhaustionLevel") float accessor$exhaustionLevel();
@Accessor("saturationLevel") void accessor$saturationLevel(final float saturationLevel);

@Accessor("exhaustionLevel") void accessor$exhaustionLevel(final float exhaustionLevel);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,8 @@ public static void register(final DataProviderRegistrator registrator) {
.get(h -> (HandPreference) (Object) h.getMainArm())
.set((h, v) -> h.setMainArm((HumanoidArm) (Object) v))
.create(Keys.EXHAUSTION)
.get(h -> (double) ((FoodDataAccessor) h.getFoodData()).accessor$exhaustionLevel())
.setAnd((h, v) -> {
if (v < 0 || v > PlayerData.EXHAUSTION_MAX) {
return false;
}
((FoodDataAccessor) h.getFoodData()).accessor$exhaustionLevel(v.floatValue());
return true;
})
.get(h -> (double) h.getFoodData().getExhaustionLevel())
.set((h, v) -> ((FoodDataAccessor) h.getFoodData()).accessor$exhaustionLevel(v.floatValue()))
.create(Keys.EXPERIENCE)
.get(h -> h.totalExperience)
.set(ExperienceHolderUtil::setExperience)
Expand Down Expand Up @@ -98,23 +92,13 @@ public static void register(final DataProviderRegistrator registrator) {
.delete(h -> ExperienceHolderUtil.setExperience(h, 0))
.create(Keys.FLYING_SPEED)
.get(h -> (double) h.getAbilities().getFlyingSpeed())
.setAnd((h, v) -> {
if (v < 0) {
return false;
}
.set((h, v) -> {
((AbilitiesAccessor) h.getAbilities()).accessor$flyingSpeed(v.floatValue());
h.onUpdateAbilities();
return true;
})
.create(Keys.FOOD_LEVEL)
.get(h -> h.getFoodData().getFoodLevel())
.setAnd((h, v) -> {
if (v < 0 || v > PlayerData.FOOD_LEVEL_MAX) {
return false;
}
h.getFoodData().setFoodLevel(v);
return true;
})
.set((h, v) -> ((FoodDataAccessor) h.getFoodData()).accessor$foodLevel(v))
.create(Keys.IS_FLYING)
.get(h -> h.getAbilities().flying)
.set((h, v) -> {
Expand All @@ -131,13 +115,7 @@ public static void register(final DataProviderRegistrator registrator) {
.get(h -> PlayerData.SATURATION_MAX)
.create(Keys.SATURATION)
.get(h -> (double) h.getFoodData().getSaturationLevel())
.setAnd((h, v) -> {
if (v < 0 || v > PlayerData.SATURATION_MAX) {
return false;
}
((FoodDataAccessor) h.getFoodData()).accessor$saturationLevel(v.floatValue());
return true;
})
.set((h, v) -> ((FoodDataAccessor) h.getFoodData()).accessor$saturationLevel(v.floatValue()))
.create(Keys.SLEEP_TIMER)
.get(Player::getSleepTimer)
.set((p, i) -> ((PlayerAccessor) p).accessor$sleepCounter(i))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public abstract class FoodDataMixin implements FoodDataBridge {
this.foodLevel = this.impl$fireEventAndGetValue(Keys.FOOD_LEVEL, this.foodLevel, value);
}

@Redirect(method = "setSaturation", at = @At(value = "FIELD", target = "Lnet/minecraft/world/food/FoodData;saturationLevel:F", opcode = Opcodes.PUTFIELD))
private void impl$setSaturationLevel(final FoodData self, final float value) {
this.saturationLevel = this.impl$fireEventAndGetValue(Keys.SATURATION, (double) this.saturationLevel, (double) value).floatValue();
}

@Redirect(method = "eat(IF)V", at = @At(value = "FIELD", target = "Lnet/minecraft/world/food/FoodData;saturationLevel:F", opcode = Opcodes.PUTFIELD))
private void impl$eatSetSaturationLevel(final FoodData self, final float value) {
this.saturationLevel = this.impl$fireEventAndGetValue(Keys.SATURATION, (double) this.saturationLevel, (double) value).floatValue();
Expand All @@ -86,6 +91,11 @@ public abstract class FoodDataMixin implements FoodDataBridge {
this.saturationLevel = this.impl$fireEventAndGetValue(Keys.SATURATION, (double) this.saturationLevel, (double) value).floatValue();
}

@Redirect(method = "setExhaustion", at = @At(value = "FIELD", target = "Lnet/minecraft/world/food/FoodData;exhaustionLevel:F", opcode = Opcodes.PUTFIELD))
private void impl$setExhaustion(final FoodData self, final float value) {
this.exhaustionLevel = this.impl$fireEventAndGetValue(Keys.EXHAUSTION, (double) this.exhaustionLevel, (double) value).floatValue();
}

@Redirect(method = "addExhaustion", at = @At(value = "FIELD", target = "Lnet/minecraft/world/food/FoodData;exhaustionLevel:F", opcode = Opcodes.PUTFIELD))
private void impl$addExhaustion(final FoodData self, final float value) {
this.exhaustionLevel = this.impl$fireEventAndGetValue(Keys.EXHAUSTION, (double) this.exhaustionLevel, (double) value).floatValue();
Expand Down

0 comments on commit d31a2f7

Please sign in to comment.