Jump to content

How to create metadata block?


Minus

Recommended Posts

I've tried code from TheGreyGhost and also some vanilla blocks with meta, but everytime I register them game shows only ID (F3+H). When I look on planks or logs I see ID/meta and when looking on my custom planks I see only ID. I want to create planks just like in game, so separate blockstates files and of course metadata. Please help me. Maybe I miss something importnat, or done something stupid, but not see it...

 

My ClientProxy class for registering blocks

package net.minus.additionalcraft.proxy.client;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minus.additionalcraft.blocks.ACPlanks;

public class ACBlocksClient
{
public static void preInitClient()
{
	Item itemBlockVariants = GameRegistry.findItem("additionalcraft", "planks");

	ModelBakery.addVariantName(itemBlockVariants, "additionalcraft:cherry_planks",
			 "additionalcraft:dev_planks");
}

public static void initClient()
{
	final String modid = "additionalcraft";

	final int DEFAULT_ITEM_SUBTYPE = 0;

	registerInventoryBlock(modid, "aluminum_ore");
	registerInventoryBlock(modid, "ruby_ore");
	registerInventoryBlock(modid, "aluminum_block");
	registerInventoryBlock(modid, "ruby_block");
	registerInventoryBlock(modid, "inverted_lamp_on");
	registerInventoryBlock(modid, "inverted_lamp_off");

	//Registering with metadata

	Item tempMetadataItem;
	ModelResourceLocation itemModelResourceLocation;

	tempMetadataItem = GameRegistry.findItem(modid, "planks");
	itemModelResourceLocation = new ModelResourceLocation("additionalcraft:cherry_planks", "inventory");
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(tempMetadataItem, ACPlanks.EnumType.CHERRY.getMetadata(), itemModelResourceLocation);

	tempMetadataItem = GameRegistry.findItem(modid, "planks");
	itemModelResourceLocation = new ModelResourceLocation("additionalcraft:dev_planks", "inventory");
	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(tempMetadataItem, ACPlanks.EnumType.DEV.getMetadata(), itemModelResourceLocation);
}

 

package net.minus.additionalcraft.proxy.common;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minus.additionalcraft.blocks.*;
import net.minus.additionalcraft.creativetab.ACCreativeTabs;
import net.minus.additionalcraft.items.ACDoorItem;
import net.minus.additionalcraft.items.ACPlanksItem;

also blocks class for commonProxy
public class ACBlocks
{
//Ores
public static Block aluminumOre;
public static Block rubyOre;

//Blocks
public static Block aluminumBlock;
public static Block rubyBlock;

//LAMPS
public static Block invertedRedstoneLamp_On;
public static Block invertedRedstoneLamp_Off;

//DOORS
public static Block glassDoor;

//WOOD
public static Block ACplanks;

public static void preInitCommon()
{
	//Ores
	aluminumOre = new ACOre(Material.rock).setUnlocalizedName("aluminum_ore");
	GameRegistry.registerBlock(aluminumOre, "aluminum_ore");
	rubyOre = new ACOre(Material.rock).setUnlocalizedName("ruby_ore");
	GameRegistry.registerBlock(rubyOre, "ruby_ore");

	//Blocks
	aluminumBlock = new ACBlock(Material.iron).setUnlocalizedName("aluminum_block");
	GameRegistry.registerBlock(aluminumBlock, "aluminum_block");
	rubyBlock = new ACBlock(Material.rock).setUnlocalizedName("ruby_block");
	GameRegistry.registerBlock(rubyBlock, "ruby_block");

	//Mechanics
	invertedRedstoneLamp_On = new InvertedLamp(true).setUnlocalizedName("inverted_lamp_on").setStepSound(Block.soundTypeGlass).setCreativeTab(ACCreativeTabs.tabACBlock);
	GameRegistry.registerBlock(invertedRedstoneLamp_On, "inverted_lamp_on");
	invertedRedstoneLamp_Off = new InvertedLamp(false).setUnlocalizedName("inverted_lamp_off").setStepSound(Block.soundTypeGlass);
	GameRegistry.registerBlock(invertedRedstoneLamp_Off, "inverted_lamp_off");
	glassDoor = new ACDoor(Material.glass).setUnlocalizedName("glass_door").setStepSound(Block.soundTypeGlass).setHardness(3.0F);
	GameRegistry.registerBlock(glassDoor, ACDoorItem.class, "glass_door");

	//Wood
	ACplanks = new ACPlanks().setUnlocalizedName("planks");
	GameRegistry.registerBlock(ACplanks, ACPlanksItem.class, "planks");
}

 

My custom planks class

package net.minus.additionalcraft.blocks;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IStringSerializable;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minus.additionalcraft.creativetab.ACCreativeTabs;

public class ACPlanks extends Block
{
    public static final PropertyEnum VARIANT = PropertyEnum.create("variant", ACPlanks.EnumType.class);
    //private static final String __OBFID = "CL_00002082";

    public ACPlanks()
    {
        super(Material.wood);
        this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, ACPlanks.EnumType.CHERRY));
        this.setCreativeTab(ACCreativeTabs.tabACBlock);
    }

    @Override
    public int damageDropped(IBlockState state)
    {
        return ((ACPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
    }

    @Override
    @SideOnly(Side.CLIENT)
    public void getSubBlocks(Item itemIn, CreativeTabs tab, List list)
    {
        ACPlanks.EnumType[] aenumtype = ACPlanks.EnumType.values();
        int i = aenumtype.length;

        for (int j = 0; j < i; ++j)
        {
            ACPlanks.EnumType enumtype = aenumtype[j];
            list.add(new ItemStack(itemIn, 1, enumtype.getMetadata()));
        }
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        return this.getDefaultState().withProperty(VARIANT, ACPlanks.EnumType.byMetadata(meta));
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return ((ACPlanks.EnumType)state.getValue(VARIANT)).getMetadata();
    }

    @Override
    protected BlockState createBlockState()
    {
        return new BlockState(this, new IProperty[] {VARIANT});
    }

    public static enum EnumType implements IStringSerializable
    {
        CHERRY(0, "cherry"),
        DEV(1, "dev");
        private static final ACPlanks.EnumType[] META_LOOKUP = new ACPlanks.EnumType[values().length];
        private final int meta;
        private final String name;
        private final String unlocalizedName;

        //private static final String __OBFID = "CL_00002081";

        private EnumType(int meta, String name)
        {
            this(meta, name, name);
        }

        private EnumType(int meta, String name, String unlocalizedName)
        {
            this.meta = meta;
            this.name = name;
            this.unlocalizedName = unlocalizedName;
        }

        
        public int getMetadata()
        {
            return this.meta;
        }

        @Override
        public String toString()
        {
            return this.name;
        }

        public static ACPlanks.EnumType byMetadata(int meta)
        {
            if (meta < 0 || meta >= META_LOOKUP.length)
            {
                meta = 0;
            }

            return META_LOOKUP[meta];
        }

        public String getName()
        {
            return this.name;
        }

        public String getUnlocalizedName()
        {
            return this.unlocalizedName;
        }

        static
        {
            ACPlanks.EnumType[] var0 = values();
            int var1 = var0.length;

            for (int var2 = 0; var2 < var1; ++var2)
            {
                ACPlanks.EnumType var3 = var0[var2];
                META_LOOKUP[var3.getMetadata()] = var3;
            }
        }
    }
}

 

And custom planks item

package net.minus.additionalcraft.items;

import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minus.additionalcraft.blocks.ACPlanks;

public class ACPlanksItem extends ItemBlock
{
public ACPlanksItem(Block block)
{
	super(block);
}

@Override
public int getMetadata(int metadata)
{
	return metadata;
}

@Override
public String getUnlocalizedName(ItemStack stack)
{
	ACPlanks.EnumType type = ACPlanks.EnumType.byMetadata(stack.getMetadata());
	return super.getUnlocalizedName() + "." + type.toString();
}
}

 

If you left your code unattended it will grow to one big mess...

Link to comment
Share on other sites

Hi

Some questions

1) Do the subtypes both show up in the creative inventory? (i.e. an item for both cherry and dev)  Or is there only one custom plank?

2) do the items render correctly in your hand or in the inventory?

3) if you place the cherry block, does it look the same as the dev block?

4) are there any relevant error messages in the console?

 

One thing to try (which may not fix it)

add    this.setHasSubtypes(true); to your ACPlanksItem constructor

 

-TGG

 

 

 

 

 

Link to comment
Share on other sites

Thanks Grey. added this.setHasSubtypes(true); and now I see metadata correctly. Also I've looked to models and blockstates to check if there are no problems. Still can't see textures if I place them in the world. In console I found something like that:

[11:38:37] [Client thread/ERROR] [FML]: Exception loading model additionalcraft:models/block/planks with vanilla loader, skipping
java.io.FileNotFoundException: additionalcraft:models/block/planks.json
at net.minecraft.client.resources.FallbackResourceManager.getResource(FallbackResourceManager.java:70) ~[FallbackResourceManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.getResource(SimpleReloadableResourceManager.java:67) ~[simpleReloadableResourceManager.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadModel(ModelBakery.java:260) ~[ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.access$1200(ModelLoader.java:51) ~[ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader$VanillaLoader.loadModel(ModelLoader.java:417) [ModelLoader$VanillaLoader.class:?]
at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:92) [ModelLoaderRegistry.class:?]
at net.minecraftforge.client.model.ModelLoader.loadAnyModel(ModelLoader.java:165) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader.getModel(ModelLoader.java:148) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader$WeightedRandomModel.<init>(ModelLoader.java:320) [ModelLoader$WeightedRandomModel.class:?]
at net.minecraftforge.client.model.ModelLoader.registerVariant(ModelLoader.java:120) [ModelLoader.class:?]
at net.minecraft.client.resources.model.ModelBakery.loadVariants(ModelBakery.java:122) [ModelBakery.class:?]
at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:98) [ModelLoader.class:?]
at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:68) [ModelLoader.class:?]
at net.minecraft.client.resources.model.ModelManager.onResourceManagerReload(ModelManager.java:29) [ModelManager.class:?]
at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:124) [simpleReloadableResourceManager.class:?]
at net.minecraft.client.Minecraft.startGame(Minecraft.java:470) [Minecraft.class:?]
at net.minecraft.client.Minecraft.run(Minecraft.java:325) [Minecraft.class:?]
at net.minecraft.client.main.Main.main(Main.java:117) [Main.class:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_31]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_31]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_31]
at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]
at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]
at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]
at GradleStart.main(GradleStart.java:45) [start/:?]

 

It shows twice, so probably forge tries to load models, but don't see my model names from planks.json. It's like it skip any information about variants and still try to load model for block like normal variant (In planks.json I have only 2 variants - cherry and dev).

If you left your code unattended it will grow to one big mess...

Link to comment
Share on other sites

Hi

 

What is in your blockstates  .json  ?  That should look something like

 

{
    "variants": {
           "colour=red": { "model": "minecraftbyexample:mbe03_block_variants_model_red"},
         "colour=green": { "model": "minecraftbyexample:mbe03_block_variants_model_green" }
    }
}

 

-TGG

Link to comment
Share on other sites

Yeah i found that planks.json was causing my problem. In variant name I used only name of variant (without variant=) and now textures are correctly displayed in world too. Thank you ;)

If you left your code unattended it will grow to one big mess...

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.