Compare commits

..

2 commits

View file

@ -6,14 +6,14 @@ import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.effect.MobEffectInstance; import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects; import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity; 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.EnchantedItemInUse;
import net.minecraft.world.item.enchantment.LevelBasedValue; import net.minecraft.world.item.enchantment.LevelBasedValue;
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect; import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import xyz.nearmisses.patience.mc_rebalance.MCRebalance;
import java.util.Objects;
public record CrumbleEffect(LevelBasedValue amount) implements EnchantmentEntityEffect { public record CrumbleEffect(LevelBasedValue amount) implements EnchantmentEntityEffect {
public static final MapCodec<CrumbleEffect> CODEC = RecordCodecBuilder.mapCodec(instance -> public static final MapCodec<CrumbleEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
@ -22,15 +22,19 @@ public record CrumbleEffect(LevelBasedValue amount) implements EnchantmentEntity
).apply(instance, CrumbleEffect::new) ).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 @Override
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) { 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(); MobEffectInstance effect = player.getActiveEffects().iterator().next();
player.getActiveEffects().remove(effect); if(effect.is(MobEffects.WITHER)){return;}
player.getActiveEffects().add(new MobEffectInstance(MobEffects.WITHER, player.removeEffect(effect.getEffect());
(int)(effect.getDuration() * this.amount.calculate(level)), MCRebalance.LOGGER.info(String.valueOf(effect));
(effect.getAmplifier() > 0 ? effect.getAmplifier() - 1 : 0) + (player.hasEffect(MobEffects.WITHER) ? Objects.requireNonNull(player.getEffect(MobEffects.WITHER)).getAmplifier() : 0) player.addEffect(new MobEffectInstance(MobEffects.WITHER,
)); // That last line is a mess, but far less so than my initial attempt. Reduced RNG pending. //(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());
} }
} }