Jump to content

[1.7.10] BlockItem loosing its metadata when placed


JaredBGreat

Recommended Posts

I've was invited to help out with Minefantasy 2 and started trying to add smaller pieces (since I don't know all AnonymousProduction plan, or apparently talent, or have much experience with things beyond placing existing blocks in the world).  I was trying to add extra version of a decorative block by switching to a meta data version.  But, even though everything looks fine in creative tabs, and the block could be crafted correctly, when placed it always places as metadata 0.  I've read tutorials, and a book, but they leave the impression I've done everything right.  I've also seen this thread on a similar problem: http://www.minecraftforge.net/forum/index.php?topic=29676.0

 

...but it didn't seem to help -- I tried changes ItemBlock to ItemBlockWithMetadata and no change (also looked and found vanilla wool does really use that either, but inherits from ItemBlock).  I've googled and search but so far nothing helpful.

 

The code I have is this:

 

package minefantasy.mf2.block.basic;

import java.util.List;
import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.IIcon;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

/**
* This is suppose to be a generic class for creating blocks with subtypes, but its not working;
* as items they are fine, but placing the block in the world does not work.  Leaving this for 
* not, but its not used.
* 
* @author BlackJar72
*
*/
public class BasicMetadataBlockMF extends BasicBlockMF {
private final String NAME;
private final int NUMBER;
@SideOnly(Side.CLIENT)
private IIcon[] icons;


public BasicMetadataBlockMF(String name, Material material, Class itemBlock, int number)
{
	super(name, material, null);
	NUMBER = number;
	NAME = name;
}


public BasicMetadataBlockMF(String name, Material material, Class itemBlock, int number, Object drop)
{
	super(material);
	NUMBER = number;
	NAME = name;

	GameRegistry.registerBlock(this, itemBlock, NAME);
	setBlockName(NAME);

	if(material == Material.rock)
	{
		this.setHarvestLevel("pickaxe", 0);
	}
	setItemDropped(drop);
	this.setCreativeTab(CreativeTabs.tabBlock);
}

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

@Override
@SideOnly(Side.CLIENT)
public void registerBlockIcons(IIconRegister iReg) {
	icons = new IIcon[NUMBER];		
	for(int i=0; i < NUMBER; i++) {
		icons[i] = iReg.registerIcon("minefantasy2:basic/" + NAME + i);
	}
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(int p1, int meta) {
	return icons[meta];
}


private void setItemDropped(Object item)
    {
	if(item == null) {
		drop = Item.getItemFromBlock(this); 
	} else {
		if(drop instanceof Item)
		{
			drop = item;
		} else if(drop instanceof Block) {
			drop = Item.getItemFromBlock((Block) drop);
		} else {
			// failsafe
			drop = Item.getItemFromBlock(this);
		}
	} 
    }

@Override
public Item getItemDropped(int meta, Random rand, int i)
    {
	return (Item)drop;
    }

@Override
    public int damageDropped(int meta)
    {
        return meta;
    }
}

 

package minefantasy.mf2.block.itemblocks;

import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

/**
* Supposed to be the BlockItem for the BasicMetadataBlockMF for clay wall, which is not working,
* but leaving both for now.
* 
* @author BlackJar72
*
*/

public class ItemClayWall extends ItemBlock {

public ItemClayWall(Block block) {
	super(block);
	setHasSubtypes(true);
	GameRegistry.registerItem(this, block.getUnlocalizedName(), "minefantasy2");
}

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

@Override
public String getUnlocalizedName(ItemStack item) {
	return getUnlocalizedName() + item.getItemDamage();
}
}

 

...and elsewhere...

 

public static Block clayWall  = new BasicMetadataBlockMF("clayWall", Material.wood, ItemClayWall.class, 4).setHardness(1.0F).setResistance(1.0F).setStepSound(Block.soundTypeWood);

 

Does anyone know what I'm doing wrong / what's going wrong?  Any ideas what would make this work?

Developer of Doomlike Dungeons.

Link to comment
Share on other sites

This:

new BasicMetadataBlockMF("clayWall", Material.wood, ItemClayWall.class, 4)

Calls this:

 

	public BasicMetadataBlockMF(String name, Material material, Class itemBlock, int number)
{
	super(name, material, null);
	NUMBER = number;
	NAME = name;
}

 

Notice that the itemblock paramter goes unused.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Well, that was a silly mistake on my part.  Changed that but now I get a crash:

 

Caused by: java.lang.IllegalStateException: Can't free registry slot 198 occupied by net.minecraft.item.ItemBlock@1fadf38
at cpw.mods.fml.common.registry.GameData.freeSlot(GameData.java:926)
at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:832)
at cpw.mods.fml.common.registry.GameData.registerItem(GameData.java:802)
at cpw.mods.fml.common.registry.GameRegistry.registerItem(GameRegistry.java:143)
at minefantasy.mf2.block.itemblocks.ItemClayWall.<init>(ItemClayWall.java:22)
... 49 more

 

...but I'm not trying to register an ID of 198, or any other specific ID.  Shouldn't "GameRegistry.registerItem(this, block.getUnlocalizedName(), "minefantasy2");" (the line reference at the bottom) be finding an appropriate ID?

Developer of Doomlike Dungeons.

Link to comment
Share on other sites

Does each metadata version have its own name when you register it? I see that name will be passed in... but it's been so long since I used 1.7.10.

 

Also, are you calling setHasSubtypes (true) somewhere? My own walls mod had that in the item block constructor.

 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Yes, its right up there, it is registering sub-types.  I think Draco18s may have seen what I'm doing wrong.  But I can't tell because it crashes now -- it looks like Forge is trying to claim a vanilla ID when I call GameRegistry.registerItem -- which now has me more confused, why would it do that?

 

EDIT:  I thought the crash might be caused by the items being static and defined where declared, so that init hasn't actually run yet.  But moving the definition around only changes the ID it tries to steal, it doesn't fix the problem.

 

EDIT2:  Reading further up the stacktrace reveals that the crash is caused by trying to register in the game registry from inside the contructor (I think).  Apparently I need to change the registration to include the class of the ItemBlock to make it work, but I can't for the life of me find where AP is registering the blocks (though they clearly seem to be registered) -- I'll just have to ask him, maybe he doesn't even want something like this.  Thanks for the help.

Developer of Doomlike Dungeons.

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

    • I cant craft any of the epic fight mod weapons. I try using the recipes in the crafting table but nothing is working. and when i click on the epic fight weapon in jei there is no recipe at all.
    • Oklahoma Nation Cowboys at Youngstown Country PenguinsYoungstown, Ohio; Wednesday, 7 p.m. EDTBOTTOM LINE: The Youngstown Region Penguins facial area the Oklahoma Country Cowboys within the Countrywide Invitation Penguins include absent 15-5 versus Horizon League rivals, with a 9-4 history within non-meeting participate in. Youngstown Region is 1-2 inside online games resolved as a result of considerably less than 4 facts. The Cowboys are 8-10 in just Massive 12 engage in. Oklahoma Region ranks 9th within just the Large 12 taking pictures 31.1% towards 3-stage wide PERFORMERS: Dwayne Cohill is averaging 17.8 details and 4.8 helps for the Penguins. Adrian Nelson is averaging 17.1 info higher than the remaining 10 game titles for Youngstown Thompson is averaging 11.7 details for the Cowboys. Caleb Asberry is averaging 13.1 facts about the very last 10 video games for Oklahoma last 10 Video games: Penguins: 7-3 Zeke Zaragoza Jersey, averaging 79.7 info, 33.4 rebounds, 14.8 helps, 5.3 steals and 2.7 blocks for each video game despite the fact that capturing 48.1% versus the marketplace. Their rivals incorporate averaged 72.4 details for every : 4-6, averaging 66.4 specifics, 33.1 rebounds, 11.1 helps Jake Henry Jersey, 4.9 steals and 3.6 blocks for each sport even though taking pictures 41.3% towards the sector. Their rivals consist of averaged 72.0 info. The made this tale making use of technological innovation delivered by means of Information and facts Skrive and info against Sportradar. Cowboys Shop
    • Oklahoma Nation Cowboys at Youngstown Country PenguinsYoungstown, Ohio; Wednesday, 7 p.m. EDTBOTTOM LINE: The Youngstown Region Penguins facial area the Oklahoma Country Cowboys within the Countrywide Invitation Penguins include absent 15-5 versus Horizon League rivals, with a 9-4 history within non-meeting participate in. Youngstown Region is 1-2 inside online games resolved as a result of considerably less than 4 facts. The Cowboys are 8-10 in just Massive 12 engage in. Oklahoma Region ranks 9th within just the Large 12 taking pictures 31.1% towards 3-stage wide PERFORMERS: Dwayne Cohill is averaging 17.8 details and 4.8 helps for the Penguins. Adrian Nelson is averaging 17.1 info higher than the remaining 10 game titles for Youngstown Thompson is averaging 11.7 details for the Cowboys. Caleb Asberry is averaging 13.1 facts about the very last 10 video games for Oklahoma last 10 Video games: Penguins: 7-3 Zeke Zaragoza Jersey, averaging 79.7 info, 33.4 rebounds, 14.8 helps, 5.3 steals and 2.7 blocks for each video game despite the fact that capturing 48.1% versus the marketplace. Their rivals incorporate averaged 72.4 details for every : 4-6, averaging 66.4 specifics, 33.1 rebounds, 11.1 helps Jake Henry Jersey, 4.9 steals and 3.6 blocks for each sport even though taking pictures 41.3% towards the sector. Their rivals consist of averaged 72.0 info. The made this tale making use of technological innovation delivered by means of Information and facts Skrive and info against Sportradar. Cowboys Shop
    • DUTA89 agen slot online terbaik dan sering memberikan kemenangan kepada setiap member yang deposit diatas 50k dengan tidak klaim bonus sepeser pun.   Link daftar : https://heylink.me/DUTA89OFFICIAL/  
    • Hello All! Started a MC Eternal 1.6.2.2 server on Shockbyte hosting. The only other mod I added was betterfarmland v0.0.8BETA. Server is 16GB and Shockbyte wont tell me how many CPU cores i have.  We are having problems now when players log in it seems to crash the server. At other times it seems fine and we can have 3 people playing for hours at a time. Usually always when it does crash it is when someone logs in. Crash Reports Below. To the person who can post the fix I will reward $100 via Paypal.   ---- Minecraft Crash Report ---- // This is a token for 1 free hug. Redeem at your nearest Mojangsta: [~~HUG~~] Time: 2024-09-19 21:04:58 UTC Description: Exception in server tick loop java.lang.StackOverflowError     at net.minecraft.advancements.PlayerAdvancements.hasCompletedChildrenOrSelf(PlayerAdvancements.java:451)     at net.minecraft.advancements.PlayerAdvancements.shouldBeVisible(PlayerAdvancements.java:419)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:385)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:406)     at net.minecraft.advancements.PlayerAdvancements.ensureVisibility(PlayerAdvancements.java:411)     at net.minecraft.advancements.P  
  • Topics

×
×
  • Create New...

Important Information

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