[Suggestion] Block place event
There is UseBlockCallback, but I'm not sure if that is what I need.
Nevermind, misread this.
~~We already have this. Override Block#onPlaced(). Most modern editors, such as Eclipse or IntelliJ should recommend this using Intellisense.~~
Is this a serious comment?
Keep in mind player Events have to listen for methods in ClientPlayerInteractionManager and ServerPlayerIneractionManager (both seperate to the Fabric API) in their Mixins for hooking in events, and LivingEntites have to listen for methods in ServerPlayerEntity and PlayerEntity (which are also separate to the Fabric API) in their Mixins for hooking in events - and there isn't a method that focuses on the onPlaced method - in fact the onPlaced method is never accessed to any classes accesible to the Fabric API so this is pretty much impossible to implement without a very hacky solution or attempting to modify the Minecraft packages. For now I'd suggest possibly just creating classes that extend Block and use those instead until something like this could be solved.
Keep in mind player Events have to listen for methods in
ClientPlayerInteractionManagerandServerPlayerIneractionManager(both seperate to the Fabric API) in their Mixins for hooking in events, and LivingEntites have to listen for methods inServerPlayerEntityandPlayerEntity(which are also separate to the Fabric API) in their Mixins for hooking in events - and there isn't a method that focuses on theonPlacedmethod - in fact theonPlacedmethod is never accessed to any classes accesible to the Fabric API so this is pretty much impossible to implement without a very hacky solution or attempting to modify the Minecraft packages. For now I'd suggest possibly just creating classes that extendBlockand use those instead until something like this could be solved.
I don't understand why you can't just hook into the interaction manager like you said. What is hacky, and why do we need to modify the packages?
This is a bit old, and I haven't used Fabric in a long while, so I very well could be wrong. Judging by what I said, hooking into the InteractionManager is possible, but they don't have any methods for placing blocks to listen for. This might have changed in later versions. This is where my point of these files being separate from the FabricAPI comes from - you can't just look & modify the code, or at least as far as I know. I don't know what hacky method I used to know I was referencing.
Yeah, looking back on it this doesn't really seem very... possible. Not with the Player's interaction.
ServerPlayerInteractionManager doesn't have any method for placing blocks, and there are not any methods exposed to the Fabric API you can inject into for this. This is how ServerPlayerInteractionManagerMixin works, injecting in code that call the specific fabric events.
For example, onBlockBroken injects into the tryBreakBlock method in the base file (ServerPlayerInteractionManager)
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onBroken(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V"), method = "tryBreakBlock", locals = LocalCapture.CAPTURE_FAILHARD)
Leaving this code in whenever the method is called, which then calls all the methods onto the AFTER event in PlayerBlockBreakEvents:
PlayerBlockBreakEvents.AFTER.invoker().afterBlockBreak(this.world, this.player, pos, state, entity);
This is only possible because the ServerPlayerInteractionManager has the method tryBreakBlock, but it has no other method to do with placing a block, so we can't inject any event code into the class from the mixin at all. The only block-related interaction that is exposed to the Fabric API is interactBlock
I'd recommend trying to create a BlockItem mixin and inject in code for the place method?
I say we find where Block#onPlace or whatever is called, then we go from there. Perhaps I'll do some investigating in a few days.
BlockItem could have something, though.
Potential changes to some mixin toolchain stuff could make it viable to port the neo event. Currently it would be a little jank