Jump to content

Recommended Posts

Posted

I have a block called BlockWeatherDetector. I want it to be harvestable with any tool, including an empty hand, and drop itself when harvested. I thought it would be as simple as calling .setHarvestLevel(null, 0) and setting .getItemDropped() to return the item obtained from the block class, but it's not working. In survival mode, with tile drops turned on, if I break the block without a pickaxe...it doesn't drop anything. Am I doing something wrong?

 

Constructor:

protected BlockWeatherDetector() {
	super(Material.iron);
	this.setCreativeTab(CreativeTabs.tabRedstone).setHardness(0.5F);
	this.setStepSound(Block.soundTypeMetal).setBlockName("weatherDetector");
	this.setBlockTextureName("weatherworks:weather_detector").setHarvestLevel(null, 0);
}

 

getItemDropped:

	@Override
public Item getItemDropped(int metadata, Random rand, int fortuneLevel) {
	Item item=Item.getItemFromBlock(WeatherWorks.weatherDetector);
	System.out.println("Item dropped: "+item);
	return item;
}

 

Intantiation/Registration (in WeatherWorks.java):

public static final BlockWeatherDetector weatherDetector = new BlockWeatherDetector();
// ...skipping irrelevant code...
GameRegistry.registerBlock(weatherDetector, "weather_detector");

 

The console log is never output unless using a pickaxe, so I know getItemDropped() isn't even being called when breaking it with your hand.

 

What am I doing wrong?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

You're calling setHarvestLvl() after the setBlockTextureName() with a dot. Not good. It should be like this:

 

this.setHarvestLvl(CODE);

NOT

this.setBlockTextureName(CODE).setHarvestLvl(CODE);

 

Btw, why do you want material iron? If you want the step sound, you can get it from soundTypeIron in setStepSound(); Material iron sets the harvest lvl to pickaxe..

I might be terribly wrong.. Like really, really wrong. But I'm just trying to help.

Posted

I actually did have it separate; I only chained them up here for shorter code. I'm 100% sure (because I just checked) that those property-setting methods, including setTextureName(), are chainable (they return the instance itself). Either way, even if I split it, it doesn't fix the problem.

 

As for the material, I want iron pickaxes and better to harvest it faster, but I still want it harvestable overall with anything, including a hand. I thought setHarvestLevel() would override that; if not, do I need to use a different material and then override isToolEffective()? If I do that, how can I get the level (wood, gold, iron, diamond, etc.) of the tool, since it looks like that method only takes the type and the metadata?

Whatever Minecraft needs, it is most likely not yet another tool tier.

Posted

I actually did have it separate; I only chained them up here for shorter code. I'm 100% sure (because I just checked) that those property-setting methods, including setTextureName(), are chainable (they return the instance itself). Either way, even if I split it, it doesn't fix the problem.

 

This is correct.  You can chain them, but its not good practice to do it in the constructor.

 

As for the material, I want iron pickaxes and better to harvest it faster, but I still want it harvestable overall with anything, including a hand. I thought setHarvestLevel() would override that; if not, do I need to use a different material and then override isToolEffective()? If I do that, how can I get the level (wood, gold, iron, diamond, etc.) of the tool, since it looks like that method only takes the type and the metadata?

 

For iron picks to harvest it faster all you have to do is nothing.  Iron will automatically be faster than stone, than wood, than by hand.

 

That said, there's three options:

1) Override

getHarvestTool

and return null.  This will say "this block is always harvestable."

2) Override

getDrops

which will let you drop the item, "harvested" or not.

3) Override

getPlayerRelativeBlockHardness

which will let you dictate how long it takes to break.  Note: this will be the hardest method.

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.

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



×
×
  • Create New...

Important Information

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