Posted February 4, 20178 yr Hi, I am currently working on a new idea for a mod, but have gotten a little stumped. I want it to be that when an item is dropped (by a player or machine, such as a dropper) the item would despawn and a mob would spawn in its place. I know this should be simple but I am completely stumped. I have been trying to accomplish this with a ItemTossEvent, which is semi-successful. @SubscribeEvent public void ironNuggetDrop(ItemTossEvent e){ World world = e.getEntity().world; Item item = e.getEntityItem().getEntityItem().getItem(); BlockPos pos = e.getEntityItem().getPosition(); if(!world.isRemote){ if(item == Items.APPLE){ spawnSkelly(world, pos); e.getEntityItem().isDead = true; } }else{ e.getPlayer().sendMessage(new TextComponentString("it works, you dropped it")); } } private void spawnSkelly(World worldIn, BlockPos pos){ EntitySkeleton skelly = new EntitySkeleton (worldIn); skelly.setPosition(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5); worldIn.spawnEntity(skelly); } There is a couple of issues however: 1) The item immediately despawns, so you do not even see it. Which I want it to be there for like a second if possible. 2) It does not work with droppers and such. 3) The mobs are spawning in random orientation instead of where the item lands, which is what I wanted. So I went into another option which is to create a custom EntityThrowable. This kind of works, except I could not get a custom particle to work so it still shows nothing and a mob just spawns. And it also does not work with droppers. Any help would be greatly appreciated Thanks OC
February 4, 20178 yr Author 1 minute ago, diesieben07 said: Use EntityItem:.setInfinitePickupDelay to prevent the item from being picked up and set the lifespan field to the amount of ticks you want the item to exist for. Note that this will not prevent droppers and such from picking up the item. If you want to prevent that, you have to spawn a fake entity that only looks like an item in it's place. Use EntityJoinWorldEvent instead of ItemTossEvent. Not sure what you mean. You say they spawn in a random orientation, but then say at which position you wanted them to spawn (kinda like "my car is green, but I wanted it to have a spoiler"). Please clarify. Quite right, I want them to spawn at the point where the Item hits, on top of said block. So when you toss the item the mob spawns where it lands. At the moment they spawn behind the player. Sorry should have been more specific Thanks OC
February 4, 20178 yr Author 3 minutes ago, diesieben07 said: Ah, I see what's going on. Well, you will have to wait until the item stops moving then. This means you must create a custom entity for it and replace all items that you want to behave this way using EntityJoinWorldEvent. Ahh ok thank you, I will give this a go and come back if I fail lol! Thanks so much for the help OC
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.