Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello , First sorry if i make english mistakes , I'm french

I would like to know if it's possible to execute something when the entity of item obsidian (when you throw it for example) collide the block and "consume" or delete the entity after .

Thank you in advance :)

 

(I have a mod which create a block but i don't think it will help , there is nothing in it  , also i am a noob in modding ^^' it will be super if you could show me the final code , sorry for the disturbance)

  • Author

okay , if i understand i will use this

public void onEntityCollidedWithBlock( World world, int x, int y, int z, Entity entity ) {

and do my event .

 

But i don't understand what to change to execute only if the entity is an item of obsidian .

  • Author

I'm really not an expert ^^' may I have the code please ? I really don't know how to use that and i don't want to use your time

  • Author

public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity){


//when mod collides
if(entity instanceof EntityItem){
world.createExplosion((Entity)null, i, j, k, 4F, true);
}

 

I use an explosion to test , but it don't seems to work . And if i succed to test if the entity is an item , i really don't know how to test it's an obsidian

  • Author

I have an error :

error: incomparable types: Entity and Item

if(entity == Item.getItemFromBlock(Blocks.obsidian)){

          ^

 

  • Author

if(entityItem.getEntityItem(entity) == Item.getItemFromBlock(Blocks.obsidian)){

I try this but it don't work :/

I think you should take a step back and learn more about Java here.

 

entityItem.getEntityItem() returns an ItemStack, which you are comparing to an Item. You have to compare apples to apples, so to speak:

 

if (entityItem.getEntityItem().getItem() == Item.getItemFromBlock(Blocks.obsidian))

 

Also, you are confusing both me and probably yourself by having 'entity' AND 'entityItem' - are they the same? Where are these entities coming from?

  • Author

it's true that i don't know enough , it's y first "big" project , also your condition don't work ^^' it can't find symbol

Method called when entity collides:

public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity){

if entity is an item

if(entity instanceof EntityItem){

if it handles obsidian as item

if(((EntityItem) entity).getEntityItem().getItem() == Item.getItemFromBlock(Blocks.obsidian)){

And now the action. Example:

world.setBlock(i, j, k, Blocks.glass);

And don't forget to remove item:

entity.setDead();

 

Complete code:

public void onEntityCollidedWithBlock(World world, int i, int j, int k, Entity entity){
if(entity instanceof EntityItem){
  if(((EntityItem) entity).getEntityItem().getItem() == Item.getItemFromBlock(Blocks.obsidian)){
   world.setBlock(i, j, k, Blocks.glass);
   entity.setDead();
  }
}
}

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.