Posted September 22, 20205 yr So I want the player to drop 16 blocks of dirt when crouching(yes I know, very funny) but the items just won't spawn. The event definitelly fires. Here's the code. PlayerEntity p = event.getPlayer(); ItemEntity dirt = new ItemEntity(p.world, p.getPosX(), p.getPosY(), p.getPosZ(), new ItemStack(Items.DIRT, 16)); dirt.setLocationAndAngles(p.getPosX(), p.getPosY(), p.getPosZ(), 0.0F, 0.0F); p.world.addEntity(dirt);
September 22, 20205 yr 1 hour ago, Error_Coding said: So I want the player to drop 16 blocks of dirt when crouching(yes I know, very funny) but the items just won't spawn. The event definitelly fires. Here's the code. PlayerEntity p = event.getPlayer(); ItemEntity dirt = new ItemEntity(p.world, p.getPosX(), p.getPosY(), p.getPosZ(), new ItemStack(Items.DIRT, 16)); dirt.setLocationAndAngles(p.getPosX(), p.getPosY(), p.getPosZ(), 0.0F, 0.0F); p.world.addEntity(dirt); I see nothing wrong with the code, could you post more context?
September 22, 20205 yr Author 3 minutes ago, vemerion said: I see nothing wrong with the code, could you post more context? There isn't much more to it but sure, here's the whole class. @Mod.EventBusSubscriber(modid = FirstMod.MOD_ID, bus = Bus.FORGE) public class DropDirtOnCrouchEvent { @SubscribeEvent public static void dropDirtOnCrouchEvent(InputUpdateEvent event) { if(event.getMovementInput().sneaking) { PlayerEntity p = event.getPlayer(); ItemEntity dirt = new ItemEntity(p.world, p.getPosX(), p.getPosY(), p.getPosZ(), new ItemStack(Items.DIRT, 16)); dirt.setLocationAndAngles(p.getPosX(), p.getPosY(), p.getPosZ(), 0.0F, 0.0F); p.world.addEntity(dirt); } } } I'm pretty sure that the error has to be in the code snippet I posted above tho(I tried adding a potion effect to the player to check if the event fires and that worked)
September 22, 20205 yr 1 minute ago, Error_Coding said: There isn't much more to it but sure, here's the whole class. InputUpdateEvent is a client only event, you can not add entities to the world from the client.
September 22, 20205 yr Author 11 minutes ago, vemerion said: InputUpdateEvent is a client only event, you can not add entities to the world from the client. Oh, thanks. Guess I will have to read into packet transfer.
September 22, 20205 yr 6 minutes ago, Error_Coding said: Oh, thanks. Guess I will have to read into packet transfer. You could try to listen to the PlayerTickEvent and use the isSneaking() method on the player. That way you would avoid sending extra packets.
September 22, 20205 yr Just now, Error_Coding said: That works. Thanks, you just saved my day. No problem, glad I could help!
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.