Skip to content

Commit

Permalink
Post process block place event 1.19.2 (#85)
Browse files Browse the repository at this point in the history
* The star of the show, MutableContainerItemContext!

* Fix gha complaining

* disable mc-publish on PRs

* during place event

* fix injection point & add deprecation javadoc
  • Loading branch information
IThundxr authored Feb 21, 2024
1 parent fa18644 commit 793a914
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AfterPlace> AFTER_PLACE = EventFactory.createArrayBacked(AfterPlace.class, callbacks -> context -> {
for (AfterPlace callback : callbacks)
callback.afterPlace(context);
Expand All @@ -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<PostProcessPlace> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<InteractionResult> cir, @Local BlockPos blockPos, @Local BlockState blockState) {
BlockEvents.POST_PROCESS_PLACE.invoker().postProcessPlace(context, blockPos, blockState);
}
}

0 comments on commit 793a914

Please sign in to comment.