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

[1.16.4] Can't Set ItemTier Material to Custom


Recommended Posts

Hello! I'm currently trying to set my ItemTier's repair material to be an item that I've added to the game, so that it can be used in an anvil. However, I seem to run into a problem where it fails to add as the registry for the repair item hasn't taken place yet! However, I'm not sure how I could fix this, as I need to register the ToolItems at some point. Here's the code I've written:

 

Repair Material:

public static final RegistryObject<Item> foodariumIngot = ITEMS.register("foodarium_ingot", () -> new Item(new Item.Properties().group(SurvivalExtras2.CreativeGroup)));

Tool Creation:

public static final Item[] foodariumTools = ModToolsArmor.registerTools("foodarium", 2, 777, 8.0F,
        2.5F, 16, -3.05F, ModItems.foodariumIngot.get());

ModToolsArmor.registerTools() function:

public static Item[] registerTools(String materialName, int harvestLevel, int maxUses, float miningSpeed,
                           float attackDamageExtraFromWood, int enchantability, float axeAttackSpeed, Item repairMaterial) {

    Item[] tools = new Item[5];

    ModItemTier itemTier = new ModItemTier(harvestLevel, maxUses, miningSpeed, attackDamageExtraFromWood, enchantability,
            repairMaterial);

    tools[0] = ModItems.ITEMS.register(materialName + "_sword", () ->
            new SwordItem(itemTier, 4, -2.4F, new Item.Properties().group(SurvivalExtras2.CreativeGroup))
            ).get();
    tools[1] = ModItems.ITEMS.register(materialName + "_pickaxe", () ->
            new PickaxeItem(itemTier, 1, -2.8F, new Item.Properties().group(SurvivalExtras2.CreativeGroup))
    ).get();
    tools[2] = ModItems.ITEMS.register(materialName + "_axe", () ->
            new PickaxeItem(itemTier, 5, axeAttackSpeed, new Item.Properties().group(SurvivalExtras2.CreativeGroup))
    ).get();
    tools[3] = ModItems.ITEMS.register(materialName + "_shovel", () ->
            new ShovelItem(itemTier, 1.5F, -3.0F, new Item.Properties().group(SurvivalExtras2.CreativeGroup))
    ).get();
    tools[4] = ModItems.ITEMS.register(materialName + "_shovel", () ->
            new HoeItem(itemTier, -3, 0.0F, new Item.Properties().group(SurvivalExtras2.CreativeGroup))
    ).get();


    return tools;
}

Thank you so much for any help!

EDIT: Crash log: https://pastebin.com/s9N9Qur6

Edited by hammy3502
Link to post
Share on other sites

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to post
Share on other sites

Hello, and thank you for the help so far!

 

It seems in 1.16, LazyLoadBase was moved to LazyValue, but even with that, it sadly still seems to crash.

 

Tool Creation:

public static final Item[] foodariumTools = ModToolsArmor.registerTools("foodarium", 2, 777, 8.0F,
        2.5F, 16, -3.05F, ModItems.foodariumIngot.get());

Start of registerTools (rest of it is the same):

public static Item[] registerTools(String materialName, int harvestLevel, int maxUses, float miningSpeed,
                           float attackDamageExtraFromWood, int enchantability, float axeAttackSpeed, Item repairMaterial) {

    Item[] tools = new Item[5];

    ModItemTier itemTier = new ModItemTier(harvestLevel, maxUses, miningSpeed, attackDamageExtraFromWood, enchantability,
            () -> Ingredient.fromItems(repairMaterial));

Modified ItemTier:

public class ModItemTier implements IItemTier {

    private final int harvestLevel;
    private final int maxUses;
    private final float miningSpeed;
    private final float attackDamageExtraFromWood;
    private final int enchantability;
    private final LazyValue<Ingredient> repairMaterial;

    public ModItemTier(int harvestLevel, int maxUses, float miningSpeed, float attackDamageExtraFromWood, int enchantability, Supplier<Ingredient> repairMaterial) {
        this.harvestLevel = harvestLevel;
        this.maxUses = maxUses;
        this.miningSpeed = miningSpeed;
        this.attackDamageExtraFromWood = attackDamageExtraFromWood;
        this.repairMaterial = new LazyValue<>(repairMaterial);
        this.enchantability = enchantability;

    }

    @Override
    public int getMaxUses() {
        return this.maxUses;
    }

    @Override
    public float getEfficiency() {
        return this.miningSpeed;
    }

    @Override
    public float getAttackDamage() {
        return this.attackDamageExtraFromWood;
    }

    @Override
    public int getHarvestLevel() {
        return this.harvestLevel;
    }

    @Override
    public int getEnchantability() {
        return this.enchantability;
    }

    @Override
    public Ingredient getRepairMaterial() {
        return this.repairMaterial.getValue();
    }
}

New Crash Log (seems to have the same error as before):

https://pastebin.com/PSDVZaDE

 

Thank you again for all the help so far!

Link to post
Share on other sites

You are creating items in a static initializer. You cannot do that. Items must be created and registered during the registry events. I suggest you use DeferredRegister for this purpose.

Then you still have a hard requirement on foodariumIngot being there when you call registerTools, because you just call foodariumIngot.get(). But at this point you have no idea that it is initialized, so you cannot do that. You need to use the supplier (foodariumIngot), not call get immediately.

Link to post
Share on other sites

Hello, and thank you so much for the help! I know it may not be clear from the code above, but the items are currently registered through the DeferredRegister. How would I go about getting the supplier for foodariumIngot? Just passing in the foodariumIngot is a RegistryObject<Item>, but I need a Supplier<Item>. Thank you so much for any help!

Link to post
Share on other sites
3 minutes ago, hammy3502 said:

know it may not be clear from the code above, but the items are currently registered through the DeferredRegister.

That is not possible. You call registerTools from a static initializer and it returns an Item[]. If the items it returns were registered using DeferredRegister, this would crash, because this runs before the registry event.

Link to post
Share on other sites

I've put a quick temporary patch on registerTools to return a boolean, and simply register the items necessary without calling .get(), though the crash still occurs on the repairMaterial, as I'm not sure how to pass in a proper Supplier.

Link to post
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.

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.



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • What I've been trying to do is I have been attempting to implement an item that can create a transparent blue layer around the entire player. I am using Curios' API for this, as the item is meant to be an equippable accessory. There are also other accessories I have implemented to the mod using the API. I have been able to implement everything that handles this rendering with the accessory item, however I've become stuck after running into a specific issue: when the transparent blue layer is active, it will prevent any accessories specifically on the player's arms from rendering. As far as I can tell, this only happens with the accessories on the player's arms (such as the gloves or even Curios' template knuckles item), as accessories rendering on the player's body for some reason render just fine under the transparent layer. Images for better context: I have been at this for quite awhile but haven't able to figure out what is causing this issue, especially since the inconsistency between rendering for body parts has made me even more confused. It could be a Curios issue, but nothing in its accessory layer code exactly stands out as a cause (if it is indeed Curios' fault though it would at least be good to know what the issue is to pass on to the mod dev). The pendant and glove accessories both render with the same RenderType and render buffer, which I duplicated based on the vanilla armor layer's choices for that, as the vanilla armor layer is also immune to the transparency issue on the arm model part: The relevant code for items and renderers can be found below: Pendants: - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/common/item/accessories/pendant/PendantItem.java - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/client/renderer/accessory/model/PendantModel.java Gloves: - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/common/item/accessories/gloves/GlovesItem.java - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/client/renderer/accessory/model/GlovesModel.java Repulsion Shield (the item creating the transparency layer): - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/common/item/accessories/misc/RepulsionShieldItem.java - https://github.com/Gilded-Games/The-Aether/blob/1.16/src/main/java/com/gildedgames/aether/client/renderer/accessory/model/RepulsionShieldModel.java and, if necessary, Curios' Accessory Layer (code not mine, obviously): - https://github.com/TheIllusiveC4/Curios/blob/1.16.x-forge/src/main/java/top/theillusivec4/curios/client/render/CuriosLayer.java Any help would be appreciated, as I've run out of ideas for what could be causing this issue and how I could fix it. I can provide more information if needed.
    • Ok that's fair. But it's still terrible.
    • Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • Ah sorry, you're right. I can refer you to the way Lycanites renders all of their .obj model entities, and best of all it's up to date for 1.16, but it is pretty complicated than just your standard java model. Depending on what you're doing it might not be worth it... https://gitlab.com/Lycanite/LycanitesMobs/-/tree/master/src/main/java/com/lycanitesmobs/client
    • wasn't TEST for item stacks, or tile entities? I know I have to extend an EntityRenderer, but I don't know how to get an obj to render from there
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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