Jump to content

[1.15.2] ItemEntity not added to world


Error_Coding

Recommended Posts

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);

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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)

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.