Posted March 13, 201411 yr I need to monitor all of the instances of some of the less common vanilla blocks, beds, doors furnaces and the like. Repeatedly scanning for them is not lag friendly, so I was looking for place / remove hooks. I found BlockEvent.BreakEvent but I can't find the matching PlaceEvent. I tried using PlayerInteractEvent's but since these fire before the actual placement figuring out what was placed is awkward, I guess I could stash the coordinates and look them up on the next tick but that seems cumbersome. I looked into replacing the vanilla blocks with ones wrapped with monitoring stuff, but trying to replace vanilla blocks looks like a bad idea. Soooo, what's the correct way of doing this?
March 14, 201411 yr You can use Java Reflection, to solve that issue. There is a method (onBlockPlaced) in vanilla Minecraft classes, (super.onBlockPlaced(***)) is required of course. If you would like to cancel it, you could use Reflection and modify the Block class at runtime.
March 14, 201411 yr Author I wasn't aware that you could make mods like that through the reflection system and I'm not sure what to Google for, what am I looking for? I did find redefineClasses is that the path you are suggesting? And I presume since we're talking about reflection you know no native Forge way of doing this?
March 14, 201411 yr I found BlockEvent.BreakEvent but I can't find the matching PlaceEvent. I tried using PlayerInteractEvent's but since these fire before the actual placement figuring out what was placed is awkward, I guess I could stash the coordinates and look them up on the next tick but that seems cumbersome. There is no PlaceEvent probably because block placing occurs from a lot of places. Player, enderman, piston, falling sand/gravel, dispenser... If you only care about player placed blocks, stashing the coordinates and checking later on is a perfectly valid solution.
March 14, 201411 yr Author By the same logic doesn't block breaking happen from many places? yet it has an event.
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.