Jump to content

Finding Item Entity in World


OfficialPiAddict

Recommended Posts

Hi Everyone, this is my first mod for minecraft so I am still learning, thus any help would be greatly appreciated. I am trying to have an item set the blocks underneath or around it on fire when it is dropped on the ground, but I am not sure how I should go about this. My initial thought was to find the entity in the world and then use its world coordinates and SetBlock() to accomplish this. However I couldn't find a way to find the entity in the world.

 

Is this the best way to go about this? And if so, how would I go about finding the entity in the world.

 

All replies would be greatly appreciated.

 

Thanks, OfficialPiAddict.

Link to comment
Share on other sites

Override

Item#onEntityItemUpdate

. This is called once per tick by every

EntityItem

containing an

ItemStack

of your

Item

.

 

In your override of this method, check that the entity is on the ground (its

onGround

field is

true

), the block at the entity's position isn't fire and fire can be placed at the entity's position (

Block#canPlaceBlockAt

returned

true

). If this condition is met, set the block at the entity's position to fire.

 

In 1.7.10, use

World#getBlock

and

World#setBlock

to get and set the

Block

at the specified position. Use the

posX

,

posY

and

posZ

fields of

Entity

to get an entity's position and

MathHelper.floor_double

to convert them to integers.

 

In 1.8.x, use

World#getBlockState

and

World#setBlockState

to get and set the

IBlockState

at the specified position. Use

IBlockState#getBlock

to get the state's

Block

. Use the

BlockPos(Entity)

constructor to get an entity's position as a

BlockPos

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

In addition to the above comment, I'd take a look into the flint and steel's code to see how it sets stuff on fire. I believe World has a method like setBlockOnFire, which also plays the sound effect.

Also, if this isn't your own custom item you're working with, you may need to look into event handling, which there are plenty of tutorials for.

catch(Exception e)

{

 

}

Yay, Pokémon exception handling, gotta catch 'em all (and then do nothing with 'em).

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



×
×
  • Create New...

Important Information

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