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

    • OLXTOTO - Bandar Togel Online Dan Slot Terbesar Di Indonesia OLXTOTO telah lama dikenal sebagai salah satu bandar online terkemuka di Indonesia, terutama dalam pasar togel dan slot. Dengan reputasi yang solid dan pengalaman bertahun-tahun, OLXTOTO menawarkan platform yang aman dan andal bagi para penggemar perjudian daring. DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI DAFTAR OLXTOTO DISINI Beragam Permainan Togel Sebagai bandar online terbesar di Indonesia, OLXTOTO menawarkan berbagai macam permainan togel. Mulai dari togel Singapura, togel Hongkong, hingga togel Sidney, pemain memiliki banyak pilihan untuk mencoba keberuntungan mereka. Dengan sistem yang transparan dan hasil yang adil, OLXTOTO memastikan bahwa setiap taruhan diproses dengan cepat dan tanpa keadaan. Slot Online Berkualitas Selain togel, OLXTOTO juga menawarkan berbagai permainan slot online yang menarik. Dari slot klasik hingga slot video modern, pemain dapat menemukan berbagai opsi permainan yang sesuai dengan preferensi mereka. Dengan grafis yang memukau dan fitur bonus yang menggiurkan, pengalaman bermain slot di OLXTOTO tidak akan pernah membosankan. Keamanan dan Kepuasan Pelanggan Terjamin Keamanan dan kepuasan pelanggan merupakan prioritas utama di OLXTOTO. Mereka menggunakan teknologi enkripsi terbaru untuk melindungi data pribadi dan keuangan para pemain. Tim dukungan pelanggan yang ramah dan responsif siap membantu pemain dengan setiap pertanyaan atau masalah yang mereka hadapi. Promosi dan Bonus Menarik OLXTOTO sering menawarkan promosi dan bonus menarik kepada para pemainnya. Mulai dari bonus selamat datang hingga bonus deposit, pemain memiliki kesempatan untuk meningkatkan kemenangan mereka dengan memanfaatkan berbagai penawaran yang tersedia. Penutup Dengan reputasi yang solid, beragam permainan berkualitas, dan komitmen terhadap keamanan dan kepuasan pelanggan, OLXTOTO tetap menjadi salah satu pilihan utama bagi para pecinta judi online di Indonesia. Jika Anda mencari pengalaman berjudi yang menyenangkan dan terpercaya, OLXTOTO layak dipertimbangkan.
    • I have been having a problem with minecraft forge. Any version. Everytime I try to launch it it always comes back with error code 1. I have tried launching from curseforge, from the minecraft launcher. I have also tried resetting my computer to see if that would help. It works on my other computer but that one is too old to run it properly. I have tried with and without mods aswell. Fabric works, optifine works, and MultiMC works aswell but i want to use forge. If you can help with this issue please DM on discord my # is Haole_Dawg#6676
    • Add the latest.log (logs-folder) with sites like https://paste.ee/ and paste the link to it here  
    • 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
  • Topics

×
×
  • Create New...

Important Information

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