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



×
×
  • Create New...

Important Information

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