Jump to content

[1.8] Change block model based on damage


JimiIT92

Recommended Posts

I know that the registration could be the problem, but since there is actually no metadata value saved how can i register it properly? Like a normal metadata block (so using a normal ItemBlock class and registering every variant with a different name?)

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Ok, so i've now this

block.setUnlocalizedName(name);
	GameRegistry.registerBlock(block, name);
	ModelBakery.addVariantName(Item.getItemFromBlock(coal_block), 
			BL.MODID + ":" + "coal_block_0", 
			BL.MODID + ":" + "coal_block_1",
			BL.MODID + ":" + "coal_block_2",
			BL.MODID + ":" + "coal_block_3",
			BL.MODID + ":" + "coal_block_4",
			BL.MODID + ":" + "coal_block_5",
			BL.MODID + ":" + "coal_block_6",
			BL.MODID + ":" + "coal_block_7",
			BL.MODID + ":" + "coal_block_8",
			BL.MODID + ":" + "coal_block_9",
			BL.MODID + ":" + "coal_block_10");
	for(int i = 0; i < 11; i++)
		renderItem.getItemModelMesher().register(Item.getItemFromBlock(block), i, new ModelResourceLocation(BL.MODID + ":" + name + "_" + i, "inventory"));

The model file are pretty the same as before (only the block high on each value is changed)

So now if i place a block down it place the last block model registered (the corresponding to the damage value of 10)

 

EDIT: printing this in the getActualState always return 10

System.out.println(state.getValue(DAMAGE));

 

so basically the damage value is never change, even doing this

newState = state.withProperty(DAMAGE, Integer.valueOf(progress.getPartialBlockDamage()));

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Ok, quick discover. If i comment everything in my getActualState method and only do this

state.withProperty(DAMAGE, Integer.valueOf(3));

 

it return the block model for the damage value of 3, wich is correct. So i think that the problem could be in this method

@Override
@SideOnly(Side.CLIENT)
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
	IBlockState newState = null;

	RenderGlobal render = Minecraft.getMinecraft().renderGlobal;

	DestroyBlockProgress progress;

	if(damage != null)
	{
		Map mp;
		try {
			mp = (Map)damage.get(render);
			Iterator it = mp.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry pair = (Map.Entry)it.next();
				progress = (DestroyBlockProgress) pair.getValue();

				if(progress.getPosition().equals(pos))
				{
					newState =  state.withProperty(DAMAGE, Integer.valueOf(progress.getPartialBlockDamage()));
				}
			}
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
	return newState;
}

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Woops xD Ok, changed to this ;)

/**
 * Get the actual Block state of this Block at the given position. This applies properties not visible in the
 * metadata, such as fence connections.
 */
@Override
@SideOnly(Side.CLIENT)
public IBlockState getActualState(IBlockState state, IBlockAccess worldIn, BlockPos pos)
{
	RenderGlobal render = Minecraft.getMinecraft().renderGlobal;

	DestroyBlockProgress progress;

	if(damage != null)
	{
		Map mp;
		try {
			mp = (Map)damage.get(render);
			Iterator it = mp.entrySet().iterator();
			while (it.hasNext()) {
				Map.Entry pair = (Map.Entry)it.next();
				progress = (DestroyBlockProgress) pair.getValue();

				if(progress.getPosition().equals(pos))
				{
					return state.withProperty(DAMAGE, Integer.valueOf(progress.getPartialBlockDamage()));
				}
			}
		} catch (IllegalArgumentException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
	}
	return state;
}

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.

×
×
  • Create New...

Important Information

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