Jump to content

Recommended Posts

Posted

Hello everyone, I ran into another problem that I am stuck on. For the life of my I can't seem to get blockstates working in such a way that it simulates metadata. I basically have a block and I want 7 variants. Each variant should have a different texture. That is the only difference. I am using custom OBJ models and I have my block working fine. I've read over several "metadata" and blockstates tutorials and have tried everything I can think of over the last 3 days with the same results all the time. I get a crash on the createBlockState method in my block if I try to add any IProperty to the blockstate. The crash happens on game load, before I even get to the menu and while the forge splash screen shows I am on the "constructing mods" phase.

 

So, for example, I can do this with no problems:

 

    @Override
    protected BlockState createBlockState()
    {
    	return new ExtendedBlockState(this, new IProperty[0], new IUnlistedProperty[]{OBJModel.OBJProperty.instance});
    }

 

But if I try adding this to my block class I crash:

 

    public static final PropertyInteger WOOD_TYPE = PropertyInteger.create("woodtype", 0,6);

    @Override
    protected BlockState createBlockState()
    {
    	System.out.println("test");
    	return new ExtendedBlockState(this, new IProperty[]{WOOD_TYPE}, new IUnlistedProperty[]{OBJModel.OBJProperty.instance});
    }
    
    @Override
    public IBlockState getStateFromMeta(int meta)
    {
    	return this.getDefaultState().withProperty(WOOD_TYPE, meta);
    }
    
    @Override
    public int getMetaFromState(IBlockState state)
    {
    	return state.getValue(WOOD_TYPE);
    }

 

I've tried creating my own Enum and using the PropertyEnum class and I've tried creating an IUnlistedProperty and using the Properties.toUnlisted and adding either one to the IUnlistedProperties all the time with a similar crash. I've tried returning just a BlockState with the same results too. I've tried commenting out my getExtendedState method to make sure that wasn't interfereing and I got the same result. The code above I think is the simplest methods to get some meta data values. However, I get the NPE crash.

 

Here is my crash: http://pastebin.com/cMmjDCsB

 

It comes down to this:

Caused by: java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:213)

Which I am totally at a loss for. I've tried everything I can think of and I keep getting this error if I try to add an IProperty. I've even copy pasted the three methods from BlockColored and I got the same exact result.

 

I think I added the relevant data to my .json file, but I am not totally confident on that. Here is my .json:

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
            "wood": "bibliocraft:texture",
            "books": "bibliocraft:texture"
        },
        "custom":
        {
            "flip-v": true
        },
        "model": "bibliocraft:bookcase.obj"

    },
    "variants": {
    
        "normal": [{}],
        "inventory": [{
            "transform": "forge:default-block"
        }],
       
        "woodtype": {
            0: {
                 "textures": {
                    "wood": "minecraft:blocks/planks_oak"
                    }
            },
            1: {
                 "textures": {
                    "wood": "minecraft:blocks/planks_spruce"
                    }
            },
            2: {
                 "textures": {
                    "wood": "minecraft:blocks/planks_birch"
                    }
            },
            3: {
                 "textures": {
                    "wood": "minecraft:blocks/planks_jungle"
                    }
            },
            4: {
             "textures": {
                    "wood": "minecraft:blocks/planks_acacia"
                    }
            },
            5: {
                 "textures": {
                    "wood": "minecraft:blocks/planks_darkoak"
                    }
            },
            6: {
                 "textures": {
                    "wood": "bibliocraft:blocks/frame"
                    }
            }
        }
    }
}

 

 

For further reference, my custom models are loaded in the preInit on the client side like this:

		OBJLoader.instance.addDomain("bibliocraft");
		Item item = Item.getItemFromBlock(BlockBookcase.instance);
		ModelResourceLocation loc = new ModelResourceLocation("bibliocraft:" + BlockBookcase.name, "inventory");
		ModelLoader.setCustomModelResourceLocation(item, 0, loc);

 

 

Does anyone have any idea what is happening or what I can do to fix this? Is there something I am missing perhaps? I just want some simple block variants. I think I posted all the relevant code, but let me know if there is something else.

Posted

Somehow the

IProperty

array you're passing to the

ExtendedBlockState

constructor contains a

null

value, but I can't see how that could happen in your current code since

WOOD_TYPE

is initialised in a static field. If you set a breakpoint on that line, is

WOOD_TYPE

null

? Does the value at index 0 of the array become

null

in the

BlockState

constructor before the exception is thrown?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I just tried the breakpoint and it turns out that yeah, it is null. My property isn't getting initialized before createBlockState() is being called. I checked and it looks like the constructor in my block doesn't seem to get called before the createBlockState() method either. That seems pretty odd, so I tried removing the final from the property and initalizing my WOOD_TYPE inside the createBlockState() method and it worked! Thanks, at least I understand the problem better and have a work around. I don't understand why my WOOD_TYPE isn't getting initialized as a final static type though. 

 

With the metablocks working, the textures on the models still aren't changing. I have my 7 blocks, but the textures are all the same. The only place I've done anything to read the metadata / "woodtype" is in the json file I shared in the OP. Is there something else that must be done? Like is there something I have to put into my .mtl file to allow me to override the default texture or does something have to change in my json file?

 

Thanks.

 

 

Posted

createBlockState

is called from the

Block

constructor.

 

Your blockstates file looks correct, but I've never worked with OBJ models myself. If you use a simple JSON model like

block/cube_all

and set the

all

texture, does it work?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted

I haven't quite figured out vanilla json models yet so I can try loading the cube_all model. I'm still going through the learning curve on much of the 1.8 stuff. I plan to keep experimenting with that. But I did learn that I can just edit or remove the "textures" portion of my json file and it doesn't seem to make any difference. The textures are being loading from the .mtl file that goes with the .obj file. So maybe there is something else I need to do since I am using an obj model.

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Hi here is an update. I was able to fix the code so my mod does not crash Minecraft. Please understand that I am new to modding but I honestly am having a hard time understanding how anyone can get this to work without having extensive programming and debugging experience as well as searching across the Internet, multiple gen AI bots (claude, grok, openai), and examining source code hidden in the gradle directory and in various github repositories. I guess I am wrong because clearly there are thousands of mods so maybe I am just a newbie. Ok, rant over, here is a step by step summary so others can save the 3 days it took me to figure this out.   1. First, I am using forge 54.1.0 and Minecraft 1.21.4 2. I am creating a mod to add a shotgun to Minecraft 3. After creating the mod and compiling it, I installed the .jar file to the proper directory in Minecraft and used 1.21.4-forge-54.1.0 4. The mod immediately crashed with the error: Caused by: java.lang.NullPointerException: Item id not set 5. Using the stack trace, I determined that the Exception was being thrown from the net.minecraft.world.item.Item.Properties class 6. It seems that there are no javadocs for this class, so I used IntelliJ which was able to provide a decompiled version of the class, which I then examined to see the source of the error. Side question: Are there javadocs? 7. This method, specifically, was the culprit: protected String effectiveDescriptionId() {      return this.descriptionId.get(Objects.requireNonNull(this.id, "Item id not set"));  } 8. Now my quest was to determine how to set this.id. Looking at the same source file, I determined there was another method:  public Item.Properties setId(ResourceKey<Item> pId) {             this.id = pId;             return this;   } 9. So now, I need to figure out how to call setId(). This required working backwards a bit. Starting from the constructor, I stubbed out the variable p which is of type Item.Properties public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); Rather than putting this all on one line, I split it up for readability like this: private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); Here is was the missing function, setId(), which takes a type of ResourceKey<Item>. My next problem is that due to the apparent lack of documentation (I tried searching the docs on this site) I could not determine the full import path to ResourceKey. I did some random searching on the Internet and stumbled across a Github repository which gave two clues: import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceLocation; Then I created the rk variable like this: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); And now putting it all together in order: private static ResourceKey<Item> rk = ResourceKey.create(Registries.ITEM, ResourceLocation.parse("modid:shotgunmod")); private static final Item.Properties p = new Item.Properties().useItemDescriptionPrefix().setId(rk); public static final RegistryObject<Item> SHOTGUN = ITEMS.register("shotgun", () -> new ShotgunItem(p)); This compiled and the mod no longer crashes. I still have more to do on it, but hopefully this will save someone hours. I welcome any feedback and if I missed some obvious modding resource or tutorial that has this information. If not, I might suggest we add it somewhere for people trying to write a mod that doesn't crash. Thank you !!!  
    • I will keep adding to this thread with more information in case anyone can help, or at the very least I can keep my troubleshooting organized. I decided to downgrade to 54.1.0 in the hopes that this would fix the issue but it didn't. At least now I am on a "recommended" version. The crash report did confirm my earlier post that the Exception is coming from effectiveDescriptionId(). I'll continue to see if I can find a way to set the ID manually.   Caused by: java.lang.NullPointerException: Item id not set         at java.base/java.util.Objects.requireNonNull(Objects.java:259) ~[?:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item$Properties.effectiveDescriptionId(Item.java:465) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/net.minecraft.world.item.Item.<init>(Item.java:111) ~[forge-1.21.4-54.1.0-client.jar!/:?]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ShotgunItem.<init>(ShotgunItem.java:19) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/com.example.shotgunmod.ModItems.lambda$static$0(ModItems.java:15) ~[shotgunmod-1.0.0.jar!/:1.0.0]         at TRANSFORMER/[email protected]/net.minecraftforge.registries.DeferredRegister$EventDispatcher.lambda$handleEvent      
    • It just randomly stop working after a rebooted my dedicated server PLEASE HELP!   com.google.gson   Failed to start the minecraft server com.google.gson.JsonSyntaxException: Expected a com.google.gson.JsonObject but was com.google.gson.JsonPrimitive; at path $  
    • It was working perfectly fine last night but now I'm getting an exit code -1 with the textbox: The game crashed: rendering overlay Error: net.minecraftforge.fml.ModLoadingException: Supplementaries (supplementaries) encountered an error during the done event phase Here's the crash log: https://pastebin.com/KmesArYS Any help is apricated
    • Link to Crashlog: https://pastebin.com/bKqH9fx2 Trying to set up a custom mod pack, was going smoothly up until recently as the WorldLoader screen, (the one that appears when you select "create new world" in Singleplayer), was clicked to test that it was running fine. Most Recent Few mods added were; - Create (+ its addons) - Immersive Weathering [Forge] I've tried all I could think of since loading up the game worked fine and I've never had this issue before.  Any help is appreciated.  
  • Topics

×
×
  • Create New...

Important Information

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