Jump to content

[1.8] [SOLVED] Metadata blocks change to 0 when placed


Ferrettomato

Recommended Posts

I've been attempting to learn how to mod in Minecraft 1.8 using Wuppy29's book on modding in Minecraft 1.7.10. I've consulted the "Updating your mod to 1.8" thread many times, and it's helped me out exceptionally, but I can't figure out what's going wrong this time. I copied the code in the book as best I could, leaving out things like IIcon since they've been replaced by all those .JSON files, but whenever I place one of my metadata blocks, the placed block always becomes metadata 0 (I know it isn't just the textures glitching, thanks to pick block). It isn't anything to do with the .JSON files, I'm fairly sure of that. Can anyone tell me what blatantly obvious fact I'm missing?

 

Files:

 

Mod file

package com.ferret.myfirstmod;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.Item.ToolMaterial;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.DungeonHooks;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameRegistry;

@Mod(modid = MyFirstMod.MODID, version = MyFirstMod.VERSION)
public class MyFirstMod
{
    public static final String MODID = "ferret_myfirstmod";
    public static final String VERSION = "1.0";
    public static Item key;
    public static Item cube;
    public static Item berry;
    public static Item lightpickaxe;
    public static Item lightsword;
    public static Item lightaxe;
    public static Item lightshovel;
    public static Item lighthoe;
    public static Item lightpaxel;
    public static Item lightingot;
    public static Item lighthelmet;
    public static Item lightchestplate;
    public static Item lightleggings;
    public static Item lightboots;
    public static Item death;
    public static Block lightstone;
    ToolMaterial lightalloy = EnumHelper.addToolMaterial("lightalloy", 3, 1000, 11F, 3.5F, 10);
    ArmorMaterial lightarmor = EnumHelper.addArmorMaterial("lightarmor", "lightarmor", 1000, new int[] {3, 7, 6, 3}, 10);
    
    @EventHandler
    public void preInit(FMLPreInitializationEvent event)
    {
    	key = new ItemKey();
    	GameRegistry.registerItem(key, "key");
    	cube = new ItemCube();
    	GameRegistry.registerItem(cube, "cube");
    	berry = new ItemBerry(3, 0.3F, true);
    	GameRegistry.registerItem(berry, "berry");
    	lightpickaxe = new ItemLightPickaxe(lightalloy, "lightpickaxe");
    	GameRegistry.registerItem(lightpickaxe, "lightpickaxe");
    	lightsword = new ItemLightSword(lightalloy, "lightsword");
    	GameRegistry.registerItem(lightsword, "lightsword");
    	lightaxe = new ItemLightAxe(lightalloy, "lightaxe");
    	GameRegistry.registerItem(lightaxe, "lightaxe");
    	lightshovel = new ItemLightShovel(lightalloy, "lightshovel");
    	GameRegistry.registerItem(lightshovel, "lightshovel");
    	lighthoe = new ItemLightHoe(lightalloy, "lighthoe");
    	GameRegistry.registerItem(lighthoe, "lighthoe");
    	lightpaxel = new ItemLightPaxel(lightalloy, "lightpaxel");
    	GameRegistry.registerItem(lightpaxel, "lightpaxel");
    	lightingot = new ItemLightIngot();
    	GameRegistry.registerItem(lightingot, "lightingot");
    	lighthelmet = new ItemLightArmor(lightarmor, 0, 0, "lighthelmet");
    	lightchestplate = new ItemLightArmor(lightarmor, 0, 1, "lightchestplate");
    	lightleggings = new ItemLightArmor(lightarmor, 0, 2, "lightleggings");
    	lightboots = new ItemLightArmor(lightarmor, 0, 3, "lightboots");
    	GameRegistry.registerItem(lighthelmet, "LightHelmet");
    	GameRegistry.registerItem(lightchestplate, "LightChestplate");
    	GameRegistry.registerItem(lightleggings, "LightLeggings");
    	GameRegistry.registerItem(lightboots, "LightBoots");
    	death = new ItemDeath(0, 0.0F, true);
    	GameRegistry.registerItem(death, "death");
    	lightstone = new BlockLightStone();
    	GameRegistry.registerBlock(lightstone, ItemLightStone.class, "lightstone");
    }
    
    @EventHandler
    public void init(FMLInitializationEvent event)
    {
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.key, 0, new ModelResourceLocation("ferret_myfirstmod:greykey", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.key, 1, new ModelResourceLocation("ferret_myfirstmod:redkey", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.key, 2, new ModelResourceLocation("ferret_myfirstmod:greenkey", "inventory"));
    	ModelBakery.addVariantName(key, new String[]{"ferret_myfirstmod:greykey", "ferret_myfirstmod:redkey", "ferret_myfirstmod:greenkey"});
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.cube, 0, new ModelResourceLocation("ferret_myfirstmod:cube", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.berry, 0, new ModelResourceLocation("ferret_myfirstmod:berry", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightpickaxe, 0, new ModelResourceLocation("ferret_myfirstmod:lightpickaxe", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightsword, 0, new ModelResourceLocation("ferret_myfirstmod:lightsword", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightaxe, 0, new ModelResourceLocation("ferret_myfirstmod:lightaxe", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightshovel, 0, new ModelResourceLocation("ferret_myfirstmod:lightshovel", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lighthoe, 0, new ModelResourceLocation("ferret_myfirstmod:lighthoe", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightpaxel, 0, new ModelResourceLocation("ferret_myfirstmod:lightpaxel", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightingot, 0, new ModelResourceLocation("ferret_myfirstmod:lightingot", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lighthelmet, 0, new ModelResourceLocation("ferret_myfirstmod:lighthelmet", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightchestplate, 0, new ModelResourceLocation("ferret_myfirstmod:lightchestplate", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightleggings, 0, new ModelResourceLocation("ferret_myfirstmod:lightleggings", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.lightboots, 0, new ModelResourceLocation("ferret_myfirstmod:lightboots", "inventory"));
    	ModelBakery.addVariantName(lighthelmet, new String[]{"ferret_myfirstmod:lighthelmet", "ferret_myfirstmod:lightchestplate", "ferret_myfirstmod:lightleggings", "ferret_myfirstmod:lightboots"});
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(this.death, 0, new ModelResourceLocation("ferret_myfirstmod:death", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(this.lightstone), 0, new ModelResourceLocation("ferret_myfirstmod:lightstone", "inventory"));
    	Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(this.lightstone), 1, new ModelResourceLocation("ferret_myfirstmod:lightwall", "inventory"));
    	ModelBakery.addVariantName(Item.getItemFromBlock(this.lightstone), new String[]{"ferret_myfirstmod:lightstone", "ferret_myfirstmod:lightwall"});
    	
    	GameRegistry.addSmelting(Blocks.glowstone, new ItemStack(this.lightingot), 0.1F);
    	
        GameRegistry.addRecipe(new ItemStack(this.lightsword),
        		" X ",
        		" X ",
        		" Y ",
        		'X', this.lightingot, 'Y', Items.stick
        );
        
        GameRegistry.addRecipe(new ItemStack(this.lightpickaxe),
        		"XXX",
        		" Y ",
        		" Y ",
        		'X', this.lightingot, 'Y', Items.stick
        );
        
        GameRegistry.addRecipe(new ItemStack(this.lightaxe),
        		" XX",
        		" YX",
        		" Y ",
        		'X', this.lightingot, 'Y', Items.stick
        );
        
        GameRegistry.addRecipe(new ItemStack(this.lightshovel),
        		" X ",
        		" Y ",
        		" Y ",
        		'X', this.lightingot, 'Y', Items.stick
        );
        
        GameRegistry.addRecipe(new ItemStack(this.lighthoe),
        		" XX",
        		" Y ",
        		" Y ",
        		'X', this.lightingot, 'Y', Items.stick
        );
        
        GameRegistry.addRecipe(new ItemStack(this.lightpaxel),
        		"YXZ",
        		'X', this.lightingot, 'Y', this.lightpickaxe, 'Z', this.lightaxe
        );
        
        //Adds a shapeless recipe to combine redstone and red dye to make more red dye
        GameRegistry.addShapelessRecipe(new ItemStack(Items.dye, 2, 1),
        	Items.redstone, new ItemStack(Items.dye, 1, 1)
        );
        //Adds a smelting recipe to turn stone in to stone bricks
        
        GameRegistry.addSmelting(Blocks.stone, new ItemStack(Blocks.stonebrick), 0.1F);
        
        //Adds a recipe to combine a stone sword and flint to create a stone sword enchanted with Sharpness I
        ItemStack enchantedSwordItemStack = new ItemStack(Items.stone_sword);
        enchantedSwordItemStack.addEnchantment(Enchantment.sharpness, 1);
        GameRegistry.addShapelessRecipe(enchantedSwordItemStack,
        		Items.flint, Items.stone_sword
        );
        
        //Removes spiders from the pool of possible dungeon spawner types
        DungeonHooks.removeDungeonMob("Spider");
        
        //Adds blazes to the pool of possible dungeon spawner types
        DungeonHooks.addDungeonMob("Blaze", 100);
        
        //Adds 25-50 cobblestone as a possible item to appear in bonus chests
        ChestGenHooks.addItem(ChestGenHooks.BONUS_CHEST, new WeightedRandomChestContent(new ItemStack(Blocks.cobblestone), 25, 50, 10));
    }
}

 

BlockLightStone

package com.ferret.myfirstmod;

import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class BlockLightStone extends Block
{
String name = "lightstone";

public BlockLightStone()
{
	super(Material.rock);
	setUnlocalizedName(MyFirstMod.MODID + "_" + name);
	setCreativeTab(CreativeTabs.tabBlock);
	setHardness(2.0F);
	setResistance(5F);
	setStepSound(Block.soundTypeStone);
	setHarvestLevel("pickaxe", 2);
}

@SuppressWarnings({"unchecked", "rawtypes"})
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
	for (int i = 0; i < 2; i++)
	{
		par3List.add(new ItemStack(par1, 1, i));
	}
}
}

 

ItemLightStone

package com.ferret.myfirstmod;

import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

public class ItemLightStone extends ItemBlock{

public ItemLightStone(Block block) {
	super(block);
	setHasSubtypes(true);
}

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

@Override
public String getUnlocalizedName(ItemStack itemstack)
{
	String name = "";
	switch(itemstack.getItemDamage())
	{
		case 0:
			name = "ore";
			break;
		case 1:
			name = "wall";
			break;
		default:
			System.out.println("Invalid metadata for Block LightStone");
			name = "broken";
			break;
	}
	return getUnlocalizedName() + "." + name;
}

}

 

Thanks in advance.

Link to comment
Share on other sites

Try as I might, I can't manage to glean the information I need in order to fix my code. I don't have a particularly exceptional understanding of Java, and as a result your explanations and examples seem to be a bit beyond me. I didn't want to ask how to implement Block.getStateFromMeta() and Block.getMetaFromState() in my code, but I don't see any other way. How do I?

Link to comment
Share on other sites

Hi

 

You will need to add properties to your Block, for example like BlockStone's VARIANT

 

public class BlockStone extends Block

{

    public static final PropertyEnum VARIANT = PropertyEnum.create("variant", BlockStone.EnumType.class);

 

the VARIANT is used to keep track of the type of block - so ORE and WALL in your case. 

 

The BlockStone converts metadata to property VARIANT using

    public IBlockState getStateFromMeta(int meta)

    {

        return this.getDefaultState().withProperty(VARIANT, BlockStone.EnumType.byMetadata(meta));

    }

and it converts property VARIANT to metadata using

    public int getMetaFromState(IBlockState state)

    {

        return ((BlockStone.EnumType)state.getValue(VARIANT)).getMetadata();

    }

 

You will have to do the same thing for your ORE and WALL variants.

Alternatively, since you only have two variants - ore and wall - you could just make two separate Blocks - one for ore and one for wall.  That would be much simpler. 

 

-TGG

Link to comment
Share on other sites

I attempted to make the changes you described, but it only resulted in the placed ore blocks no longer being textured (placing walls still places ore). I did add a new EnumType for the BlockLightStone class in addition to the methods you asked me to add. It turned out like this:

package com.ferret.myfirstmod;

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;

public class BlockLightStone extends Block
{
String name = "lightstone";
public static final PropertyEnum VARIANT = PropertyEnum.create("variant", BlockLightStone.EnumType.class);

public BlockLightStone()
{
	super(Material.rock);
	setUnlocalizedName(MyFirstMod.MODID + "_" + name);
	setCreativeTab(CreativeTabs.tabBlock);
	setHardness(2.0F);
	setResistance(5F);
	setStepSound(Block.soundTypeStone);
	setHarvestLevel("pickaxe", 2);
}



@SuppressWarnings({"unchecked", "rawtypes"})
@SideOnly(Side.CLIENT)
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
	for (int i = 0; i < 2; i++)
	{
		par3List.add(new ItemStack(par1, 1, i));
	}
}

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

}

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

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

    public static enum EnumType implements IStringSerializable
    {
        ORE(0, "ore"),
        WALL(1, "wall");
        /** Array of the Block's BlockStates */
        private static final BlockLightStone.EnumType[] META_LOOKUP = new BlockLightStone.EnumType[values().length];
        /** The BlockState's metadata. */
        private final int meta;
        /** The EnumType's name. */
        private final String name;
        private final String unlocalizedName;

        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;
        }

        /**
         * Returns the EnumType's metadata value.
         */
        public int getMetadata()
        {
            return this.meta;
        }

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

        /**
         * Returns an EnumType for the BlockState from a metadata value.
         */
        public static BlockLightStone.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
        {
            BlockLightStone.EnumType[] var0 = values();
            int var1 = var0.length;

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

 

I made no changes to the other classes. Most of the changes made were copied directly from the BlockStone class and modified slightly. What have I done wrong this time? My guess is that I named something incorrectly in the EnumType. I'm sorry to be such a bother, but I can't seem to find any good guides on this subject that are suited for beginners like myself.

 

Yes, ordinarily it would be best to just have two blocks, but for the purpose of learning how to make metadata blocks I'm making it one.

Link to comment
Share on other sites

Yes, see the OP. It is actually called an Item, not an ItemBlock, but that doesn't really make a difference. It's just the naming scheme the book told me to use, but seeing the recent posts, I'll use ItemBlock from now on. It's worth noting that these blocks behave perfectly in the inventory. They're both there, they both have the right names, and they're both textured correctly. The problems don't start until I place them in the world. I'm currently under the impression that ItemLightStone has nothing to do with this, since it's working perfectly.

 

EDIT: Okay, I copied BlockStone's

damageDropped(IBlockState state)

method and now the blocks are being placed as the correct counterparts. But now the problem is the tile textures no longer want to load. Is there some special way of loading tile textures because of this IBlockState stuff?

Link to comment
Share on other sites

I followed the steps in your troubleshooting guide, but I was unable to locate the problem. I receive the following errors when I run the game:

-snip-

 

I compared my JSONs to those in the MinecraftByExample project, and my blockstate JSON was completely wrong. After making the necessary changes, (and being foiled by the absence of a single comma for god knows how long) I got everything to work. Thanks a bunch! I'll make sure to check back on MBE for future issues.

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

    • Hi! I'm following Kaupenjoe's guide and making an entity, and I get a problem where two animations mix into one when my entity walks - idle  anim plays together with walking. As I'm pretty new into coding and modding, I don't know everything about what I do following his guide and I'd like to set up animations in specific way: 1. When entity is doing nothing, idle animation plays; 2. When entity is walking, only walk animation is playing Here's the code for this entity's animations, it only has 2 at the moment. What should I fix here to get the result I need? public final AnimationState idleAnimationState = new AnimationState(); private int idleAnimationTimeout = 0; @Override public void tick() { super.tick(); if(this.level().isClientSide()){ setupAnimationStates(); } } private void setupAnimationStates() { if(this.idleAnimationTimeout <= 0) { this.idleAnimationTimeout = this.random.nextInt(40) + 80; this.idleAnimationState.start(this.tickCount); } else { --this.idleAnimationTimeout; } } @Override protected void updateWalkAnimation(float pPartialTick) { float f; if(this.getPose() == Pose.STANDING) { f = Math.min(pPartialTick * 6F, 1f); } else { f = 0f; } this.walkAnimation.update(f, 0.2f); } Hopefully I got into right forum topic, I'm not very used to forum posting xDD  
    • DAFTAR WSOSLOT88 KLIK DISINI ATAU KETIK GOOGLE >> WSOSLOT88.COM       Slot Freebet Terbaru tanpa deposit dan tanpa syarat telah mengubah paradigma perjudian daring dengan memberikan kesempatan yang luar biasa bagi para pemain untuk menikmati permainan Slot tanpa tekanan finansial atau kendala persyaratan. Ini adalah langkah revolusioner dalam industri perjudian online yang mengutamakan pengalaman pemain. Dengan menawarkan kesempatan untuk mencoba berbagai permainan dan peluang menang tanpa modal, Slot freebet ini menjadi pilihan yang sangat menarik bagi para pecinta Slot di seluruh dunia. Jadi, jangan lewatkan kesempatan emas ini untuk merasakan sensasi keseruan permainan Slot tanpa harus membayar sepeser pun! Keyword terkait : Slot Freebet Slot Freebet Tanpa Deposit Slot Freebet Tanpa Syarat Slot Freebet Terbaru Slot Freebet Gratis Slot Freebet Tanpa Deposit 2024 Slot Freebet Tanpa Deposit Tanpa Syarat 2024 Slot Freebet 15k Tanpa Deposit Tanpa Syarat 2024 Slot Freebet 25k Tanpa Deposit Tanpa Syarat 2024 Slot Freebet 50k Tanpa Deposit Tanpa Syarat
    • Add crash-reports with sites like https://paste.ee/ and paste the link to it here   Delete the session.lock from the worldsave and test it again
    • Maybe it is a specific mod which is not working with this launcher
  • Topics

×
×
  • Create New...

Important Information

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