diff --git a/src/main/java/anticope/rejects/utils/GiveUtils.java b/src/main/java/anticope/rejects/utils/GiveUtils.java index 1825f80..b49742c 100644 --- a/src/main/java/anticope/rejects/utils/GiveUtils.java +++ b/src/main/java/anticope/rejects/utils/GiveUtils.java @@ -5,6 +5,7 @@ import net.minecraft.component.ComponentChanges; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.*; +import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.Enchantments; import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffectInstance; @@ -15,6 +16,8 @@ import net.minecraft.nbt.NbtList; import net.minecraft.nbt.StringNbtReader; import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -65,6 +68,7 @@ public class GiveUtils { ); private static final Random random = new Random(); + private static Registry enchantmentRegistry; public static void giveItem(ItemStack item) throws CommandSyntaxException { if (!mc.player.getAbilities().creativeMode) throw NOT_IN_CREATIVE.create(); @@ -134,19 +138,21 @@ public static void giveItem(ItemStack item) throws CommandSyntaxException { }); PRESETS.put("32k", (preview) -> { - if (preview) return Items.DIAMOND_SWORD.getDefaultStack(); + enchantmentRegistry = mc.world.getRegistryManager().get(RegistryKeys.ENCHANTMENT); + + if (preview || enchantmentRegistry == null) return Items.DIAMOND_SWORD.getDefaultStack(); ItemStack stack = Items.DIAMOND_SWORD.getDefaultStack(); stack.apply(DataComponentTypes.ENCHANTMENTS, ItemEnchantmentsComponent.DEFAULT, component -> { ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(component); - builder.add(Enchantments.SHARPNESS, 255); - builder.add(Enchantments.KNOCKBACK, 255); - builder.add(Enchantments.FIRE_ASPECT, 255); - builder.add(Enchantments.LOOTING, 10); - builder.add(Enchantments.SWEEPING_EDGE, 3); - builder.add(Enchantments.UNBREAKING, 255); - builder.add(Enchantments.MENDING, 1); - builder.add(Enchantments.VANISHING_CURSE, 1); + builder.add(enchantmentRegistry.entryOf(Enchantments.SHARPNESS), 255); + builder.add(enchantmentRegistry.entryOf(Enchantments.KNOCKBACK), 255); + builder.add(enchantmentRegistry.entryOf(Enchantments.FIRE_ASPECT), 255); + builder.add(enchantmentRegistry.entryOf(Enchantments.LOOTING), 10); + builder.add(enchantmentRegistry.entryOf(Enchantments.SWEEPING_EDGE), 3); + builder.add(enchantmentRegistry.entryOf(Enchantments.UNBREAKING), 255); + builder.add(enchantmentRegistry.entryOf(Enchantments.MENDING), 1); + builder.add(enchantmentRegistry.entryOf(Enchantments.VANISHING_CURSE), 1); return builder.build(); });