new: CripplingEnchantmentEffect, blindness and weakness
Some checks failed
build / build (push) Failing after 2s
Some checks failed
build / build (push) Failing after 2s
This commit is contained in:
@@ -13,11 +13,9 @@ import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
||||
|
||||
public class ModEnchantmentEffects {
|
||||
public static final RegistryKey<Enchantment> THUNDERING = of("thundering");
|
||||
public static MapCodec<LightningEnchantmentEffect> LIGHTNING_EFFECT = register("lightning_effect", LightningEnchantmentEffect.CODEC);
|
||||
public static final RegistryKey<Enchantment> WITHERING = of("withering");
|
||||
public static MapCodec<WitheringEnchantmentEffect> WITHERING_EFFECT = register("withering_effect", WitheringEnchantmentEffect.CODEC);
|
||||
public static final RegistryKey<Enchantment> POISONING = of("poisoning");
|
||||
public static MapCodec<PoisonEnchantmentEffect> POISONING_EFFECT = register("poisoning_effect", PoisonEnchantmentEffect.CODEC);
|
||||
public static final RegistryKey<Enchantment> CRIPPLING = of("crippling");
|
||||
|
||||
|
||||
private static RegistryKey<Enchantment> of(String path) {
|
||||
|
||||
@@ -88,6 +88,25 @@ public class ModEnchantmentGenerator extends FabricDynamicRegistryProvider {
|
||||
new WitheringEnchantmentEffect(EnchantmentLevelBasedValue.linear(2.0f, 1.0f)) // 2s base, +1s per level
|
||||
)
|
||||
);
|
||||
// Our new enchantment, "Crippling."
|
||||
register(entries, ModEnchantmentEffects.CRIPPLING, Enchantment.builder(
|
||||
Enchantment.definition(
|
||||
registries.getOrThrow(RegistryKeys.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
||||
10,
|
||||
3,
|
||||
Enchantment.leveledCost(1, 10),
|
||||
Enchantment.leveledCost(1, 15),
|
||||
5,
|
||||
AttributeModifierSlot.HAND
|
||||
)
|
||||
)
|
||||
.addEffect(
|
||||
EnchantmentEffectComponentTypes.POST_ATTACK,
|
||||
EnchantmentEffectTarget.ATTACKER,
|
||||
EnchantmentEffectTarget.VICTIM,
|
||||
new CripplingEnchantmentEffect(EnchantmentLevelBasedValue.linear(2.0f, 1.0f)) // 2s base, +1s per leve
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private void register(Entries entries, RegistryKey<Enchantment> key, Enchantment.Builder builder, ResourceCondition... resourceConditions) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package dev.sillyangel.more_spear_enchantments.enchantment.effect;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
||||
import net.minecraft.entity.effect.StatusEffects;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.enchantment.EnchantmentEffectContext;
|
||||
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
|
||||
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
public record CripplingEnchantmentEffect(EnchantmentLevelBasedValue duartion) implements EnchantmentEntityEffect {
|
||||
public static final MapCodec<CripplingEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||
instance.group(
|
||||
EnchantmentLevelBasedValue.CODEC.fieldOf("duration").forGetter(CripplingEnchantmentEffect::duartion)
|
||||
).apply(instance, CripplingEnchantmentEffect::new)
|
||||
);
|
||||
|
||||
@Override
|
||||
public void apply(ServerWorld world, int level, EnchantmentEffectContext context, Entity target, Vec3d pos) {
|
||||
if (target instanceof LivingEntity victim) {
|
||||
if (context.owner() != null && context.owner() instanceof PlayerEntity player) {
|
||||
int Duration = (int) (this.duartion.getValue(level) * 50); // Convert to ticks
|
||||
int slownessAmplifier = level - 1; // Level 1 = Slowness 0, Level 2 = Slowness I, Level 3 = Slowness II
|
||||
int weaknessAmplifier = level - 1; // Level 1 = Weakness 0, Level 2 = Weakness I, Level 3 = Weakness II
|
||||
victim.addStatusEffect(new StatusEffectInstance(
|
||||
StatusEffects.SLOWNESS,
|
||||
Duration,
|
||||
slownessAmplifier,
|
||||
false,
|
||||
true
|
||||
));
|
||||
victim.addStatusEffect(new StatusEffectInstance(
|
||||
StatusEffects.WEAKNESS,
|
||||
Duration,
|
||||
weaknessAmplifier,
|
||||
false,
|
||||
true
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
||||
return CODEC;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user