diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java index 69e2aa1..7b7c3df 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/ChestBoatMixin.java @@ -25,7 +25,7 @@ public class ChestBoatMixin { method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/vehicle/VehicleEntity;destroy(Lnet/minecraft/world/item/Item;)V" + target = "Lnet/minecraft/world/entity/vehicle/ChestBoat;destroy(Lnet/minecraft/world/item/Item;)V" ) ) private void checkForPlayer( diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/InventoryMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/InventoryMixin.java deleted file mode 100644 index e9b2cdc..0000000 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/InventoryMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.nyon.telekinesis.mixins; - -import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; -import net.minecraft.world.entity.player.Inventory; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.ItemStack; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; - -@Mixin(Inventory.class) -public class InventoryMixin { - - @WrapWithCondition( - method = "dropAll", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/world/entity/player/Player;drop(Lnet/minecraft/world/item/ItemStack;ZZ)Lnet/minecraft/world/entity/item/ItemEntity;" - ) - ) - public boolean redirectEquipmentDrop( - Player instance, - ItemStack stack, - boolean throwRandomly, - boolean retainOwnership - ) { - return EntityUtils.spawnAtLocationInject(instance, stack); - } -} diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java index 1ef91af..2606883 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/LivingEntityMixin.java @@ -1,69 +1,67 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; -import dev.nyon.telekinesis.TelekinesisPolicy; -import net.minecraft.server.level.ServerLevel; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import dev.nyon.telekinesis.DropEvent; +import dev.nyon.telekinesis.utils.MixinHelper; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.phys.Vec3; +import net.minecraft.world.level.storage.loot.LootParams; +import net.minecraft.world.level.storage.loot.parameters.LootContextParams; +import org.apache.commons.lang3.mutable.MutableInt; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; +import org.spongepowered.asm.mixin.injection.ModifyArg; +import java.util.ArrayList; +import java.util.List; import java.util.function.Consumer; @Mixin(LivingEntity.class) public abstract class LivingEntityMixin { - @Unique - final LivingEntity livingEntity = (LivingEntity) (Object) this; - @WrapWithCondition( + @ModifyExpressionValue( method = "dropExperience", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/ExperienceOrb;award(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/phys/Vec3;I)V" + target = "Lnet/minecraft/world/entity/LivingEntity;getExperienceReward(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/entity/Entity;)I" ) ) - public boolean redirectExp( - ServerLevel world, - Vec3 pos, - int amount + public int redirectExp( + int original, + Entity entity ) { - final var attacker = livingEntity.getLastAttacker(); - if (!(attacker instanceof ServerPlayer serverPlayer)) return true; + if (!(entity instanceof ServerPlayer player)) return original; - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ExpDrops, - serverPlayer, - serverPlayer.getMainHandItem(), - player -> PlayerUtils.addExpToPlayer(player, amount) - ); - - return !hasTelekinesis; + return MixinHelper.modifyExpressionValuePlayerExp(player, original); } - @ModifyArgs( + @ModifyArg( method = "dropFromLootTable", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/level/storage/loot/LootTable;getRandomItems(Lnet/minecraft/world/level/storage/loot/LootParams;JLjava/util/function/Consumer;)V" - ) + ), + index = 2 ) - public void redirectCommonDrops( - Args args, - DamageSource damageSource, - boolean bl + public Consumer redirectCommonDrops( + LootParams params, + long seed, + Consumer original ) { - args.>set(2, item -> { - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.MobDrops, damageSource, player -> { - if (!player.addItem(item)) livingEntity.spawnAtLocation(item); - }); + DamageSource source = params.getParamOrNull(LootContextParams.DAMAGE_SOURCE); + if (source == null || !(source.getEntity() instanceof ServerPlayer player)) return original; + + return item -> { + ArrayList mutableList = new ArrayList<>(List.of(item)); + DropEvent.INSTANCE.getEvent() + .invoker() + .invoke(mutableList, new MutableInt(0), player, player.getMainHandItem()); - if (!hasTelekinesis) livingEntity.spawnAtLocation(item); - }); + if (!mutableList.isEmpty()) original.accept(item); + }; } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java index 555daf3..5212abb 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/MinecartTNTMixin.java @@ -1,5 +1,9 @@ package dev.nyon.telekinesis.mixins; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.vehicle.MinecartTNT; import org.spongepowered.asm.mixin.Mixin; @@ -7,6 +11,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.item.Item; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; /*?}*/ @@ -14,18 +19,23 @@ public class MinecartTNTMixin { /*? if >1.20.2 {*/ - @ModifyExpressionValue( + @Unique + private static final ThreadLocal threadLocal = new ThreadLocal<>(); + + @WrapOperation( method = "destroy(Lnet/minecraft/world/damagesource/DamageSource;)V", at = @At( value = "INVOKE", - target = "Lnet/minecraft/world/entity/vehicle/MinecartTNT;getDropItem()Lnet/minecraft/world/item/Item;" + target = "Lnet/minecraft/world/entity/vehicle/MinecartTNT;destroy(Lnet/minecraft/world/item/Item;)V" ) ) - private Item changeDroppedItem( - Item original, - DamageSource damageSource + private void checkForPlayer( + MinecartTNT instance, + Item dropItem, + Operation original, + DamageSource source ) { - return EntityUtils.getDropItemInject(original, damageSource); + MixinHelper.prepareVehicleServerPlayer(instance, dropItem, original, source, threadLocal); } /*?}*/ } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java index 67d08c1..06a5ae7 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SheepMixin.java @@ -1,91 +1,56 @@ package dev.nyon.telekinesis.mixins; -import dev.nyon.telekinesis.TelekinesisPolicy; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import dev.nyon.telekinesis.utils.MixinHelper; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundSource; -import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.animal.Sheep; -import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; -import org.spongepowered.asm.mixin.Final; +import net.minecraft.world.level.block.Block; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -import java.util.Map; @Mixin(Sheep.class) public abstract class SheepMixin { - @Shadow - @Final - private static Map ITEM_BY_DYE; @Unique - private final RandomSource random = RandomSource.create(); - + private static final ThreadLocal threadLocal = new ThreadLocal<>(); - @Redirect( + @WrapOperation( method = "mobInteract", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/Sheep;shear(Lnet/minecraft/sounds/SoundSource;)V" ) ) - public void manipulateWoolDrops( + private void prepareThreadLocalForShearing( Sheep instance, - SoundSource soundSource, - Player player, - InteractionHand interactionHand + SoundSource source, + Operation original, + Player _player, + InteractionHand hand ) { - instance.level() - .playSound(null, instance, SoundEvents.SHEEP_SHEAR, soundSource, 1.0F, 1.0F); - instance.setSheared(true); - int i = 1 + random.nextInt(3); - - if (!(player instanceof ServerPlayer serverPlayerr)) { - dropAllNormally(i, instance); - return; - } - - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ShearingDrops, - serverPlayerr, - player.getItemInHand(interactionHand), - serverPlayer -> { - for (int j = 0; j < i; ++j) { - if (!serverPlayer.addItem(new ItemStack(ITEM_BY_DYE.get(instance.getColor()), 1))) { - ItemEntity entity = instance.spawnAtLocation(ITEM_BY_DYE.get(instance.getColor()), 1); - entity.setDeltaMovement(entity.getDeltaMovement() - .add((random.nextFloat() - random.nextFloat()) * 0.1F, - random.nextFloat() * 0.05F, - (random.nextFloat() - random.nextFloat()) * 0.1F - )); - } - } - } - ); - - if (!hasTelekinesis) dropAllNormally(i, instance); + MixinHelper.prepareShearableServerPlayer(instance, source, original, _player, threadLocal); } - @Unique - void dropAllNormally( - int i, - Sheep instance - ) { - for (int j = 0; j < i; ++j) { - ItemEntity entity = instance.spawnAtLocation(ITEM_BY_DYE.get(instance.getColor()), 1); - entity.setDeltaMovement(entity.getDeltaMovement() - .add((random.nextFloat() - random.nextFloat()) * 0.1F, - random.nextFloat() * 0.05F, - (random.nextFloat() - random.nextFloat()) * 0.1F - )); - } + @ModifyExpressionValue( + method = "shear", + at = @At( + value = "INVOKE", + target = "Ljava/util/Map;get(Ljava/lang/Object;)Ljava/lang/Object;" + ) + ) + private Object modifyShearDrops(Object original) { + ServerPlayer player = threadLocal.get(); + if (!(original instanceof Block block)) return original; + if (player == null) return original; + + if (MixinHelper.wrapWithConditionPlayerItemSingle(player, new ItemStack(block))) return original; + else return ItemStack.EMPTY; } } \ No newline at end of file diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java index 464ef17..ef5e437 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/SnowGolemMixin.java @@ -1,46 +1,54 @@ package dev.nyon.telekinesis.mixins; -import dev.nyon.telekinesis.TelekinesisPolicy; -import net.minecraft.sounds.SoundEvents; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import dev.nyon.telekinesis.utils.MixinHelper; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundSource; -import net.minecraft.world.InteractionHand; import net.minecraft.world.entity.animal.SnowGolem; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.Items; +import net.minecraft.world.level.ItemLike; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; +import org.spongepowered.asm.mixin.injection.ModifyArg; @Mixin(SnowGolem.class) public class SnowGolemMixin { - @Redirect( + @Unique + private static final ThreadLocal threadLocal = new ThreadLocal<>(); + + @WrapOperation( method = "mobInteract", at = @At( value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/SnowGolem;shear(Lnet/minecraft/sounds/SoundSource;)V" ) ) - public void manipulateWoolDrops( + private void prepareThreadLocalForShearing( SnowGolem instance, - SoundSource soundSource, - Player player, - InteractionHand interactionHand + SoundSource source, + Operation original, + Player _player ) { - instance.level() - .playSound(null, instance, SoundEvents.SNOW_GOLEM_SHEAR, soundSource, 1.0F, 1.0F); - if (!instance.level() - .isClientSide()) { - instance.setPumpkin(false); - - ItemStack item = new ItemStack(Items.CARVED_PUMPKIN); + MixinHelper.prepareShearableServerPlayer(instance, source, original, _player, threadLocal); + } - boolean hasTelekinesis = TelekinesisUtils.handleTelekinesis(TelekinesisPolicy.ShearingDrops, player, serverPlayer -> { - if (!serverPlayer.addItem(item)) instance.spawnAtLocation(item, 1.7F); - }); + @ModifyArg( + method = "shear", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/world/item/ItemStack;(Lnet/minecraft/world/level/ItemLike;)V" + ) + ) + private ItemLike modifyShearDrops(ItemLike original) { + ServerPlayer player = threadLocal.get(); + if (player == null) return original; - if (!hasTelekinesis) instance.spawnAtLocation(item, 1.7F); - } + if (MixinHelper.wrapWithConditionPlayerItemSingle(player, new ItemStack(original))) return original; + else return Items.AIR; } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java index 9a00cf0..8085561 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/mixins/WitherBossMixin.java @@ -1,31 +1,33 @@ package dev.nyon.telekinesis.mixins; -import com.llamalad7.mixinextras.injector.v2.WrapWithCondition; import dev.nyon.telekinesis.utils.MixinHelper; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.boss.wither.WitherBoss; +import net.minecraft.world.entity.item.ItemEntity; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; import net.minecraft.world.level.ItemLike; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArgs; +import org.spongepowered.asm.mixin.injection.invoke.arg.Args; @Mixin(WitherBoss.class) public abstract class WitherBossMixin { - @WrapWithCondition( + @ModifyArgs( method = "dropCustomDeathLoot", at = @At( value = "INVOKE", - target = "net/minecraft/world/entity/boss/wither/WitherBoss.spawnAtLocation (Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" + target = "Lnet/minecraft/world/entity/boss/wither/WitherBoss;spawnAtLocation(Lnet/minecraft/world/level/ItemLike;)Lnet/minecraft/world/entity/item/ItemEntity;" ) ) - protected boolean redirectEquipmentDrop( - WitherBoss instance, - ItemLike itemLike, - ServerLevel serverLevel, - DamageSource damageSource, - boolean bl + protected void redirectEquipmentDrop( + Args args, ServerLevel serverLevel, DamageSource damageSource, boolean bl ) { - return MixinHelper.entityCustomDeathLootSingle(damageSource, new ItemStack(itemLike)); + ItemLike original = args.get(0); + + if (MixinHelper.entityCustomDeathLootSingle(damageSource, new ItemStack(original))) return; + args.set(0, Items.AIR); } } diff --git a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/MixinHelper.java b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/MixinHelper.java index 33c0960..c8e8d3b 100644 --- a/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/MixinHelper.java +++ b/telekinesis-fabric/src/main/java/dev/nyon/telekinesis/utils/MixinHelper.java @@ -3,10 +3,12 @@ import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import dev.nyon.telekinesis.DropEvent; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.sounds.SoundSource; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.LivingEntity; -import net.minecraft.world.entity.vehicle.ChestBoat; +import net.minecraft.world.entity.Shearable; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.vehicle.VehicleEntity; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; @@ -29,6 +31,18 @@ public static boolean wrapWithConditionPlayerItemSingle( return !mutableList.isEmpty(); } + public static int modifyExpressionValuePlayerExp( + ServerPlayer player, + int exp + ) { + MutableInt mutableInt = new MutableInt(exp); + DropEvent.INSTANCE.getEvent() + .invoker() + .invoke(new ArrayList<>(), mutableInt, player, player.getMainHandItem()); + + return mutableInt.getValue(); + } + public static boolean entityDropEquipmentSingle( LivingEntity entity, ItemStack item @@ -111,4 +125,25 @@ public static void prepareVehicleServerPlayer( threadLocal.set(previous); } } + + public static void prepareShearableServerPlayer( + Shearable instance, + SoundSource source, + Operation original, + Player _player, + ThreadLocal threadLocal + ) { + if (!(_player instanceof ServerPlayer player)) { + original.call(instance, source); + return; + } + + ServerPlayer previous = threadLocal.get(); + threadLocal.set(player); + try { + original.call(instance, source); + } finally { + threadLocal.set(previous); + } + } } diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt index 1c47db6..78ed8b2 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantment.kt @@ -1,5 +1,11 @@ package dev.nyon.telekinesis +import net.minecraft.core.registries.Registries +import net.minecraft.resources.ResourceLocation +import net.minecraft.tags.TagKey + + + /*? if <1.21 {*//* import net.minecraft.network.chat.Component import net.minecraft.network.chat.Style @@ -49,3 +55,6 @@ class TelekinesisEnchantment : Enchantment( Component.translatable("enchantment.telekinesis.telekinesis.name").withStyle(Style.EMPTY.withColor(0xFFB64C)) } *//*?}*/ + +val tagKey = TagKey.create(Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath("telekinesis", "auto_move")) +val enchantmentId = ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis") \ No newline at end of file diff --git a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt index 9b14656..3f81135 100644 --- a/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt +++ b/telekinesis-fabric/src/main/kotlin/dev/nyon/telekinesis/TelekinesisEnchantmentGenerator.kt @@ -4,6 +4,7 @@ import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator 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.FabricTagProvider.EnchantmentTagProvider import net.minecraft.core.HolderLookup import net.minecraft.core.RegistrySetBuilder import net.minecraft.core.registries.Registries @@ -20,13 +21,15 @@ class TelekinesisEnchantmentGenerator : DataGeneratorEntrypoint { override fun onInitializeDataGenerator(generator: FabricDataGenerator) {/*? if >=1.21 {*/ val pack = generator.createPack() - pack.addProvider(::EnchantmentProvider)/*?}*/ + pack.addProvider(::EnchantmentProvider) + pack.addProvider(::TelekinesisTagProvider) + /*?}*/ } override fun buildRegistry(registryBuilder: RegistrySetBuilder) { registryBuilder.add(Registries.ENCHANTMENT) { context -> val enchantmentDefinition: EnchantmentDefinition = Enchantment.definition( - context.lookup(Registries.ITEM).getOrThrow(ItemTags.DURABILITY_ENCHANTABLE), + context.lookup(Registries.ITEM).getOrThrow(ItemTags.DURABILITY_ENCHANTABLE), // TODO: only tools!! 2, 1, dynamicCost(25, 25), @@ -36,9 +39,7 @@ class TelekinesisEnchantmentGenerator : DataGeneratorEntrypoint { ) context.register( - ResourceKey.create( - Registries.ENCHANTMENT, ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis") - ), Enchantment.enchantment(enchantmentDefinition).build( + ResourceKey.create(Registries.ENCHANTMENT, enchantmentId), Enchantment.enchantment(enchantmentDefinition).build( ResourceLocation.fromNamespaceAndPath("telekinesis", "telekinesis.name") ) ) @@ -46,6 +47,14 @@ class TelekinesisEnchantmentGenerator : DataGeneratorEntrypoint { } } +private class TelekinesisTagProvider( + output: FabricDataOutput, completableFuture: CompletableFuture +) : EnchantmentTagProvider(output, completableFuture) { + override fun addTags(registries: HolderLookup.Provider) { + getOrCreateTagBuilder(tagKey).add(enchantmentId) + } +} + private class EnchantmentProvider( output: FabricDataOutput, registriesFuture: CompletableFuture ) : FabricDynamicRegistryProvider(output, registriesFuture) { diff --git a/telekinesis-fabric/src/main/resources/telekinesis.mixins.json b/telekinesis-fabric/src/main/resources/telekinesis.mixins.json index c5121f2..8607cf6 100644 --- a/telekinesis-fabric/src/main/resources/telekinesis.mixins.json +++ b/telekinesis-fabric/src/main/resources/telekinesis.mixins.json @@ -1,35 +1,34 @@ { - "required": true, - "minVersion": "0.8", - "package": "dev.nyon.telekinesis.mixins", - "compatibilityLevel": "JAVA_17", - "mixins": [ - "AbstractChestedHorseMixin", - "AbstractHorseMixin", - "AbstractMinecartMixin", - "AllayMixin", - "BlockMixin", - "BoatMixin", - "ChestBoatMixin", - "EnchantmentsMixin", - "EnderManMixin", - "FishingHookMixin", - "InventoryMixin", - "LivingEntityMixin", - "MinecartTNTMixin", - "MobMixin", - "PiglinMixin", - "PigMixin", - "PlayerMixin", - "SheepMixin", - "SnowGolemMixin", - "SpawnerBlockMixin", - "StriderMixin", - "SweetBerryBushBlockMixin", - "VehicleEntityMixin", - "WitherBossMixin" - ], - "injectors": { - "defaultRequire": 1 + "required": true, + "minVersion": "0.8", + "package": "dev.nyon.telekinesis.mixins", + "compatibilityLevel": "JAVA_17", + "mixins": [ + "AbstractChestedHorseMixin", + "AbstractHorseMixin", + "AbstractMinecartMixin", + "AllayMixin", + "BlockMixin", + "BoatMixin", + "ChestBoatMixin", + "EnchantmentsMixin", + "EnderManMixin", + "FishingHookMixin", + "LivingEntityMixin", + "MinecartTNTMixin", + "MobMixin", + "PiglinMixin", + "PigMixin", + "PlayerMixin", + "SheepMixin", + "SnowGolemMixin", + "SpawnerBlockMixin", + "StriderMixin", + "SweetBerryBushBlockMixin", + "VehicleEntityMixin", + "WitherBossMixin" + ], + "injectors": { + "defaultRequire": 1 } }