Jump to content

Recommended Posts

Posted

Hi

 

I asked this question before for 1.12.2 but didn't really understand the answer, and in 1.13.2 I can't get the same thing I managed to do myself in my other 1.12.2 mod.

I made a Base class for adding a material item (copper, tin, silver, etc) used for crafting and stuff. Due to the similarities of the items, I feel like there should be a generic way of going from the same model file and then tint it in a different colour similar to how Minecraft can dye Leather Armour.

 

In my 1.12.2 code, I managed to have my items from a list be applied with the same model file but couldn't figure out the colour handler:

Spoiler

@Mod.EventBusSubscriber
public class ClientProxy extends CommonProxy {

    @SubscribeEvent
    public static void registerItemModel(ModelRegistryEvent event) {
        //registerItemModel();
        /*for (int i = 0; i< intercraftcore.ITEMS_INGOTS.length; i++) {
            registerItemModel(intercraftcore.ITEMS_INGOTS[i],"ingot");
        }
        for (int i = 0; i< intercraftcore.ITEMS_DUSTS.length; i++) {
            registerItemModel(intercraftcore.ITEMS_DUSTS[i],"dust");
        }
        for (int i = 0; i< intercraftcore.ITEMS_NUGGETS.length; i++) {
            registerItemModel(intercraftcore.ITEMS_NUGGETS[i],"nugget");
        }*/
        for (int j = 0; j< EnumIngotHandler.IngotTypes.values().length; j++) {
            registerItemModelMeta(intercraftcore.INGOT,j, "ingot");
        }
        for (int j = 0; j< EnumNuggetHandler.NuggetTypes.values().length; j++) {
            registerItemModelMeta(intercraftcore.NUGGET,j, "nugget");
        }
        for (int j = 0; j< EnumDustHandler.DustTypes.values().length; j++) {
            registerItemModelMeta(intercraftcore.DUST,j, "dust");
        }
        for (int j = 0; j< EnumDustSmallHandler.DustSmallTypes.values().length; j++) {
            registerItemModelMeta(intercraftcore.DUSTSMALL,j, "dustsmall");
        }
    }



    //Render BLOCKS and Items.
    /*protected static void registerModel(Block block) {
        ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(Reference.MODID + ":" + block.getUnlocalizedName().substring(5)));
    }*/
    protected static void registerItemModel(Item item,String type) {
        ModelLoader.setCustomModelResourceLocation(item,0,new ModelResourceLocation(Reference.MODID+":"+type,"inventory"));
    }
    protected static void registerItemModelMeta(Item item,int meta,String type) {
        ModelLoader.setCustomModelResourceLocation(item,meta,new ModelResourceLocation(Reference.MODID+":"+type,"inventory"));
    }


    @SubscribeEvent
    public void itemColorHandlers(ColorHandlerEvent.Item event) {
        ItemColors colors = event.getItemColors();
        //colors.registerItemColorHandler(ColorHandler.ColorTypes.GREEN,intercraftcore.INGOT);
        //colors.registerItemColorHandler();
        //colors.registerItemColorHandler(new IItemColor(intercraftcore.INGOT,111111),intercraftcore.INGOT);

    }
}

 

 

 

Here is the code for my base class:

Spoiler

@Mod.EventBusSubscriber(modid = Reference.MODID,bus = Mod.EventBusSubscriber.Bus.MOD)
public class ElementBase extends Item {

    public ElementBase(String name, String oredict, int tint) {
        super(new Item.Properties().group(ItemGroup.REDSTONE));

        ResourceLocation resourceLocation = new ResourceLocation(Reference.MODID,"models/item/ingot.json");

        setRegistryName(name);
        //ModelLoader.defaultModelGetter().apply(resourceLocation);

    }
}

 

 

 

 

The commented out line of code in the base class is an attempt to set it a fixed model file and eventually apply the tint to the texture for that item from the "tint" variable.

 

Usage:

Spoiler

public class Copper extends ElementBase {

    public Copper() {

        super("cu","copper",0xffb732);
    }
}

 

 

 

Posted

AFAIK using ItemColors should work.

 

1)

24 minutes ago, Simon_kungen said:

@Mod.EventBusSubscriber public class ClientProxy

A common event subscriber on a client-Only class. This won’t work. Event subscribers force load classes (even if they are annotated with sideonly/onlyin) whose value (sides) in the annotation match the current side.

2)

26 minutes ago, Simon_kungen said:

public class ClientProxy extends CommonProxy {

CommonProxy. In 2019. Why.

3)

27 minutes ago, Simon_kungen said:

Proxy

A proxy to register stuff. Why. You have event subscribers and registry events.

4)

28 minutes ago, Simon_kungen said:

@SubscribeEvent public static void registerItemModel(ModelRegistryEvent event) {

This will crash on the server because of #1

5)

31 minutes ago, Simon_kungen said:

@Mod.EventBusSubscriber(modid = Reference.MODID,bus = Mod.EventBusSubscriber.Bus.MOD)

Making your item an event subscriber is very likely not what you want

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
2 minutes ago, Cadiboo said:

AFAIK using ItemColors should work.

 

1)

A common event subscriber on a client-Only class. This won’t work. Event subscribers force load classes (even if they are annotated with sideonly/onlyin) whose value (sides) in the annotation match the current side.

2)

CommonProxy. In 2019. Why.

3)

A proxy to register stuff. Why. You have event subscribers and registry events.

4)

This will crash on the server because of #1

5)

Making your item an event subscriber is very likely not what you want

Ok, removed

@Mod.EventBusSubscriber(modid = Reference.MODID,bus = Mod.EventBusSubscriber.Bus.MOD)

from the code. This mod for 1.13.2 doesn't use CommonProxy and ClientProxy classes anymore. But how would I apply multiple items with a single model file?

Posted

I don’t think it’s possible easily in 1.13. You can use the property override system that the bow uses for its textures, but IIRC that’s about it. Draco18s will likely know more about the internals of the item model system and how it works but I’m not sure if they’ve looked into 1.13 yet. You may need to use the dreaded ItemModelMesher if it still exists in 1.13

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
5 hours ago, Simon_kungen said:

public class Copper extends ElementBase

You don't need this. You can get the same effect by calling new ElementBase("cu","copper",0xffb732); instead of new Copper();  A class that does fuckall does not need to exist. There's no class for Sticks or for Iron Ingots.

 

4 hours ago, Cadiboo said:

Draco18s will likely know more about the internals of the item model system and how it works but I’m not sure if they’ve looked into 1.13 yet.

I haven't.

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.

Posted
52 minutes ago, Draco18s said:

You don't need this. You can get the same effect by calling new ElementBase("cu","copper",0xffb732); instead of new Copper();  A class that does fuckall does not need to exist. There's no class for Sticks or for Iron Ingots.

 

I haven't.

Hmm, ok. Might have to ask around in that case. And thanks for the tip.

Posted

The main thing I wanted to keep common among these items is the texture, I have made separate item models for each new element but all using the main item texture. So the problem I had last time was to use the IItemColor interface which persists still.

 

This is the class right now with how I think you use it:

public class ElementBase extends Item implements IItemColor {

    protected int tint;

    public ElementBase(String name, String oredict, int tint) {
        super(new Item.Properties().group(ItemGroup.REDSTONE));

        this.tint = tint;
        setRegistryName(name+"_ingot");


    }

    public int getColor(@Nonnull ItemStack itemStack, int tint) {
        return return Color.GREEN.getRGB();
    }
}

 

But I wouldn't ask if I didn't need help. This Github page is what I use in the code but I at least thought this amount of code would do something.

Posted
23 hours ago, Simon_kungen said:

public int getColor(@Nonnull ItemStack itemStack, int tint) {

Does this override anything? It looks like it should but doesn’t have the @Override annotation 

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
1 minute ago, Cadiboo said:

Does this override anything? It looks like it should but doesn’t have the @Override annotation 

I had the override annotation, but nothing happened with or without it.

Posted

https://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why

 

Use it every time you override a method for two benefits. Do it so that you can take advantage of the compiler checking to make sure you actually are overriding a method when you think you are. This way, if you make a common mistake of misspelling a method name or not correctly matching the parameters, you will be warned that you method does not actually override as you think it does. Secondly, it makes your code easier to understand because it is more obvious when methods are overwritten.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted
21 minutes ago, Cadiboo said:

https://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why

 

Use it every time you override a method for two benefits. Do it so that you can take advantage of the compiler checking to make sure you actually are overriding a method when you think you are. This way, if you make a common mistake of misspelling a method name or not correctly matching the parameters, you will be warned that you method does not actually override as you think it does. Secondly, it makes your code easier to understand because it is more obvious when methods are overwritten.

Ok. Cool. But the problem is still there with it still not changing the colour. I am expecting it to change the tint to green in this case:

Spoiler

public class ElementBase extends Item implements IItemColor {

    protected int tint;

  	public ElementBase(String name, String oredict, int tint) {
        super(new Item.Properties().group(IntercraftCore.RESOURCES));

        this.tint = tint;
        setRegistryName(name+"_ingot");


    }

    @Override
    public int getColor(ItemStack itemStack, int tint) {

        return Color.GREEN.getRGB();

    }
}

 

 

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.