Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.14.3] Ingredient.fromTag() isn't working


SansyHuman
 Share

Recommended Posts

I created an item "Copper Ingot" whose tag is "forge:ingots/copper". I made a constant which contains that tag.

public final class ForgeItemTags
{
	public static final Tag<Item> COPPER_INGOT = ItemTags.getCollection().getOrCreate(new ResourceLocation("forge", "ingots/copper"));
	
	private ForgeItemTags() {}
}

And I used Ingredient.fromTag() method to set all copper ingots, including my copper ingot, to be repair materials of copper tools.

public enum BiomeOreItemTier implements IItemTier
{
	COPPER(2, 223, 5.7F, 2.0F, 15, Ingredient.fromTag(ForgeItemTags.COPPER_INGOT));
	
	private final int harvestLevel;
	private final int maxUses;
	private final float efficiency;
	private final float attackDamage;
	private final int enchantability;
	private final Ingredient repairMaterial;
	
	BiomeOreItemTier(int harvestLevel, int maxUses, float efficiency, float attackDamage, int enchantability, Ingredient repairMaterial)
	{
		this.harvestLevel = harvestLevel;
		this.maxUses = maxUses;
		this.efficiency = efficiency;
		this.attackDamage = attackDamage;
		this.enchantability = enchantability;
		this.repairMaterial = repairMaterial;
	}
	
	/...
}

Then I used the COPPER ItemTier to make my copper sword.

public static final Item COPPER_SWORD = register("copper_sword", new SwordItem(BiomeOreItemTier.COPPER, 3, -2.4F, new Item.Properties().group(BiomeOreItemGroup.BIOME_ORE_TOOL)));

But in the game, I cannot repair my sword using my copper ingot. I can't figure out what is wrong with my codes. When I printed the item tag of my copper ingot using onItemRightClick() method in Item class the ingot had the tag "forge:ingots/copper". But it cannot repair my copper tools. How can I fix it?

Link to comment
Share on other sites

58 minutes ago, cheaterpaul said:

while you created the tag, the tag is not filled with anything. For that you must create this json "resources/forge/tags/items/ingots/copper.json" and fill it with


{
  "replace": false,
  "values": [
    "modid:yourCopperIngot"
  ]
}

 

Of course I made that file, but it didn't work.

Link to comment
Share on other sites

while i cant see your whole code, this works for me:

package com.example.examplemod;
*imports
@Mod("examplemod")
public class ExampleMod
{
    public static Tag<Item> coppertag = new ItemTags.Wrapper(new ResourceLocation("forge", "ingots/copper"));
    public ExampleMod() {
    }
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onItemRegistry(final RegistryEvent.Register<Item> blockRegistryEvent) {
            blockRegistryEvent.getRegistry().register(new Item(new Item.Properties().group(ItemGroup.BREWING)).setRegistryName("examplemod:copper"));
            blockRegistryEvent.getRegistry().register(new SwordItem(new Tier(),4,1,new Item.Properties().group(ItemGroup.BREWING)).setRegistryName("examplemod:coppersword"));
        }
    }

    public static class Tier implements IItemTier{
        @Override
        public int getMaxUses() {
            return 100;
        }

        @Override
        public float getEfficiency() {
            return 4;
        }

        @Override
        public float getAttackDamage() {
            return 2;
        }

        @Override
        public int getHarvestLevel() {
            return 1;
        }

        @Override
        public int getEnchantability() {
            return 50;
        }

        @Override
        public Ingredient getRepairMaterial() {
            return Ingredient.fromTag(coppertag);
        }

        public Tier() {
        }
    }
}

 but i think the problem is that you need

public static final Tag<Item> COPPER_INGOT = new ItemTags.Wrapper(new ResourceLocation("forge", "ingots/copper"));

not

public static final Tag<Item> COPPER_INGOT = ItemTags.getCollection().getOrCreate(new ResourceLocation("forge", "ingots/copper"));

 

otherwise your copper.json is in a wrong directory

Edited by cheaterpaul
Link to comment
Share on other sites

43 minutes ago, cheaterpaul said:

while i cant see your whole code, this works for me:


package com.example.examplemod;
*imports
@Mod("examplemod")
public class ExampleMod
{
    public static Tag<Item> coppertag = new ItemTags.Wrapper(new ResourceLocation("forge", "ingots/copper"));
    public ExampleMod() {
    }
    @Mod.EventBusSubscriber(bus=Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {
        @SubscribeEvent
        public static void onItemRegistry(final RegistryEvent.Register<Item> blockRegistryEvent) {
            blockRegistryEvent.getRegistry().register(new Item(new Item.Properties().group(ItemGroup.BREWING)).setRegistryName("examplemod:copper"));
            blockRegistryEvent.getRegistry().register(new SwordItem(new Tier(),4,1,new Item.Properties().group(ItemGroup.BREWING)).setRegistryName("examplemod:coppersword"));
        }
    }

    public static class Tier implements IItemTier{
        @Override
        public int getMaxUses() {
            return 100;
        }

        @Override
        public float getEfficiency() {
            return 4;
        }

        @Override
        public float getAttackDamage() {
            return 2;
        }

        @Override
        public int getHarvestLevel() {
            return 1;
        }

        @Override
        public int getEnchantability() {
            return 50;
        }

        @Override
        public Ingredient getRepairMaterial() {
            return Ingredient.fromTag(coppertag);
        }

        public Tier() {
        }
    }
}

 but i think the problem is that you need


public static final Tag<Item> COPPER_INGOT = new ItemTags.Wrapper(new ResourceLocation("forge", "ingots/copper"));

not


public static final Tag<Item> COPPER_INGOT = ItemTags.getCollection().getOrCreate(new ResourceLocation("forge", "ingots/copper"));

 

otherwise your copper.json is in a wrong directory

It finally works! Thank you very much.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.