switch from yarn to minecraft mapping due to 26.1
This commit is contained in:
@@ -31,12 +31,13 @@ subprojects {
|
|||||||
// for more information about repositories.
|
// for more information about repositories.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loom {
|
||||||
|
silentMojangMappingsLicense()
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
|
minecraft "net.minecraft:minecraft:$rootProject.minecraft_version"
|
||||||
mappings loom.layered {
|
mappings loom.officialMojangMappings()
|
||||||
it.mappings("net.fabricmc:yarn:$rootProject.yarn_mappings:v2")
|
|
||||||
it.mappings("dev.architectury:yarn-mappings-patch-neoforge:$rootProject.yarn_mappings_patch_neoforge_version")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -5,22 +5,22 @@ import dev.architectury.registry.registries.DeferredRegister;
|
|||||||
import dev.architectury.registry.registries.RegistrySupplier;
|
import dev.architectury.registry.registries.RegistrySupplier;
|
||||||
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
|
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
|
||||||
import dev.sillyangel.more_spear_enchantments.enchantment.effect.*;
|
import dev.sillyangel.more_spear_enchantments.enchantment.effect.*;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.world.item.enchantment.Enchantment;
|
||||||
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
public class ModEnchantmentEffects {
|
public class ModEnchantmentEffects {
|
||||||
// Deferred register for enchantment effect types
|
// Deferred register for enchantment effect types
|
||||||
public static final DeferredRegister<MapCodec<? extends EnchantmentEntityEffect>> ENCHANTMENT_ENTITY_EFFECTS =
|
public static final DeferredRegister<MapCodec<? extends EnchantmentEntityEffect>> ENCHANTMENT_ENTITY_EFFECTS =
|
||||||
DeferredRegister.create(MoreSpearEnchantments.MOD_ID, RegistryKeys.ENCHANTMENT_ENTITY_EFFECT_TYPE);
|
DeferredRegister.create(MoreSpearEnchantments.MOD_ID, Registries.ENCHANTMENT_ENTITY_EFFECT_TYPE);
|
||||||
|
|
||||||
// Enchantment registry keys
|
// Enchantment registry keys
|
||||||
public static final RegistryKey<Enchantment> THUNDERING = of("thundering");
|
public static final ResourceKey<Enchantment> THUNDERING = of("thundering");
|
||||||
public static final RegistryKey<Enchantment> WITHERING = of("withering");
|
public static final ResourceKey<Enchantment> WITHERING = of("withering");
|
||||||
public static final RegistryKey<Enchantment> POISONING = of("poisoning");
|
public static final ResourceKey<Enchantment> POISONING = of("poisoning");
|
||||||
public static final RegistryKey<Enchantment> CRIPPLING = of("crippling");
|
public static final ResourceKey<Enchantment> CRIPPLING = of("crippling");
|
||||||
|
|
||||||
// Register enchantment effect types
|
// Register enchantment effect types
|
||||||
public static final RegistrySupplier<MapCodec<LightningEnchantmentEffect>> LIGHTNING_EFFECT =
|
public static final RegistrySupplier<MapCodec<LightningEnchantmentEffect>> LIGHTNING_EFFECT =
|
||||||
@@ -32,9 +32,9 @@ public class ModEnchantmentEffects {
|
|||||||
public static final RegistrySupplier<MapCodec<CripplingEnchantmentEffect>> CRIPPLING_EFFECT =
|
public static final RegistrySupplier<MapCodec<CripplingEnchantmentEffect>> CRIPPLING_EFFECT =
|
||||||
ENCHANTMENT_ENTITY_EFFECTS.register("crippling", () -> CripplingEnchantmentEffect.CODEC);
|
ENCHANTMENT_ENTITY_EFFECTS.register("crippling", () -> CripplingEnchantmentEffect.CODEC);
|
||||||
|
|
||||||
private static RegistryKey<Enchantment> of(String path) {
|
private static ResourceKey<Enchantment> of(String path) {
|
||||||
Identifier id = Identifier.of(MoreSpearEnchantments.MOD_ID, path);
|
Identifier id = Identifier.fromNamespaceAndPath(MoreSpearEnchantments.MOD_ID, path);
|
||||||
return RegistryKey.of(RegistryKeys.ENCHANTMENT, id);
|
return ResourceKey.create(Registries.ENCHANTMENT, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerModEnchantmentEffects() {
|
public static void registerModEnchantmentEffects() {
|
||||||
|
|||||||
@@ -2,40 +2,41 @@ package dev.sillyangel.more_spear_enchantments.enchantment.effect;
|
|||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.world.entity.Mob;
|
||||||
import net.minecraft.enchantment.EnchantmentEffectContext;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
|
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||||
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
|
||||||
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
public record CripplingEnchantmentEffect(EnchantmentLevelBasedValue duration) implements EnchantmentEntityEffect {
|
public record CripplingEnchantmentEffect(LevelBasedValue duration) implements EnchantmentEntityEffect {
|
||||||
public static final MapCodec<CripplingEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
public static final MapCodec<CripplingEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||||
instance.group(
|
instance.group(
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("duration").forGetter(CripplingEnchantmentEffect::duration)
|
LevelBasedValue.CODEC.fieldOf("duration").forGetter(CripplingEnchantmentEffect::duration)
|
||||||
).apply(instance, CripplingEnchantmentEffect::new)
|
).apply(instance, CripplingEnchantmentEffect::new)
|
||||||
);
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(ServerWorld world, int level, EnchantmentEffectContext context, Entity target, Vec3d pos) {
|
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
||||||
if (target instanceof LivingEntity victim) {
|
if (target instanceof LivingEntity victim) {
|
||||||
if (context.owner() != null && context.owner() instanceof PlayerEntity player) {
|
if (context.owner() != null && context.owner() instanceof Player player) {
|
||||||
int Duration = (int) (this.duration.getValue(level) * 50); // Convert to ticks
|
int Duration = (int) (this.duration.calculate(level) * 50); // Convert to ticks
|
||||||
int slownessAmplifier = level - 1; // Level 1 = Slowness 0, Level 2 = Slowness I, Level 3 = Slowness II
|
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
|
int weaknessAmplifier = level - 1; // Level 1 = Weakness 0, Level 2 = Weakness I, Level 3 = Weakness II
|
||||||
victim.addStatusEffect(new StatusEffectInstance(
|
victim.addEffect(new MobEffectInstance(
|
||||||
StatusEffects.SLOWNESS,
|
MobEffects.SLOWNESS,
|
||||||
Duration,
|
Duration,
|
||||||
slownessAmplifier,
|
slownessAmplifier,
|
||||||
false,
|
false,
|
||||||
true
|
true
|
||||||
));
|
));
|
||||||
victim.addStatusEffect(new StatusEffectInstance(
|
victim.addEffect(new MobEffectInstance(
|
||||||
StatusEffects.WEAKNESS,
|
MobEffects.WEAKNESS,
|
||||||
Duration,
|
Duration,
|
||||||
weaknessAmplifier,
|
weaknessAmplifier,
|
||||||
false,
|
false,
|
||||||
@@ -46,7 +47,7 @@ public record CripplingEnchantmentEffect(EnchantmentLevelBasedValue duration) im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
public MapCodec<? extends EnchantmentEntityEffect> codec() {
|
||||||
return CODEC;
|
return CODEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,41 +2,41 @@ package dev.sillyangel.more_spear_enchantments.enchantment.effect;
|
|||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.world.entity.EntityType;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.world.entity.EntitySpawnReason;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.entity.SpawnReason;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.enchantment.EnchantmentEffectContext;
|
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||||
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
|
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||||
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
public record LightningEnchantmentEffect(EnchantmentLevelBasedValue amount) implements EnchantmentEntityEffect {
|
public record LightningEnchantmentEffect(LevelBasedValue amount) implements EnchantmentEntityEffect {
|
||||||
public static final MapCodec<LightningEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
public static final MapCodec<LightningEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||||
instance.group(
|
instance.group(
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("amount").forGetter(LightningEnchantmentEffect::amount)
|
LevelBasedValue.CODEC.fieldOf("amount").forGetter(LightningEnchantmentEffect::amount)
|
||||||
).apply(instance, LightningEnchantmentEffect::new)
|
).apply(instance, LightningEnchantmentEffect::new)
|
||||||
);
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(ServerWorld world, int level, EnchantmentEffectContext context, Entity target, Vec3d pos) {
|
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
||||||
if (target instanceof LivingEntity victim) {
|
if (target instanceof LivingEntity victim) {
|
||||||
if (context.owner() != null && context.owner() instanceof PlayerEntity player) {
|
if (context.owner() != null && context.owner() instanceof Player player) {
|
||||||
float numStrikes = this.amount.getValue(level);
|
float numStrikes = this.amount.calculate(level);
|
||||||
|
|
||||||
for (float i = 0; i < numStrikes; i++) {
|
for (float i = 0; i < numStrikes; i++) {
|
||||||
BlockPos position = victim.getBlockPos();
|
BlockPos position = victim.blockPosition();
|
||||||
EntityType.LIGHTNING_BOLT.spawn(world, position, SpawnReason.TRIGGERED);
|
EntityType.LIGHTNING_BOLT.spawn(world, position, EntitySpawnReason.TRIGGERED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
public MapCodec<? extends EnchantmentEntityEffect> codec() {
|
||||||
return CODEC;
|
return CODEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,33 +2,33 @@ package dev.sillyangel.more_spear_enchantments.enchantment.effect;
|
|||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.enchantment.EnchantmentEffectContext;
|
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||||
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
|
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||||
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
public record PoisonEnchantmentEffect(EnchantmentLevelBasedValue duration) implements EnchantmentEntityEffect {
|
public record PoisonEnchantmentEffect(LevelBasedValue duration) implements EnchantmentEntityEffect {
|
||||||
public static final MapCodec<PoisonEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
public static final MapCodec<PoisonEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||||
instance.group(
|
instance.group(
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("duration").forGetter(PoisonEnchantmentEffect::duration)
|
LevelBasedValue.CODEC.fieldOf("duration").forGetter(PoisonEnchantmentEffect::duration)
|
||||||
).apply(instance, PoisonEnchantmentEffect::new)
|
).apply(instance, PoisonEnchantmentEffect::new)
|
||||||
);
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(ServerWorld world, int level, EnchantmentEffectContext context, Entity target, Vec3d pos) {
|
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
||||||
if (target instanceof LivingEntity victim) {
|
if (target instanceof LivingEntity victim) {
|
||||||
if (context.owner() != null && context.owner() instanceof PlayerEntity player) {
|
if (context.owner() != null && context.owner() instanceof Player player) {
|
||||||
int poisonDuration = (int) (this.duration.getValue(level) * 40); // Convert to ticks
|
int poisonDuration = (int) (this.duration.calculate(level) * 40); // Convert to ticks
|
||||||
int poisonAmplifier = level - 2; // Level 1 = Poison 0, Level 2 = Poison I, Level 3 = Poison II
|
int poisonAmplifier = level - 2; // Level 1 = Poison 0, Level 2 = Poison I, Level 3 = Poison II
|
||||||
|
|
||||||
victim.addStatusEffect(new StatusEffectInstance(
|
victim.addEffect(new MobEffectInstance(
|
||||||
StatusEffects.POISON,
|
MobEffects.POISON,
|
||||||
poisonDuration,
|
poisonDuration,
|
||||||
poisonAmplifier,
|
poisonAmplifier,
|
||||||
false,
|
false,
|
||||||
@@ -39,7 +39,7 @@ public record PoisonEnchantmentEffect(EnchantmentLevelBasedValue duration) imple
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
public MapCodec<? extends EnchantmentEntityEffect> codec() {
|
||||||
return CODEC;
|
return CODEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,33 +2,33 @@ package dev.sillyangel.more_spear_enchantments.enchantment.effect;
|
|||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.server.world.ServerWorld;
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.entity.LivingEntity;
|
import net.minecraft.world.entity.LivingEntity;
|
||||||
import net.minecraft.entity.effect.StatusEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.entity.effect.StatusEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.enchantment.EnchantmentEffectContext;
|
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||||
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
|
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||||
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
import net.minecraft.world.item.enchantment.EnchantedItemInUse;
|
||||||
import net.minecraft.util.math.Vec3d;
|
import net.minecraft.world.phys.Vec3;
|
||||||
|
|
||||||
public record WitheringEnchantmentEffect(EnchantmentLevelBasedValue duration) implements EnchantmentEntityEffect {
|
public record WitheringEnchantmentEffect(LevelBasedValue duration) implements EnchantmentEntityEffect {
|
||||||
public static final MapCodec<WitheringEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
public static final MapCodec<WitheringEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
||||||
instance.group(
|
instance.group(
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("duration").forGetter(WitheringEnchantmentEffect::duration)
|
LevelBasedValue.CODEC.fieldOf("duration").forGetter(WitheringEnchantmentEffect::duration)
|
||||||
).apply(instance, WitheringEnchantmentEffect::new)
|
).apply(instance, WitheringEnchantmentEffect::new)
|
||||||
);
|
);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(ServerWorld world, int level, EnchantmentEffectContext context, Entity target, Vec3d pos) {
|
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
||||||
if (target instanceof LivingEntity victim) {
|
if (target instanceof LivingEntity victim) {
|
||||||
if (context.owner() != null && context.owner() instanceof PlayerEntity player) {
|
if (context.owner() != null && context.owner() instanceof Player player) {
|
||||||
int witherDuration = (int) (this.duration.getValue(level) * 40); // Convert to ticks
|
int witherDuration = (int) (this.duration.calculate(level) * 40); // Convert to ticks
|
||||||
int witherAmplifier = level - 2; // Level 1 = Wither 0, Level 2 = Wither I, Level 3 = Wither II
|
int witherAmplifier = level - 2; // Level 1 = Wither 0, Level 2 = Wither I, Level 3 = Wither II
|
||||||
|
|
||||||
victim.addStatusEffect(new StatusEffectInstance(
|
victim.addEffect(new MobEffectInstance(
|
||||||
StatusEffects.WITHER,
|
MobEffects.WITHER,
|
||||||
witherDuration,
|
witherDuration,
|
||||||
witherAmplifier,
|
witherAmplifier,
|
||||||
false,
|
false,
|
||||||
@@ -39,7 +39,7 @@ public record WitheringEnchantmentEffect(EnchantmentLevelBasedValue duration) im
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
public MapCodec<? extends EnchantmentEntityEffect> codec() {
|
||||||
return CODEC;
|
return CODEC;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
package dev.sillyangel.more_spear_enchantments.util;
|
package dev.sillyangel.more_spear_enchantments.util;
|
||||||
|
|
||||||
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
|
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.world.item.Item;
|
||||||
import net.minecraft.registry.tag.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
|
|
||||||
public class ModTags {
|
public class ModTags {
|
||||||
public static class Blocks {
|
public static class Blocks {
|
||||||
|
|
||||||
private static TagKey<Block> createTag(String name) {
|
private static TagKey<Block> createTag(String name) {
|
||||||
return TagKey.of(RegistryKeys.BLOCK, Identifier.of(MoreSpearEnchantments.MOD_ID, name));
|
return TagKey.create(Registries.BLOCK, Identifier.fromNamespaceAndPath(MoreSpearEnchantments.MOD_ID, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +19,7 @@ public class ModTags {
|
|||||||
public static final TagKey<Item> SPEARS = createTag("spears");
|
public static final TagKey<Item> SPEARS = createTag("spears");
|
||||||
|
|
||||||
private static TagKey<Item> createTag(String name) {
|
private static TagKey<Item> createTag(String name) {
|
||||||
return TagKey.of(RegistryKeys.ITEM, Identifier.of(MoreSpearEnchantments.MOD_ID, name));
|
return TagKey.create(Registries.ITEM, Identifier.fromNamespaceAndPath(MoreSpearEnchantments.MOD_ID, name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,20 @@
|
|||||||
package dev.sillyangel.more_spear_enchantments.fabric.datagen;
|
package dev.sillyangel.more_spear_enchantments.fabric.datagen;
|
||||||
|
|
||||||
import dev.sillyangel.more_spear_enchantments.util.ModTags;
|
import dev.sillyangel.more_spear_enchantments.util.ModTags;
|
||||||
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
|
|
||||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
|
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
|
||||||
import net.minecraft.item.Items;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.registry.RegistryWrapper;
|
import net.minecraft.world.item.Items;
|
||||||
import net.minecraft.registry.tag.ItemTags;
|
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class ModItemTagProvider extends FabricTagProvider.ItemTagProvider {
|
public class ModItemTagProvider extends FabricTagProvider.ItemTagProvider {
|
||||||
public ModItemTagProvider(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> completableFuture) {
|
public ModItemTagProvider(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> completableFuture) {
|
||||||
super(output, completableFuture);
|
super(output, completableFuture);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(RegistryWrapper.WrapperLookup wrapperLookup) {
|
protected void addTags(HolderLookup.Provider wrapperLookup) {
|
||||||
valueLookupBuilder(ModTags.Items.SPEARS)
|
valueLookupBuilder(ModTags.Items.SPEARS)
|
||||||
.add(Items.WOODEN_SPEAR)
|
.add(Items.WOODEN_SPEAR)
|
||||||
.add(Items.STONE_SPEAR)
|
.add(Items.STONE_SPEAR)
|
||||||
|
|||||||
@@ -3,37 +3,41 @@ package dev.sillyangel.more_spear_enchantments.fabric.enchantment;
|
|||||||
import com.mojang.serialization.MapCodec;
|
import com.mojang.serialization.MapCodec;
|
||||||
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
|
import dev.sillyangel.more_spear_enchantments.MoreSpearEnchantments;
|
||||||
import dev.sillyangel.more_spear_enchantments.enchantment.effect.*;
|
import dev.sillyangel.more_spear_enchantments.enchantment.effect.*;
|
||||||
import net.minecraft.registry.Registries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.registry.Registry;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.resources.Identifier;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.world.item.enchantment.effects.EnchantmentEntityEffect;
|
||||||
import net.minecraft.enchantment.effect.EnchantmentEntityEffect;
|
import net.minecraft.world.item.enchantment.Enchantment;
|
||||||
|
|
||||||
public class ModEnchantmentEffects {
|
public class ModEnchantmentEffects {
|
||||||
public static final RegistryKey<Enchantment> THUNDERING = of("thundering");
|
public static final ResourceKey<Enchantment> THUNDERING = of("thundering");
|
||||||
public static final RegistryKey<Enchantment> WITHERING = of("withering");
|
public static MapCodec<LightningEnchantmentEffect> LIGHTNING_EFFECT = register("lightning_effect", LightningEnchantmentEffect.CODEC);
|
||||||
public static final RegistryKey<Enchantment> POISONING = of("poisoning");
|
public static final ResourceKey<Enchantment> WITHERING = of("withering");
|
||||||
public static final RegistryKey<Enchantment> CRIPPLING = of("crippling");
|
public static MapCodec<WitheringEnchantmentEffect> WITHERING_EFFECT = register("withering_effect", WitheringEnchantmentEffect.CODEC);
|
||||||
|
public static final ResourceKey<Enchantment> POISONING = of("poisoning");
|
||||||
|
public static MapCodec<PoisonEnchantmentEffect> POISONING_EFFECT = register("poisoning_effect", PoisonEnchantmentEffect.CODEC);
|
||||||
|
public static final ResourceKey<Enchantment> CRIPPLING = of("crippling");
|
||||||
|
public static MapCodec<CripplingEnchantmentEffect> CRIPPLING_EFFECT = register("crippling_effect", CripplingEnchantmentEffect.CODEC);
|
||||||
|
|
||||||
|
|
||||||
private static RegistryKey<Enchantment> of(String path) {
|
private static ResourceKey<Enchantment> of(String path) {
|
||||||
Identifier id = Identifier.of(MoreSpearEnchantments.MOD_ID, path);
|
Identifier id = Identifier.fromNamespaceAndPath(MoreSpearEnchantments.MOD_ID, path);
|
||||||
return RegistryKey.of(RegistryKeys.ENCHANTMENT, id);
|
return ResourceKey.create(Registries.ENCHANTMENT, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T extends EnchantmentEntityEffect> MapCodec<T> register(String id, MapCodec<T> codec) {
|
private static <T extends EnchantmentEntityEffect> MapCodec<T> register(String id, MapCodec<T> codec) {
|
||||||
return Registry.register(Registries.ENCHANTMENT_ENTITY_EFFECT_TYPE, Identifier.of(MoreSpearEnchantments.MOD_ID, id), codec);
|
return Registry.register(BuiltInRegistries.ENCHANTMENT_ENTITY_EFFECT_TYPE, Identifier.fromNamespaceAndPath(MoreSpearEnchantments.MOD_ID, id), codec);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void registerModEnchantmentEffects() {
|
public static void registerModEnchantmentEffects() {
|
||||||
MoreSpearEnchantments.LOGGER.info("Registering EnchantmentEffects for " + MoreSpearEnchantments.MOD_ID);
|
MoreSpearEnchantments.LOGGER.info("Registering EnchantmentEffects for " + MoreSpearEnchantments.MOD_ID);
|
||||||
|
|
||||||
register("lightning", LightningEnchantmentEffect.CODEC);
|
// register("lightning", LightningEnchantmentEffect.CODEC);
|
||||||
register("poison", PoisonEnchantmentEffect.CODEC);
|
// register("poison", PoisonEnchantmentEffect.CODEC);
|
||||||
register("withering", WitheringEnchantmentEffect.CODEC);
|
// register("withering", WitheringEnchantmentEffect.CODEC);
|
||||||
register("crippling", CripplingEnchantmentEffect.CODEC);
|
// register("crippling", CripplingEnchantmentEffect.CODEC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,111 +5,112 @@ import dev.sillyangel.more_spear_enchantments.enchantment.effect.*;
|
|||||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
|
import net.fabricmc.fabric.api.datagen.v1.provider.FabricDynamicRegistryProvider;
|
||||||
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
|
import net.fabricmc.fabric.api.resource.conditions.v1.ResourceCondition;
|
||||||
import net.minecraft.registry.RegistryWrapper;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.registry.RegistryKeys;
|
import net.minecraft.core.registries.Registries;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.enchantment.Enchantment;
|
import net.minecraft.world.item.enchantment.Enchantment;
|
||||||
import net.minecraft.enchantment.effect.EnchantmentEffectTarget;
|
import net.minecraft.world.item.enchantment.EnchantmentTarget;
|
||||||
import net.minecraft.enchantment.EnchantmentLevelBasedValue;
|
import net.minecraft.world.item.enchantment.LevelBasedValue;
|
||||||
import net.minecraft.component.type.AttributeModifierSlot;
|
import net.minecraft.world.item.enchantment.LevelBasedValue.Linear;
|
||||||
import net.minecraft.component.EnchantmentEffectComponentTypes;
|
import net.minecraft.world.entity.EquipmentSlotGroup;
|
||||||
|
import net.minecraft.world.item.enchantment.EnchantmentEffectComponents;
|
||||||
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
public class ModEnchantmentGenerator extends FabricDynamicRegistryProvider {
|
public class ModEnchantmentGenerator extends FabricDynamicRegistryProvider {
|
||||||
public ModEnchantmentGenerator(FabricDataOutput output, CompletableFuture<RegistryWrapper.WrapperLookup> registriesFuture) {
|
public ModEnchantmentGenerator(FabricDataOutput output, CompletableFuture<HolderLookup.Provider> registriesFuture) {
|
||||||
super(output, registriesFuture);
|
super(output, registriesFuture);
|
||||||
System.out.println("REGISTERING ENCHANTS");
|
System.out.println("REGISTERING ENCHANTS");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(RegistryWrapper.WrapperLookup registries, Entries entries) {
|
protected void configure(HolderLookup.Provider registries, Entries entries) {
|
||||||
// Our new enchantment, "Thundering."
|
// Our new enchantment, "Thundering."
|
||||||
register(entries, ModEnchantmentEffects.THUNDERING, Enchantment.builder(
|
register(entries, ModEnchantmentEffects.THUNDERING, Enchantment.enchantment(
|
||||||
Enchantment.definition(
|
Enchantment.definition(
|
||||||
registries.getOrThrow(RegistryKeys.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
registries.lookupOrThrow(Registries.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
||||||
// this is the "weight" or probability of our enchantment showing up in the table
|
// this is the "weight" or probability of our enchantment showing up in the table
|
||||||
10,
|
10,
|
||||||
// the maximum level of the enchantment
|
// the maximum level of the enchantment
|
||||||
3,
|
3,
|
||||||
// base cost for level 1 of the enchantment, and min levels required for something higher
|
// base cost for level 1 of the enchantment, and min levels required for something higher
|
||||||
Enchantment.leveledCost(1, 10),
|
Enchantment.dynamicCost(1, 10),
|
||||||
// same fields as above but for max cost
|
// same fields as above but for max cost
|
||||||
Enchantment.leveledCost(1, 15),
|
Enchantment.dynamicCost(1, 15),
|
||||||
// anvil cost
|
// anvil cost
|
||||||
5,
|
5,
|
||||||
// valid slots
|
// valid slots
|
||||||
AttributeModifierSlot.HAND
|
EquipmentSlotGroup.HAND
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addEffect(
|
.withEffect(
|
||||||
// enchantment occurs POST_ATTACK
|
// enchantment occurs POST_ATTACK
|
||||||
EnchantmentEffectComponentTypes.POST_ATTACK,
|
EnchantmentEffectComponents.POST_ATTACK,
|
||||||
EnchantmentEffectTarget.ATTACKER,
|
EnchantmentTarget.ATTACKER,
|
||||||
EnchantmentEffectTarget.VICTIM,
|
EnchantmentTarget.VICTIM,
|
||||||
new LightningEnchantmentEffect(EnchantmentLevelBasedValue.linear(0.4f, 0.2f)) // scale the enchantment linearly.
|
new LightningEnchantmentEffect(LevelBasedValue.perLevel(0.4f, 0.2f)) // scale the enchantment linearly.
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
register(entries, ModEnchantmentEffects.POISONING, Enchantment.builder(
|
register(entries, ModEnchantmentEffects.POISONING, Enchantment.enchantment(
|
||||||
Enchantment.definition(
|
Enchantment.definition(
|
||||||
registries.getOrThrow(RegistryKeys.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
registries.lookupOrThrow(Registries.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
||||||
10,
|
10,
|
||||||
3,
|
3,
|
||||||
Enchantment.leveledCost(1, 10),
|
Enchantment.dynamicCost(1, 10),
|
||||||
Enchantment.leveledCost(1, 15),
|
Enchantment.dynamicCost(1, 15),
|
||||||
5,
|
5,
|
||||||
AttributeModifierSlot.HAND
|
EquipmentSlotGroup.HAND
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addEffect(
|
.withEffect(
|
||||||
EnchantmentEffectComponentTypes.POST_ATTACK,
|
EnchantmentEffectComponents.POST_ATTACK,
|
||||||
EnchantmentEffectTarget.ATTACKER,
|
EnchantmentTarget.ATTACKER,
|
||||||
EnchantmentEffectTarget.VICTIM,
|
EnchantmentTarget.VICTIM,
|
||||||
new PoisonEnchantmentEffect(EnchantmentLevelBasedValue.linear(3.0f, 1.0f)) // 3s base, +1s per level
|
new PoisonEnchantmentEffect(LevelBasedValue.perLevel(3.0f, 1.0f)) // 3s base, +1s per level
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Our new enchantment, "Withering."
|
// Our new enchantment, "Withering."
|
||||||
register(entries, ModEnchantmentEffects.WITHERING, Enchantment.builder(
|
register(entries, ModEnchantmentEffects.WITHERING, Enchantment.enchantment(
|
||||||
Enchantment.definition(
|
Enchantment.definition(
|
||||||
registries.getOrThrow(RegistryKeys.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
registries.lookupOrThrow(Registries.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
||||||
10,
|
10,
|
||||||
3,
|
3,
|
||||||
Enchantment.leveledCost(1, 10),
|
Enchantment.dynamicCost(1, 10),
|
||||||
Enchantment.leveledCost(1, 15),
|
Enchantment.dynamicCost(1, 15),
|
||||||
5,
|
5,
|
||||||
AttributeModifierSlot.HAND
|
EquipmentSlotGroup.HAND
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addEffect(
|
.withEffect(
|
||||||
EnchantmentEffectComponentTypes.POST_ATTACK,
|
EnchantmentEffectComponents.POST_ATTACK,
|
||||||
EnchantmentEffectTarget.ATTACKER,
|
EnchantmentTarget.ATTACKER,
|
||||||
EnchantmentEffectTarget.VICTIM,
|
EnchantmentTarget.VICTIM,
|
||||||
new WitheringEnchantmentEffect(EnchantmentLevelBasedValue.linear(2.0f, 1.0f)) // 2s base, +1s per level
|
new WitheringEnchantmentEffect(LevelBasedValue.perLevel(2.0f, 1.0f)) // 2s base, +1s per level
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
// Our new enchantment, "Crippling."
|
// Our new enchantment, "Crippling."
|
||||||
register(entries, ModEnchantmentEffects.CRIPPLING, Enchantment.builder(
|
register(entries, ModEnchantmentEffects.CRIPPLING, Enchantment.enchantment(
|
||||||
Enchantment.definition(
|
Enchantment.definition(
|
||||||
registries.getOrThrow(RegistryKeys.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
registries.lookupOrThrow(Registries.ITEM).getOrThrow(ModTags.Items.SPEARS),
|
||||||
10,
|
10,
|
||||||
3,
|
3,
|
||||||
Enchantment.leveledCost(1, 10),
|
Enchantment.dynamicCost(1, 10),
|
||||||
Enchantment.leveledCost(1, 15),
|
Enchantment.dynamicCost(1, 15),
|
||||||
5,
|
5,
|
||||||
AttributeModifierSlot.HAND
|
EquipmentSlotGroup.HAND
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.addEffect(
|
.withEffect(
|
||||||
EnchantmentEffectComponentTypes.POST_ATTACK,
|
EnchantmentEffectComponents.POST_ATTACK,
|
||||||
EnchantmentEffectTarget.ATTACKER,
|
EnchantmentTarget.ATTACKER,
|
||||||
EnchantmentEffectTarget.VICTIM,
|
EnchantmentTarget.VICTIM,
|
||||||
new CripplingEnchantmentEffect(EnchantmentLevelBasedValue.linear(2.0f, 1.0f)) // 2s base, +1s per leve
|
new CripplingEnchantmentEffect(LevelBasedValue.perLevel(2.0f, 1.0f)) // 2s base, +1s per leve
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register(Entries entries, RegistryKey<Enchantment> key, Enchantment.Builder builder, ResourceCondition... resourceConditions) {
|
private void register(Entries entries, ResourceKey<Enchantment> key, Enchantment.Builder builder, ResourceCondition... resourceConditions) {
|
||||||
entries.add(key, builder.build(key.getValue()), resourceConditions);
|
entries.add(key, builder.build(key.identifier()), resourceConditions); //idk, im going insane
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package dev.sillyangel.more_spear_enchantments.fabric.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 duration) implements EnchantmentEntityEffect {
|
|
||||||
public static final MapCodec<CripplingEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
|
||||||
instance.group(
|
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("duration").forGetter(CripplingEnchantmentEffect::duration)
|
|
||||||
).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.duration.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
package dev.sillyangel.more_spear_enchantments.fabric.enchantment.effect;
|
|
||||||
|
|
||||||
import com.mojang.serialization.MapCodec;
|
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.server.world.ServerWorld;
|
|
||||||
import net.minecraft.entity.Entity;
|
|
||||||
import net.minecraft.entity.EntityType;
|
|
||||||
import net.minecraft.entity.LivingEntity;
|
|
||||||
import net.minecraft.entity.SpawnReason;
|
|
||||||
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 LightningEnchantmentEffect(EnchantmentLevelBasedValue amount) implements EnchantmentEntityEffect {
|
|
||||||
public static final MapCodec<LightningEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
|
||||||
instance.group(
|
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("amount").forGetter(LightningEnchantmentEffect::amount)
|
|
||||||
).apply(instance, LightningEnchantmentEffect::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) {
|
|
||||||
float numStrikes = this.amount.getValue(level);
|
|
||||||
|
|
||||||
for (float i = 0; i < numStrikes; i++) {
|
|
||||||
BlockPos position = victim.getBlockPos();
|
|
||||||
EntityType.LIGHTNING_BOLT.spawn(world, position, SpawnReason.TRIGGERED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
|
||||||
return CODEC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package dev.sillyangel.more_spear_enchantments.fabric.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 PoisonEnchantmentEffect(EnchantmentLevelBasedValue duration) implements EnchantmentEntityEffect {
|
|
||||||
public static final MapCodec<PoisonEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
|
||||||
instance.group(
|
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("duration").forGetter(PoisonEnchantmentEffect::duration)
|
|
||||||
).apply(instance, PoisonEnchantmentEffect::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 poisonDuration = (int) (this.duration.getValue(level) * 40); // Convert to ticks
|
|
||||||
int poisonAmplifier = level - 2; // Level 1 = Poison 0, Level 2 = Poison I, Level 3 = Poison II
|
|
||||||
|
|
||||||
victim.addStatusEffect(new StatusEffectInstance(
|
|
||||||
StatusEffects.POISON,
|
|
||||||
poisonDuration,
|
|
||||||
poisonAmplifier,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
|
||||||
return CODEC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package dev.sillyangel.more_spear_enchantments.fabric.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 WitheringEnchantmentEffect(EnchantmentLevelBasedValue duration) implements EnchantmentEntityEffect {
|
|
||||||
public static final MapCodec<WitheringEnchantmentEffect> CODEC = RecordCodecBuilder.mapCodec(instance ->
|
|
||||||
instance.group(
|
|
||||||
EnchantmentLevelBasedValue.CODEC.fieldOf("duration").forGetter(WitheringEnchantmentEffect::duration)
|
|
||||||
).apply(instance, WitheringEnchantmentEffect::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 witherDuration = (int) (this.duration.getValue(level) * 40); // Convert to ticks
|
|
||||||
int witherAmplifier = level - 2; // Level 1 = Wither 0, Level 2 = Wither I, Level 3 = Wither II
|
|
||||||
|
|
||||||
victim.addStatusEffect(new StatusEffectInstance(
|
|
||||||
StatusEffects.WITHER,
|
|
||||||
witherDuration,
|
|
||||||
witherAmplifier,
|
|
||||||
false,
|
|
||||||
true
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public MapCodec<? extends EnchantmentEntityEffect> getCodec() {
|
|
||||||
return CODEC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
|
|
||||||
@Mixin(MinecraftServer.class)
|
@Mixin(MinecraftServer.class)
|
||||||
public class ExampleMixin {
|
public class ExampleMixin {
|
||||||
@Inject(at = @At("HEAD"), method = "loadWorld")
|
@Inject(at = @At("HEAD"), method = "loadLevel")
|
||||||
private void init(CallbackInfo info) {
|
private void init(CallbackInfo info) {
|
||||||
// This code is injected into the start of MinecraftServer.loadWorld()V
|
// This code is injected into the start of MinecraftServer.loadWorld()V
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,18 +3,16 @@ org.gradle.jvmargs=-Xmx2G
|
|||||||
org.gradle.parallel=true
|
org.gradle.parallel=true
|
||||||
|
|
||||||
# Mod properties
|
# Mod properties
|
||||||
mod_version = 1.0.1
|
mod_version = 1.1.0
|
||||||
maven_group = dev.sillyangel.more_spear_enchantments
|
maven_group = dev.sillyangel.more_spear_enchantments
|
||||||
archives_name = more_spear_enchantments
|
archives_name = more_spear_enchantments
|
||||||
enabled_platforms = fabric,neoforge
|
enabled_platforms = fabric,neoforge
|
||||||
|
|
||||||
# Minecraft properties
|
# Minecraft properties
|
||||||
minecraft_version = 1.21.11
|
minecraft_version = 1.21.11
|
||||||
yarn_mappings = 1.21.11+build.3
|
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
architectury_api_version = 19.0.1
|
architectury_api_version = 19.0.1
|
||||||
fabric_loader_version = 0.18.4
|
fabric_loader_version = 0.18.4
|
||||||
fabric_api_version = 0.140.2+1.21.11
|
fabric_api_version = 0.140.2+1.21.11
|
||||||
neoforge_version = 21.11.17-beta
|
neoforge_version = 21.11.17-beta
|
||||||
yarn_mappings_patch_neoforge_version = 1.21+build.6
|
|
||||||
|
|||||||
Reference in New Issue
Block a user