Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
refactor(porting): EnchUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
WakelessSloth56 committed Dec 17, 2021
1 parent f31a00d commit aa06a6e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/org/auioc/mods/ahutils/utils/game/EnchUtils.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
package org.auioc.mods.ahutils.utils.game;

import java.util.Random;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.nbt.ListNBT;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraftforge.registries.ForgeRegistries;

public interface EnchUtils {
static Enchantment getEnchantment(String id) {
return ForgeRegistries.ENCHANTMENTS.getValue(new ResourceLocation(id));
}

static void enchantAll(ListNBT enchantments) {
static void enchantAll(ListTag enchantments) {
for (int i = 0; i < enchantments.size(); i++) {
CompoundNBT nbt = enchantments.getCompound(i);
CompoundTag nbt = enchantments.getCompound(i);
nbt.putShort("lvl", (short) (nbt.getShort("lvl") + 1));
}
}

static void enchantOne(ListNBT enchantments, int index) {
CompoundNBT nbt = enchantments.getCompound(index);
static void enchantOne(ListTag enchantments, int index) {
CompoundTag nbt = enchantments.getCompound(index);
nbt.putShort("lvl", (short) (nbt.getShort("lvl") + 1));
}

static void enchantRandom(ListNBT enchantments) {
static void enchantRandom(ListTag enchantments) {
int enchCount = enchantments.size();
int index = (new Random()).nextInt((enchCount - 0) + 1) + 0;
CompoundNBT nbt = enchantments.getCompound(index);
CompoundTag nbt = enchantments.getCompound(index);
nbt.putShort("lvl", (short) (nbt.getShort("lvl") + 1));
}
}

0 comments on commit aa06a6e

Please sign in to comment.