Jump to content

I need some guidance registering Colors Blocks


American2050

Recommended Posts

So, I was trying to figure this out, but I'm not sure what steps I need to add to the register of my blocks, I know I'm missing something, but not sure what and where.

 

I'm trying to register colored buttons, I do get the buttons to show on inventory (Not render yet I haven't got to that point)

 

I know I'm missing something as all the buttons show with the same name and not an specific meta like the clay blocks do.

 

This is how I'm registering them.

 

 

	//CREATE THE BLOCKS
public static final Block CLAY_BUTTON = new ClayButton("clay_button");

public static final Block CLAY_BUTTON_COLORED = new ClayButtonColored("clay_button_colored");

public static void registerBlocks() {

	registerBlock(CLAY_BUTTON);

	registerBlock(CLAY_BUTTON_COLORED);


}

public static void registerRenders() {

	registerRender(CLAY_BUTTON);

	registerRender(CLAY_BUTTON_COLORED);

}

private static void registerBlock(Block block) {
	GameRegistry.register(block);
	GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName()));
}

private static void registerRender(Block block) {
	ModelResourceLocation modelLocation = new ModelResourceLocation(block.getRegistryName(), "inventory");
	ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), block.getMetaFromState(block.getDefaultState()),  modelLocation);
}

 

 

And this is the Block Class:

 

 

public class ClayButtonColored extends BlockButton
{

public static final PropertyEnum<EnumDyeColor> COLOR = PropertyEnum.<EnumDyeColor>create("color", EnumDyeColor.class);

public ClayButtonColored(String name) {
	super(true);
	this.setUnlocalizedName(ModInfo.MODID + ":" + name);
	this.setRegistryName(name);
	this.setHardness(0.6F);
	this.setSoundType(SoundType.STONE);
	this.setDefaultState(this.blockState.getBaseState().withProperty(COLOR, EnumDyeColor.WHITE).withProperty(FACING, EnumFacing.DOWN).withProperty(POWERED, Boolean.valueOf(false)));
	this.setCreativeTab(ModCreativeTab.MOD_TAB);
}

@Override
protected void playClickSound(EntityPlayer player, World worldIn, BlockPos pos) {
        worldIn.playSound(player, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 0.3F, 0.6F);	
}

@Override
protected void playReleaseSound(World worldIn, BlockPos pos) {
        worldIn.playSound((EntityPlayer)null, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_OFF, SoundCategory.BLOCKS, 0.3F, 0.5F);
}

@Override
public int tickRate(World worldIn)
    {
        return ConfigValues.buttonsTicks;
    }


@Override
    public int damageDropped(IBlockState state)
    {
        return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
    }

@Override
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List<ItemStack> list)
    {
        for (EnumDyeColor enumdyecolor : EnumDyeColor.values())
        {
            list.add(new ItemStack(itemIn, 1, enumdyecolor.getMetadata()));
        }
    }

@Override
    public MapColor getMapColor(IBlockState state)
    {
        return ((EnumDyeColor)state.getValue(COLOR)).getMapColor();
    }

@Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(COLOR, EnumDyeColor.byMetadata(meta));
    }

@Override
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumDyeColor)state.getValue(COLOR)).getMetadata();
    }

@Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {FACING, POWERED, COLOR});
    }
    
}

 

 

Can I have some help on the missing steps?

 

I will for sure need some help with the jsons, but that's later, first I want to know what I'm missing here as I'm not sure why the don't show a meta for each when I look at them in inventory.

Link to comment
Share on other sites

Because there is no meta for your ItemBlock.

So I should create a class for my ItemBlocks and set there the meta for each color?

Yes assuming when you say color you mean it is going to have different Item models. Because you can always you IBlockColor.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

As for now I'm testing with GameRegistry.register(new ItemColored(block, true).setRegistryName(block.getRegistryName()));

 

They each get a meta now.

 

Yes each of them with have a model that will be parent to the vanilla colored clay blocks.

 

I'm gonna start doing some of the jsons so I can tell what else I'm missing so far.

 

What I notice is that even each having its own meta, they all default to "White" when placed, but I'm gonna figure that out later :P

 

Thanks a lot for the help, will let you know how it goes.

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.