diff --git a/base/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java b/base/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java index f7515566b..924c14913 100644 --- a/base/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java +++ b/base/src/main/java/io/github/fabricators_of_create/porting_lib/event/common/BlockEvents.java @@ -63,7 +63,9 @@ public interface BeforePlace { /** * Invoked after a block is placed, from {@link BlockItem#useOn(UseOnContext)}. Called on both client and server. + * @deprecated Use {@link BlockEvents#POST_PROCESS_PLACE} instead. */ + @Deprecated public static final Event AFTER_PLACE = EventFactory.createArrayBacked(AfterPlace.class, callbacks -> context -> { for (AfterPlace callback : callbacks) callback.afterPlace(context); @@ -73,6 +75,20 @@ public interface AfterPlace { void afterPlace(BlockPlaceContext ctx); } + /** + * Invoked after a block is placed, from the TAIL of {@link BlockItem#place(BlockPlaceContext)}. + * Called on both client and server. + * Provides the block's Position and BlockState as well. + */ + public static final Event POST_PROCESS_PLACE = EventFactory.createArrayBacked(PostProcessPlace.class, callbacks -> (context, blockPos, blockState) -> { + for (PostProcessPlace callback : callbacks) + callback.postProcessPlace(context, blockPos, blockState); + }); + + public interface PostProcessPlace { + void postProcessPlace(BlockPlaceContext ctx, BlockPos blockPos, BlockState blockState); + } + private final LevelAccessor world; private final BlockPos pos; private final BlockState state; diff --git a/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java b/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java index 7bb94241e..21c6ee2ef 100644 --- a/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java +++ b/base/src/main/java/io/github/fabricators_of_create/porting_lib/mixin/common/BlockItemMixin.java @@ -2,8 +2,14 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; + import io.github.fabricators_of_create.porting_lib.event.common.BlockEvents; +import net.minecraft.core.BlockPos; + +import net.minecraft.world.level.block.state.BlockState; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -36,4 +42,9 @@ public abstract class BlockItemMixin implements BlockItemExtensions { BlockEvents.AFTER_PLACE.invoker().afterPlace(new BlockPlaceContext(context)); return placeResult; } + + @Inject(method = "place", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/InteractionResult;sidedSuccess(Z)Lnet/minecraft/world/InteractionResult;")) + private void port_lib$postProcessPlace(BlockPlaceContext context, CallbackInfoReturnable cir, @Local BlockPos blockPos, @Local BlockState blockState) { + BlockEvents.POST_PROCESS_PLACE.invoker().postProcessPlace(context, blockPos, blockState); + } }