Made Crumble not crash to desktop
This commit is contained in:
parent
d2f588d962
commit
2b690e4f94
|
|
@ -6,14 +6,14 @@ import net.minecraft.server.level.ServerLevel;
|
|||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
|
||||
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import xyz.nearmisses.patience.mc_rebalance.MCRebalance;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public record CrumbleEffect(LevelBasedValue amount) implements EnchantmentEntityEffect {
|
||||
public static final MapCodec<CrumbleEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
|
|
@ -22,15 +22,19 @@ public record CrumbleEffect(LevelBasedValue amount) implements EnchantmentEntity
|
|||
).apply(instance, CrumbleEffect::new)
|
||||
);
|
||||
|
||||
// This method has certain flaws (if wither's the first on the list, this enchantment doesn't work), but I'm actually fine with that currently (deters players from trying to half-and-half their effect application).
|
||||
@Override
|
||||
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
||||
if (target instanceof Player player && player.getActiveEffects().iterator().hasNext()) {
|
||||
if (target instanceof LivingEntity player && player.getActiveEffects().iterator().hasNext()) {
|
||||
MobEffectInstance effect = player.getActiveEffects().iterator().next();
|
||||
player.getActiveEffects().remove(effect);
|
||||
player.getActiveEffects().add(new MobEffectInstance(MobEffects.WITHER,
|
||||
(int)(effect.getDuration() * this.amount.calculate(level)),
|
||||
(effect.getAmplifier() > 0 ? effect.getAmplifier() - 1 : 0) + (player.hasEffect(MobEffects.WITHER) ? Objects.requireNonNull(player.getEffect(MobEffects.WITHER)).getAmplifier() : 0)
|
||||
)); // That last line is a mess, but far less so than my initial attempt. Reduced RNG pending.
|
||||
if(effect.is(MobEffects.WITHER)){return;}
|
||||
player.removeEffect(effect.getEffect());
|
||||
MCRebalance.LOGGER.info(String.valueOf(effect));
|
||||
player.addEffect(new MobEffectInstance(MobEffects.WITHER,
|
||||
//(int)(effect.getDuration() * this.amount.calculate(level)),
|
||||
(int)(200*this.amount.calculate(level)), // Consider which of these would be better
|
||||
(effect.getAmplifier() > 0 ? effect.getAmplifier() - 1 : 0) + (player.hasEffect(MobEffects.WITHER) ? player.getEffect(MobEffects.WITHER).getAmplifier() : 0)
|
||||
), context.owner());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue