Posted October 11, 201410 yr 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)
October 11, 201410 yr 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 .
October 11, 201410 yr 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
October 11, 201410 yr 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
October 11, 201410 yr Part of the issue is that onEntityCollidedWithBlock only gets called if the entity physically enters the block's space; for completely solid 1 meter cubes, this is impossible. http://i.imgur.com/NdrFdld.png[/img]
October 11, 201410 yr Author I have an error : error: incomparable types: Entity and Item if(entity == Item.getItemFromBlock(Blocks.obsidian)){ ^
October 11, 201410 yr Author if(entityItem.getEntityItem(entity) == Item.getItemFromBlock(Blocks.obsidian)){ I try this but it don't work
October 11, 201410 yr 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? http://i.imgur.com/NdrFdld.png[/img]
October 11, 201410 yr 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
October 11, 201410 yr 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(); } } } Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
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.