Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post process block place event 1.20.1 #86

Merged
merged 7 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,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 @@ -60,6 +62,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 level;
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);
}
}
Loading