mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Fixed client/server desync when applying status effects. Fixes #349
This commit is contained in:
parent
59bdba6437
commit
151f3604e6
3 changed files with 14 additions and 4 deletions
|
@ -19,6 +19,9 @@ public final class ClearLoveSicknessAffliction implements Affliction {
|
||||||
@Override
|
@Override
|
||||||
public void afflict(PlayerEntity player, ItemStack stack) {
|
public void afflict(PlayerEntity player, ItemStack stack) {
|
||||||
player.heal(stack.isFood() ? stack.getItem().getFoodComponent().getHunger() : 1);
|
player.heal(stack.isFood() ? stack.getItem().getFoodComponent().getHunger() : 1);
|
||||||
|
if (player.getWorld().isClient) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
player.removeStatusEffect(StatusEffects.NAUSEA);
|
player.removeStatusEffect(StatusEffects.NAUSEA);
|
||||||
player.removeStatusEffect(UEffects.FOOD_POISONING);
|
player.removeStatusEffect(UEffects.FOOD_POISONING);
|
||||||
player.removeStatusEffect(StatusEffects.WEAKNESS);
|
player.removeStatusEffect(StatusEffects.WEAKNESS);
|
||||||
|
|
|
@ -42,6 +42,9 @@ public record StatusEffectAffliction(StatusEffect effect, Range seconds, Range a
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void afflict(PlayerEntity player, ItemStack stack) {
|
public void afflict(PlayerEntity player, ItemStack stack) {
|
||||||
|
if (player.getWorld().isClient) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (chance > 0 && player.getWorld().random.nextInt(chance) > 0) {
|
if (chance > 0 && player.getWorld().random.nextInt(chance) > 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,16 +24,18 @@ public class FoodPoisoningStatusEffect extends StatusEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void applyUpdateEffect(LivingEntity entity, int amplifier) {
|
public void applyUpdateEffect(LivingEntity entity, int amplifier) {
|
||||||
|
if (entity.getWorld().isClient) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
boolean showParticles = entity.getStatusEffect(this).shouldShowParticles();
|
boolean showParticles = entity.getStatusEffect(this).shouldShowParticles();
|
||||||
|
|
||||||
if (!entity.hasStatusEffect(StatusEffects.NAUSEA) && entity.getRandom().nextInt(12) == 0) {
|
if (!entity.hasStatusEffect(StatusEffects.NAUSEA) && entity.getRandom().nextInt(12) == 0) {
|
||||||
|
|
||||||
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 1, true, showParticles, false));
|
entity.addStatusEffect(new StatusEffectInstance(StatusEffects.NAUSEA, 100, 1, true, showParticles, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (entity instanceof PlayerEntity) {
|
if (entity instanceof PlayerEntity player) {
|
||||||
((PlayerEntity)entity).getHungerManager().addExhaustion(0.5F);
|
player.getHungerManager().addExhaustion(0.5F);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EffectUtils.isPoisoned(entity) && entity.getRandom().nextInt(12) == 0 && !entity.hasStatusEffect(StatusEffects.POISON)) {
|
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,
|
user.getWorld().playSound(null, user.getX(), user.getY(), user.getZ(), USounds.Vanilla.ENTITY_PLAYER_BURP, SoundCategory.NEUTRAL,
|
||||||
1,
|
1,
|
||||||
1 + (user.getWorld().random.nextFloat() - user.getWorld().random.nextFloat()) * 0.4f);
|
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);
|
return TypedActionResult.fail(stack);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue