TheOGSeabass Posted December 31, 2020 Posted December 31, 2020 (edited) 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 December 31, 2020 by TheOGSeabass Quote
poopoodice Posted December 31, 2020 Posted December 31, 2020 (edited) 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 December 31, 2020 by poopoodice 1 Quote
TheOGSeabass Posted December 31, 2020 Author Posted December 31, 2020 Thanks so much! I'm going to look up some stuff on sending packets because I have super little experience with that but this was super helpful! Quote
poopoodice Posted December 31, 2020 Posted December 31, 2020 (edited) Sorry I just had a look the event is actually triggered on both sides, you just need to check for !World#isRemote for server side then it should be fine. Edited December 31, 2020 by poopoodice 1 Quote
TheOGSeabass Posted December 31, 2020 Author Posted December 31, 2020 Ahh I see, thanks so much for letting me know! I'm gonna try out sending a packet anyways but if anything weird goes on that's really nice to know. 🙂 Quote
Recommended Posts
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.