Fixed client/server desync when applying status effects. Fixes #349

This commit is contained in:
Sollace 2024-05-16 22:21:46 +01:00
parent 59bdba6437
commit 151f3604e6
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
3 changed files with 14 additions and 4 deletions

View file

@ -19,6 +19,9 @@ public final class ClearLoveSicknessAffliction implements Affliction {
@Override
public void afflict(PlayerEntity player, ItemStack stack) {
player.heal(stack.isFood() ? stack.getItem().getFoodComponent().getHunger() : 1);
if (player.getWorld().isClient) {
return;
}
player.removeStatusEffect(StatusEffects.NAUSEA);
player.removeStatusEffect(UEffects.FOOD_POISONING);
player.removeStatusEffect(StatusEffects.WEAKNESS);

View file

@ -42,6 +42,9 @@ public record StatusEffectAffliction(StatusEffect effect, Range seconds, Range a
@Override
public void afflict(PlayerEntity player, ItemStack stack) {
if (player.getWorld().isClient) {
return;
}
if (chance > 0 && player.getWorld().random.nextInt(chance) > 0) {
return;
}

View file

@ -24,16 +24,18 @@ public class FoodPoisoningStatusEffect extends StatusEffect {
@Override
public void applyUpdateEffect(LivingEntity entity, int amplifier) {
if (entity.getWorld().isClient) {
return;
}
boolean showParticles = entity.getStatusEffect(this).shouldShowParticles();
if (!entity.hasStatusEffect(StatusEffects.NAUSEA) && entity.getRandom().nextInt(12) == 0) {
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 1, true, showParticles, false));
}
if (entity instanceof PlayerEntity) {
((PlayerEntity)entity).getHungerManager().addExhaustion(0.5F);
if (entity instanceof PlayerEntity player) {
player.getHungerManager().addExhaustion(0.5F);
}
if (EffectUtils.isPoisoned(entity) && entity.getRandom().nextInt(12) == 0 && !entity.hasStatusEffect(StatusEffects.POISON)) {
@ -63,7 +65,9 @@ public class FoodPoisoningStatusEffect extends StatusEffect {
user.getWorld().playSound(null, user.getX(), user.getY(), user.getZ(), USounds.Vanilla.ENTITY_PLAYER_BURP, SoundCategory.NEUTRAL,
1,
1 + (user.getWorld().random.nextFloat() - user.getWorld().random.nextFloat()) * 0.4f);
user.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 1, true, false, false));
if (!user.getWorld().isClient) {
user.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 1, true, false, false));
}
return TypedActionResult.fail(stack);
}
}