Start making use of partial item

This commit is contained in:
zontreck 2024-04-01 17:00:05 -07:00
parent afb21dd2c8
commit 48c83245c9
5 changed files with 49 additions and 13 deletions

View file

@ -9,18 +9,35 @@ import net.minecraft.server.commands.GiveCommand;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.Level;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class PartialItem extends Item
{
private static final String TAG_UNCRAFT_REMAIN = "remaining";
private static final String TAG_UNCRAFT_LIST = "Items";
@Override
public boolean isEnchantable(ItemStack p_41456_) {
return true;
}
@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return false;
}
@Override
public boolean isBookEnchantable(ItemStack stack, ItemStack book) {
return false;
}
public PartialItem() {
super (new Properties().fireResistant());
@ -36,8 +53,12 @@ public class PartialItem extends Item
{
tooltip.add(ChatHelpers.macro("!Dark_Red!Number of uncraft steps remaining: [0]", "!Yellow!" + stack.getTag().getInt(TAG_UNCRAFT_REMAIN)));
}
if(stack.getTag().contains(ItemStack.TAG_ENCH))
{
tooltip.add(ChatHelpers.macro("!Dark_Red!Number of Enchantments remaining: [0]", "!Yellow!" + stack.getTag().getList(ItemStack.TAG_ENCH, Tag.TAG_COMPOUND).size()));
}
} else {
tooltip.add(ChatHelpers.macro("!Dark_Red!This partial item appears to be invalid, and contains no item fragments."));
tooltip.add(ChatHelpers.macro("!Dark_Red!This partial item appears to be invalid, and contains no fragments."));
}
}
@ -67,4 +88,18 @@ public class PartialItem extends Item
{
return ForgeRegistries.ITEMS.getValue(new ResourceLocation(item));
}
public static ItemStack makePartialItem(ItemStack original, boolean enchantMode, boolean uncraftMode)
{
if(enchantMode)
{
ItemStack partial = new ItemStack(ModItems.PARTIAL_ITEM.get(), 1);
CompoundTag tag = new CompoundTag();
tag.put(ItemStack.TAG_ENCH, original.getTag().get(ItemStack.TAG_ENCH));
partial.setTag(tag);
return partial;
} else return original;
}
}