Jump to content

Recommended Posts

Posted

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.

Posted

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.

Posted

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.

Posted

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.

Posted

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.

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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