Jump to content

[1.11.2] Forge's blockstates with subBlocks


Erfurt

Recommended Posts

Hey guys,

 

I was wondering if there's an easy way to use forge's blockstates with subBlocks? Would it work the same as for regular blocks, meaning I don't need to make a .json file for the models.block and the models.item?

What I mean is, like the way you can use it with a PropertyBool. Example below.

{
    "forge_marker": 1,
    "defaults": {
        "textures": {
            "all": "#texture"
        }
    },
    "variants": {
        "normal"    : { "model": "#model", "uvlock": true                          },
        "#bool"     : { 
            "true"  : { "model": "#model", "uvlock": true, "submodel": "#subModel" },
            "false" : { "model": "#model", "uvlock": true                          },
        }
    }
}

 

I'm using a PropertyEnum to add my subBlocks, and I call it type. So in my mind it should be something like this.

{
    "forge_marker": 1,
    "defaults": {
        "particle": "#all",
        "model": "#model",
        "uvlock": true
    },
    "variants": {
        "type"  : { 
            "#enumName1" : { "textures": { "all": "#texture" } },
            "#enumName2" : { "textures": { "all": "#texture" } }
        }
    }
}

 

Also if I have both in my class, wouldn't it be something like this?

{
    "forge_marker": 1,
    "defaults": {
        "particle": "#all"
    },
    "variants": {
        "type"  : { 
            "#enumName1" : { "textures": { "all": "#texture" } },
            "#enumName2" : { "textures": { "all": "#texture" } }
        },
        "#bool"     : { 
            "true"  : { "model": "#model", "uvlock": true, "submodel": "#subModel" },
            "false" : { "model": "#model", "uvlock": true                          },
        }
    }
}

 

I should mention that at this times, it's only the texture that seems to not be working.

Link to comment
Share on other sites

Those examples look correct.

 

If it's not working for you, post your real code and blockstates file(s) and the FML log.

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.

Link to comment
Share on other sites

21 minutes ago, Choonster said:

Those examples look correct.

 

If it's not working for you, post your real code and blockstates file(s) and the FML log.

Here's all my code.

Spoiler

How I register my renders.


public static void registerRenders()
{
	for(int i = 0; i < DecorationTypes.values().length; i++)
	{
		registerSubRender(BlockRegistry.chimney, i, DecorationTypes.values()[i].getName());
	}
}

public static void registerSubRender(Block block, int meta, String fileName)
{
	Item item = Item.getItemFromBlock(block);
	ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(item.getRegistryName(), "_" + fileName));
}

 

My BlockClass


public class ChimneyBlock extends Block implements IMetaBlockName
{
	public static final PropertyBool SLAB_STAIR = PropertyBool.create("slab_stair");
	public static final PropertyEnum TYPE = PropertyEnum.create("type", DecorationTypes.class);
	
	protected static final double pixel = 1/16D;
	protected static final AxisAlignedBB CHIMNEY_BLOCK_AABB = new AxisAlignedBB(2*pixel, 0.0D, 2*pixel, 14*pixel, 1.0D, 14*pixel);

	public ChimneyBlock()
	{
		super(Material.ROCK);
		setHardness(1.0F);
		setSoundType(SoundType.STONE);
		isToolEffective("pickaxe", getDefaultState());
		setCreativeTab(CreativeTabs.DECORATIONS);
		setDefaultState(blockState.getBaseState().withProperty(SLAB_STAIR, Boolean.valueOf(false)).withProperty(TYPE, DecorationTypes.STONEBRICK));
	}
	
	@Override
	public boolean isOpaqueCube(IBlockState state)
	{
		return false;
	}
	
	@Override
	public boolean isFullCube(IBlockState state)
	{
		return false;
	}

	@Override
	@SideOnly(Side.CLIENT)
	public BlockRenderLayer getBlockLayer()
	{
        return BlockRenderLayer.CUTOUT;
	}

	@Override
	public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
	{
        return CHIMNEY_BLOCK_AABB;
	}
	
	@Override
	@Nullable
	public AxisAlignedBB getCollisionBoundingBox(IBlockState blockState, IBlockAccess worldIn, BlockPos pos)
	{
        return CHIMNEY_BLOCK_AABB;
	}

	@Override
	@SideOnly(Side.CLIENT)
	public void randomDisplayTick(IBlockState stateIn, World worldIn, BlockPos pos, Random rand)
	{
		for (int i = 0; i < 3; ++i)
		{
			double d0 = (double)pos.getX() + rand.nextDouble();
			double d1 = (double)pos.getY() + rand.nextDouble() * 0.5D + 1.0D;
			double d2 = (double)pos.getZ() + rand.nextDouble();
			worldIn.spawnParticle(EnumParticleTypes.SMOKE_LARGE, d0, d1, d2, 0.0D, 0.0D, 0.0D, new int[0]);
		}
	}
	
	@Override
	public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
	{
		IBlockState block_under = world.getBlockState(pos.down());
		if(block_under.getProperties().containsValue(BlockSlab.EnumBlockHalf.BOTTOM) || block_under.getProperties().containsValue(BlockStairs.EnumHalf.BOTTOM))
		{
			state = state.withProperty(SLAB_STAIR, true);
		}
		else
			state = state.withProperty(SLAB_STAIR, false);
        return state;
	}
	
	@Override
	public int getMetaFromState(IBlockState state)
	{
		DecorationTypes type = (DecorationTypes) state.getValue(TYPE);
        return type.getMeta();
	}
	
	@Override
	public IBlockState getStateFromMeta(int meta)
	{
		return this.getDefaultState().withProperty(TYPE, DecorationTypes.values()[meta]);
	}
	
	@Override
	protected BlockStateContainer createBlockState()
	{
		return new BlockStateContainer(this, new IProperty[] {SLAB_STAIR, TYPE});
	}
	
	@Override
	public void getSubBlocks(Item itemIn, CreativeTabs tab, NonNullList<ItemStack> list)
	{
		for(int i = 0; i < DecorationTypes.values().length; i++)
		{
			list.add(new ItemStack(itemIn, 1, i));
		}
	}

	@Override
	public String getSpecialName(ItemStack stack)
	{
		return DecorationTypes.values()[stack.getItemDamage()].getName();
	}
}

 

My enum


public static enum DecorationTypes implements IStringSerializable
{
	STONEBRICK("stonebrick", 0),
	ENDBRICK("endbrick", 1),
	BRICK("brick", 2),
	COBBLESTONE("cobblestone", 3),
	SANDSTONE("sandstone", 4),
	RED_SANDSTONE("red_sandstone", 5);
	
	private int meta;
	private String name;
	
	private DecorationTypes(String name, int meta)
	{
		this.meta = meta;
		this.name = name;
	}
	
	@Override
	public String getName()
	{
		return this.name;
	}
	
	public int getMeta()
	{
		return meta;
	}
	
	@Override
	public String toString()
	{
		return getName();
	}
}

 

My ItemBlockClass


public class ItemSubBlock extends ItemBlock
{
	public ItemSubBlock(Block block)
	{
		super(block);
		if(!(block instanceof IMetaBlockName))
		{
			throw new IllegalArgumentException(String.format("The given Block %s is not an instance of IMetaBlockName!", block.getUnlocalizedName()));
		}
		this.setHasSubtypes(true);
		this.setMaxDamage(0);
	}
	
	@Override
	public String getUnlocalizedName(ItemStack stack)
	{
		return super.getUnlocalizedName() + "." + ((IMetaBlockName) this.block).getSpecialName(stack);
	}
	
	@Override
	public int getMetadata(int damage)
	{
		return damage;
	}
}

 

How I do the registerModelBakery


@Override
public void registerModelBakeryVariants()
{
	ModelBakery.registerItemVariants(Item.getItemFromBlock(BlockRegistry.chimney), new ResourceLocation(Reference.MOD_ID, "chimney_stonebrick"), 
			new ResourceLocation(Reference.MOD_ID, "chimney_endbrick"), 
			new ResourceLocation(Reference.MOD_ID, "chimney_brick"), 
			new ResourceLocation(Reference.MOD_ID, "chimney_cobblestone"), 
			new ResourceLocation(Reference.MOD_ID, "chimney_sandstone"), 
			new ResourceLocation(Reference.MOD_ID, "chimney_red_sandstone"));
}

 

My blockstate file (it's named "chimney.json")


{
    "forge_marker": 1,
    "defaults": {
        "particle" : "#all"
    },
    "variants": {
        "slab_stair"        : { 
            "true"          : { "model": "em:chimney", "uvlock": true, "submodel": "em:chimney_bottom" },
            "false"         : { "model": "em:chimney", "uvlock": true                                  },
        },
        "type"              : {
            "stonebrick"    : { "textures": { "all": "blocks/stonebrick"                             } },
            "endbrick"      : { "textures": { "all": "blocks/endbrick"                               } },
            "brick"         : { "textures": { "all": "blocks/brick"                                  } },
            "cobblestone"   : { "textures": { "all": "blocks/cobblestone"                            } },
            "sandstone"     : { "textures": { "all": "blocks/sandstone_top"                          } },
            "red_sandstone" : { "textures": { "all": "blocks/red_sandstone_top"                      } }
        }
    }
}

 

I personally think it's most likely to be the way I register my renders, or the registerModelBakery, that's the problem, but I don't really know.

Link to comment
Share on other sites

So you want to use the blockstates variants for the item models? The ModelResourceLocation you pass to ModelLoader.setCustomModelResourceLocation needs to have the blockstates file's name as the domain and path (the first constructor argument, which looks correct) and a full variant name as the variant (the second constructor argument, which looks incorrect).

 

An example variant from the chimney.json blockstates file would be "slab_stair=false,type=stonebrick". You're using variants like "_stonebrick", which aren't defined by the blockstates file.

 

The FML log (logs/fml-client-latest.log in the game directory) will usually tell you why a model failed to load, please post it (using Gist/Pastebin) in future.

 

If you're using ModelLoader.setCustomModelResourceLocation, ModelBakery.registerItemVariants is automatically called for you; you don't need to call it yourself.

 

In my mod, I use StateMapperBase#getPropertyString to create a property string (like "slab_stair=false,type=stonebrick") from an IBlockState when registering item models for blocks with variants. You can see how I do this here.

Edited by Choonster

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.

Link to comment
Share on other sites

1 hour ago, Choonster said:

So you want to use the blockstates variants for the item models? The ModelResourceLocation you pass to ModelLoader.setCustomModelResourceLocation needs to have the blockstates file's name as the domain and path (the first constructor argument, which looks correct) and a full variant name as the variant (the second constructor argument, which looks incorrect).

 

An example variant from the chimney.json blockstates file would be "slab_stair=false,type=stonebrick". You're using variants like "_stonebrick", which aren't defined by the blockstates file.

 

The FML log (logs/fml-client-latest.log in the game directory) will usually tell you why a model failed to load, please post it (using Gist/Pastebin) in future.

 

If you're using ModelLoader.setCustomModelResourceLocation, ModelBakery.registerItemVariants is automatically called for you; you don't need to call it yourself.

 

In my mod, I use StateMapperBase#getPropertyString to create a property string (like "slab_stair=false,type=stonebrick") from an IBlockState when registering item models for blocks with variants. You can see how I do this here.

Maybe it's me who's a complete idiot or something, but I don't get it. I have removed the modelBakery stuff, and also removed the ' "_" + ' from the registerRender. Which is what I get was wrong? Still doesn't work. Does my blockstate look correct to you, I want my types to be named "stonebrick" and not "_stonebrick"? Here's the fml-client-latest.log, there's a lot of stuff in my mod atm, so it's a bit long.

 

EDIT: I haven't changed the json file

Edited by Erfurt
Link to comment
Share on other sites

Quote

[18:22:42] [Client thread/ERROR] [FML/]: Exception loading blockstate for the variant em:chimney#slab_stair=true,type=red_sandstone:
java.lang.Exception: Could not load model definition for variant em:chimney
...
Caused by: java.lang.RuntimeException: Encountered an exception when loading model definition of 'em:chimney' from: 'em:blockstates/chimney.json' in resourcepack: 'FMLFileResourcePack:Eadore mod'
...
Caused by: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Expected name at line 10 column 10

 

You have an invalid trailing comma on line 9 of the blockstates file.

 

  • Like 1

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.

Link to comment
Share on other sites

4 minutes ago, Choonster said:

 

You have an invalid trailing comma on line 9 of the blockstates file.

 

 

5 minutes ago, diesieben07 said:

Your JSON is invalid. See the JsonSyntaxExceptions in the log.

I feel like an ass... So stupid of me not noticing that... Everything works now, thanks for your help

Link to comment
Share on other sites

1 hour ago, Choonster said:

 

You have an invalid trailing comma on line 9 of the blockstates file.

 

Actually, not everything is working... The items doesn't work. Do I need to make separate json files for them, or is it possible to get them from the blockstate?

 

Don't know if you'll need this, but here's the newest fml-client-latest.log

Edited by Erfurt
Link to comment
Share on other sites

16 minutes ago, diesieben07 said:

Forge will use the blockstate json for items as well.

This is the way I have to do to make the items work.

{
    "forge_marker": 1,
    "defaults": {
        "particle" : "#all",
        "model": "em:chimney",
        "uvlock": true
    },
    "variants": {
        "slab_stair"        : { 
            "true"          : { "submodel": "em:chimney_bottom"                   },
            "false"         : { }
        },
        "type"              : {
            "stonebrick"    : { "textures": { "all": "blocks/stonebrick"        } },
            "endbrick"      : { "textures": { "all": "blocks/end_bricks"        } },
            "brick"         : { "textures": { "all": "blocks/brick"             } },
            "cobblestone"   : { "textures": { "all": "blocks/cobblestone"       } },
            "sandstone"     : { "textures": { "all": "blocks/sandstone_top"     } },
            "red_sandstone" : { "textures": { "all": "blocks/red_sandstone_top" } }
        },
        "stonebrick"    : { "model": "em:chimney", "uvlock": true, "textures": { "all": "blocks/stonebrick"        } },
        "endbrick"      : { "model": "em:chimney", "uvlock": true, "textures": { "all": "blocks/end_bricks"        } },
        "brick"         : { "model": "em:chimney", "uvlock": true, "textures": { "all": "blocks/brick"             } },
        "cobblestone"   : { "model": "em:chimney", "uvlock": true, "textures": { "all": "blocks/cobblestone"       } },
        "sandstone"     : { "model": "em:chimney", "uvlock": true, "textures": { "all": "blocks/sandstone_top"     } },
        "red_sandstone" : { "model": "em:chimney", "uvlock": true, "textures": { "all": "blocks/red_sandstone_top" } }
    }
}

 

But I would like to know if there's a way to use the "type" part, for the items?

Link to comment
Share on other sites

5 hours ago, Erfurt said:

This is the way I have to do to make the items work.

 

But I would like to know if there's a way to use the "type" part, for the items?

 

Like I said, use a variant that already exists in the blockstates file (e.g. "slab_stair=false,type=stonebrick") as the variant of the ModelResourceLocation you pass to ModelLoader.setCustomModelResourceLocation. You can either create this string with regular string concatenation/formatting or from an IBlockState using StateMapperBase#getPropertyString.

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.

Link to comment
Share on other sites

12 hours ago, Choonster said:

 

Like I said, use a variant that already exists in the blockstates file (e.g. "slab_stair=false,type=stonebrick") as the variant of the ModelResourceLocation you pass to ModelLoader.setCustomModelResourceLocation. You can either create this string with regular string concatenation/formatting or from an IBlockState using StateMapperBase#getPropertyString.

Ahh, got it now :D

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I have no idea how a UI mod crashed a whole world but HUGE props to you man, just saved me +2 months of progress!  
    • So i know for a fact this has been asked before but Render stuff troubles me a little and i didnt find any answer for recent version. I have a custom nausea effect. Currently i add both my nausea effect and the vanilla one for the effect. But the problem is that when I open the inventory, both are listed, while I'd only want mine to show up (both in the inv and on the GUI)   I've arrived to the GameRender (on joined/net/minecraft/client) and also found shaders on client-extra/assets/minecraft/shaders/post and client-extra/assets/minecraft/shaders/program but I'm lost. I understand that its like a regular screen, where I'd render stuff "over" the game depending on data on the server, but If someone could point to the right client and server classes that i can read to see how i can manage this or any tip would be apreciated
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
    • Let me try and help you with love spells, traditional healing, native healing, fortune telling, witchcraft, psychic readings, black magic, voodoo, herbalist healing, or any other service your may desire within the realm of african native healing, the spirits and the ancestors. I am a sangoma and healer. I could help you to connect with the ancestors , interpret dreams, diagnose illness through divination with bones, and help you heal both physical and spiritual illness. We facilitate the deepening of your relationship to the spirit world and the ancestors. Working in partnership with one\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’s ancestors is a gift representing a close link with the spirit realm as a mediator between the worlds.*   Witchdoctors, or sorcerers, are often purveyors of mutis and charms that cause harm to people. we believe that we are here for only one purpose, to heal through love and compassion.*   African people share a common understanding of the importance of ancestors in daily life. When they have lost touch with their ancestors, illness may result or bad luck. Then a traditional healer, or sangoma, is sought out who may prescribe herbs, changes in lifestyle, a career change, or changes in relationships. The client may also be told to perform a ceremony or purification ritual to appease the ancestors.*   Let us solve your problems using powerful African traditional methods. We believe that our ancestors and spirits give us enlightenment, wisdom, divine guidance, enabling us to overcome obstacles holding your life back. Our knowledge has been passed down through centuries, being refined along the way from generation to generation. We believe in the occult, the paranormal, the spirit world, the mystic world.*   The services here are based on the African Tradition Value system/religion,where we believe the ancestors and spirits play a very important role in society. The ancestors and spirits give guidance and counsel in society. They could enable us to see into the future and give solutions to the problems affecting us. We use rituals, divination, spells, chants and prayers to enable us tackle the task before us.*   I have experience in helping and guiding many people from all over the world. My psychic abilities may help you answer and resolve many unanswered questions
  • Topics

×
×
  • Create New...

Important Information

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