Jump to content

Setting custom blockstate location for block


JamieEdwards

Recommended Posts

Hi guys and girls,

 

Not sure if the title really explains it properly. If you look at my github:

https://github.com/JamieRhys/Comtech

 

and under common/handlers/ModEntityHandler.java, I have the following code:

 

@SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            for(Block block : ModBlocks.BlockMap.values()) {
                event.getRegistry().register(block);

            }
        }
          
public static void registerModel(Item item, int meta) {
            int iend = item.getRegistryName().toString().indexOf("_");
            String finalString = iend != -1 ?
                    item.getRegistryName().toString().substring(0, 8) +
                            item.getRegistryName().toString().substring(8, iend) + "s/"  +
                            item.getRegistryName().toString().substring(8) :
                    "";

            ModelLoader.setCustomModelResourceLocation(
                    item,
                    meta,
                    new ModelResourceLocation(finalString, "inventory")
            );
        }

 

It seems these two do completely different things. At the moment, it seems I have to use two almost identical blockstate and model .json files for the blocks. What I would like, as you can imagine, is to use a single file for both the item and the block. Unfortunately, I'm unable to find out what I need to do in order to achieve this. I really don't want to use two separate files that are identical (or almost).

 

I can do this perfectly fine with the items.

 

Any ideas on how I can solve this? Thanks

 

 

Link to comment
Share on other sites

52 minutes ago, JamieEdwards said:

            String finalString = iend != -1 ?
                    item.getRegistryName().toString().substring(0, 8) +
                            item.getRegistryName().toString().substring(8, iend) + "s/"  +
                            item.getRegistryName().toString().substring(8) :

Wow that's disgusting. Holy hell.

 

item.getRegistryName().toString().substring(0, 8) +
                            item.getRegistryName().toString().substring(8, iend)

Soo...

item.getRegistryName().toString().substring(0, iend)

?

 

Anyway in 1.14 you don't need to register your item models manually any more. They're registered automatically by registry name and you shouldn't be using metadata to differentiate "subtype" items any more.

 

52 minutes ago, JamieEdwards said:

It seems these two do completely different things.

...yes, as evidenced by the fact that they...are different. One tells the game "this block exists" and other says "this item+meta has this model."

Edited by Draco18s

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 comment
Share on other sites

4 minutes ago, diesieben07 said:

Not quite. end index is exclusive, start inclusive.

One ends at 8 (not included) the other starts at 8 (the same value, so it is included). [0,8)+[8,x) is the same as [0,x)

 

If end was inclusive, or start was exclusive, you'd be right (either doubling or excluding) position 8.

Edited by Draco18s

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 comment
Share on other sites

3 hours ago, Draco18s said:

Wow that's disgusting. Holy hell.

 


item.getRegistryName().toString().substring(0, 8) +
                            item.getRegistryName().toString().substring(8, iend)

Soo...


item.getRegistryName().toString().substring(0, iend)

?

 

Anyway in 1.14 you don't need to register your item models manually any more. They're registered automatically by registry name and you shouldn't be using metadata to differentiate "subtype" items any more.

 

...yes, as evidenced by the fact that they...are different. One tells the game "this block exists" and other says "this item+meta has this model."

Thank you for the suggestion, I wasn't going to keep that (and trust me, it looked a whole lot worse prior to posting this xD) 

 

I'm using 1.12 at the moment. Even so, would I be able to sufficiently organise my resources without giving a custom path as you say? 

Link to comment
Share on other sites

6 minutes ago, JamieEdwards said:

would I be able to sufficiently organise my resources without giving a custom path as you say? 

You shouldn't use custom paths. If you want custom paths, I suspect you can bake it into the registry name.

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 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
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.