Jump to content

[SOLVED] [1.16.4] Different ways to spawn a dropped item during an event


TheOGSeabass

Recommended Posts

I've been building some fun blocks to add in game, one of which is a mound which can contain a sword sticking out of it that you can pick up. I've figured out how to add these mounds and work with them, but when the "PlayerInteractEvent.RightClickBlock" event is fired on these mounds, I want them to drop the sword they are holding.

The "FullMound" class I have to register these mounds has an instance variable to store the sword which is given to them, so I can easily call back the sword, but I would like to know of a seamless way to make a dropped item version of these swords drop in-game. I know I can probably add the sword to the list of drops of the "Mound" block, then destroy the block to drop the sword, then update the state of that block before the player sees that the mound block disappeared for a bit. I just want to know if there is any more seamless way to drop an item in-game when an event is called.

This is what I was trying but this doesn't do anything because I think I'm looking in the wrong places for a solution.

The ".getContained()" method shown here gets the Item stored in the mound if that helps.

new ItemEntity(world, blockPos.getX(), blockPos.getY(), blockPos.getZ(),
        mound.getContained().getDefaultInstance());



This may be a server-client thing that I'm too much of a noob to understand, but any help is appreciated!

Edited by TheOGSeabass
Link to comment
Share on other sites

You've only create an instance of ItemEntity, use World#addEntity to add it to the world.
Also it should be done on server side, where iirc the event you are using is client only, you can use onBlockActivate in your block class, otherwise send a packet.

Edited by poopoodice
  • Thanks 1
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.