Skip to content

Commit

Permalink
Update GiveUtils.java
Browse files Browse the repository at this point in the history
  • Loading branch information
crazymoose77756 committed Jun 25, 2024
1 parent f1cc9f6 commit dec715c
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/main/java/anticope/rejects/utils/GiveUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -65,6 +68,7 @@ public class GiveUtils {
);

private static final Random random = new Random();
private static Registry<Enchantment> enchantmentRegistry;

public static void giveItem(ItemStack item) throws CommandSyntaxException {
if (!mc.player.getAbilities().creativeMode) throw NOT_IN_CREATIVE.create();
Expand Down Expand Up @@ -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();
});

Expand Down

0 comments on commit dec715c

Please sign in to comment.