Jump to content

Recommended Posts

Posted

im kind of new to forge modding, does anyone know how to get blocks to drop a specific drop when mined with a specific tool, for example say I have a pickaxe named "Smelting Pick" and drops stone when mining stone, iron when mining iron ore, ect. any help is appreciated

Posted

Read aboud Forge Events.

 

Use @SubscribeEvent to setup HarvestDropsEvent.

 

Modify droplist (event.drops) depending on miner's tool (event.harvester).

 

To get the tool you need to access inventory (held item):

event.harvester.inventory.getCurrentItem();

 

Comparing item should be made on Item.class with "==" (items are singletons),e.g:

ItemStack#getItem() == MyMod.mySuperPickaxeInstance

 

Finally, post your code (what you tried) to get more help/tips.

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

So i understand is, but i am unable to pull the block being mined from the event.

 

here is my code for the Event Handler:

 

  Reveal hidden contents

 

Posted

Every event that is an instance of BlockEvent has a BlockPos which stores the coordinates. BlockEvent also has tha IBlockState. You can get the block from an IBlockState by adding .getBlock().

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

Posted
  On 12/12/2015 at 9:47 PM, ovikk said:

Every event that is an instance of BlockEvent has a BlockPos which stores the coordinates. BlockEvent also has tha IBlockState. You can get the block from an IBlockState by adding .getBlock().

 

i was about to see if i could just get the blocks pos., then see what block was in that pos. Thank you very much

Posted
  On 12/12/2015 at 8:03 PM, Ernio said:

Comparing item should be made on Item.class with "==" (items are singletons),e.g:

ItemStack#getItem() == MyMod.mySuperPickaxeInstance

 

It is bad practice to make new ItemStack just to compate items.

Only case in which you could justify it would be compating whole Stacks (their NBT and size/damage).

 

Also, in any case, that (what you did) won't work. "==" is instance comparing. Currently held item will be only ever equal to itself. If you want to compare it to other ItemStack instance you need to use .equals (note: idk if ItemStack uses equals xD).

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted

okay.. so i have my event in a spoiler below, and when mining stone, it still drops cobblestone, and when mining iron ore, it produces the following crash report

any help is greatly appreiciated

 

 

Crash Report:

 

  Reveal hidden contents

 

 

FML log

 

  Reveal hidden contents

 

 

Event code:

 

  Reveal hidden contents

 

Posted

For the third time:

heldItem == new ItemStack(GemItems.redPoweredPick)

does not work. You have to directly compare the [ttItem[/code], not the

ItemStack

.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

i had already fixed item stack thing, and even with the cheaking of the null, the game will crash randomly, (i could be doing something, or not it will still crash)

and it crashes on the first line that contains    player.getHeldItem()    and throws    java.lang.NullPointerException: Exception ticking world

Sorry for all the trouble

 

Code

 

  Reveal hidden contents

 

 

 

crash report

 

  Reveal hidden contents

 

 

 

fml log

 

  Reveal hidden contents

 

Posted

I will send you to documentation (yes, read the comment in BlockEvent$HarvestDropsEvent class). :D

  Quote

1.7.10 is no longer supported by forge, you are on your own.

Posted
  On 12/12/2015 at 11:57 PM, Ernio said:

I will send you to documentation (yes, read the comment in BlockEvent$HarvestDropsEvent class). :D

Thanks, i dont know why that wasnt my first move, i now can see that the error is being thrown for the Player, not the item. Thanks alot, it is all working now.. Except it is still dropping cobblestone, but i feel as if it is my fault, andi  can hanlde it on my own. Thanks again!  :) :)

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.