Jump to content

[Solved] [1.3.2] Forge 4.1.1.251 Help setting quantityDropped based on Metadata?


Recommended Posts

Posted

Hello everyone. I'm trying to make a simple little mod that adds the normal overworld ores (and a custom one or two) to the nether (I know it's been done, but I'm also trying to learn Java/Forge modding). Most of the ores use a value of 1 in quantityDropped, but for one of my custom ores I want it to drop 1 to 2, and for the "Nether Redstone" I want it to drop 4 to 5. Since metadata isn't one of the parameters of quantityDropped I can't easily use it in a switch statement and all of the other functions using metadata I've looked at either aren't used when the block is being broken or (in the case of idDropped) are called afterward so I can't just put an integer in the class and call it in qunatityDropped. (It seems strange to me that idDropped would be after quantityDropped but when I was getting the metadata from that then mining a redstone I'd get 1 drop and then mining any of my other ores would result in 4 to 5 drops, hinting to me that it's called afterward).

If anyone could either point me to something that has differing drop amounts based on metadata that I can look at, or can otherwise help me out it would be greatly appreciated :)

Thank you.

 

Here is my code (hopefully, I haven't really used many forums so don't know how to use spoiler tags)

NetherOreMod.java

 

  Reveal hidden contents

 

BlockNetherOres.java

 

  Reveal hidden contents

 

ItemBlockNetherOres.java

 

  Reveal hidden contents

 

WorldGeneratorNetherOres.java (you probably don't need this, but just to be thorough)

 

  Reveal hidden contents

 

 

Also, if anyone knows how to change hardness and resistance for different metadata, that would be useful as well. The suggestion on the topic here: http://www.minecraftforum.net/topic/1482075-forgemetadata-hardnessresistance/    doesn't work, but this isn't a huge concern for me right now so I haven't looked too far into it.

Thank you for your help,

Magico13

 

P.S. In the preview the spoiler tags aren't opening. I have everything in code tags inside the spoilers, so not sure if that's an issue. Am going to post anyway and hope it works in the final post, if not I'll try to edit it so it does work.

Posted

How about rather than all that, just use:

 

/**
 * ejects contained items into the world, and notifies neighbours of an update, as appropriate
 */
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
	//Do stuff here :-P
	//then use "world.getBlockMetadata(x, y, z);" to access your metadata :-)
}

(you would put that into your BlockNetherOres.java)

 

And then in there you can code it to manually drop however many you choose. (Although I'm not quite sure why you need to access the metadata to determine the drop amount? :-P)

 

Also, here is the code from "BlockOre.java", which I believe does what you asked...

    /**
     * Returns the quantity of items to drop on block destruction.
     */
    public int quantityDropped(Random par1Random)
    {
        return this.blockID == Block.oreLapis.blockID ? 4 + par1Random.nextInt(5) : 1;
    }

 

Don't worry about the spoiler tags not working, they're a little weird with me too, but they work after awhile :-P

 

 

 

Posted

Thank you Bandayd. I will give that a try tomorrow and let you know how it goes (about to go to bed, class in the morning :/) The code from BlockOre.java is what I was trying to use (semi-successfully) in  my BlockNetherOres.java (and it's just commented out for now since it wasn't functioning correctly for my purpose). The reason I need metadata is that I'm storing the redstone ore which needs to drop 4 to 5 redstone in the same ID as the other ores that need to drop just one block. So I need to know which block is being broken to define the amount of drops correctly (I don't want it dropping 4 to 5 iron, or only one redstone). I'm trying to just use one ID for the whole thing for convenience.

But yeah, I'll try that out since it looks like it's exactly what I needed.

Thanks again!

Magico13

 

Update:

I just (finally) got a chance to test it out and it's working exactly as I need it! Thank you. For anyone else who may come across this in the future with the same problem, I'll post my updated code:

BlockNetherOres.java

 

  Reveal hidden contents

 

As you can see, all I had to do was use breakBlock to get the metadata, then used it in a switch statement under quantityDropped. There may be a better way to do this, but this appears to be fully functional!

Thank you again Bandayd!

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.