Deploy some new helper functions in the API

This commit is contained in:
Aria 2023-02-22 03:52:00 -07:00
parent 954642b922
commit 116e2d92e1
4 changed files with 47 additions and 3 deletions

View file

@ -5,5 +5,5 @@ org.gradle.daemon=false
mc_version=1.18.2 mc_version=1.18.2
forge_version=40.2.1 forge_version=40.2.1
myversion=1.0.4.9 myversion=1.0.4.10
parchment_version=2022.11.06 parchment_version=2022.11.06

View file

@ -0,0 +1,44 @@
package dev.zontreck.libzontreck.util;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
public class ItemUtils {
public static Map<Enchantment, Integer> getEnchantments(ItemStack stack)
{
ListTag enchants = stack.getEnchantmentTags();
Map<Enchantment, Integer> enchantments = new HashMap<>();
Iterator<Tag> enchantsIterator = enchants.iterator();
while(enchantsIterator.hasNext())
{
CompoundTag theTag = (CompoundTag)enchantsIterator.next();
Enchantment ench = Registry.ENCHANTMENT.getOptional(EnchantmentHelper.getEnchantmentId(theTag)).get();
Integer level = EnchantmentHelper.getEnchantmentLevel(theTag);
enchantments.put(ench, level);
}
return enchantments;
}
public static Integer getEnchantmentLevel(Enchantment ench, ItemStack stack)
{
Integer ret = 0;
Map<Enchantment, Integer> enchants = getEnchantments(stack);
ret=enchants.get(ench);
return ret;
}
}

View file

@ -19,7 +19,7 @@ modId="libzontreck" #mandatory
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it # The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata # ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
# see the associated build.gradle script for how to populate this completely automatically during a build # see the associated build.gradle script for how to populate this completely automatically during a build
version="1.0.4.9" #mandatory version="1.0.4.10" #mandatory
# A display name for the mod # A display name for the mod
displayName="LibZontreck" #mandatory displayName="LibZontreck" #mandatory
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/ # A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/

View file

@ -3,6 +3,6 @@
"description": "libzontreck resources", "description": "libzontreck resources",
"pack_format": 9, "pack_format": 9,
"forge:resource_pack_format": 9, "forge:resource_pack_format": 9,
"forge:data_pack_format": 10 "forge:data_pack_format": 9
} }
} }