[Scarpet] Added ability to cancel events (#1497)
* Added ability to cancel events * Made more events cancellable * Added event_priority to __config * Check for string values for performance * Made player_finishes_using_item cancellable * Made player_chooses_recipe cancellable * Made player_swaps_hands cancellable * Made player_message cancellable * Added __on_player_placing_block (#1498) * Added event to docs, keywords, event_test * Added docs for event cancellation
This commit is contained in:
1 parent
4bb4b557e5
commit
24b9c386ec
14 files changed
+243
-99
No files matched your search
@@ -1,11 +1,13 @@
|
||||
package carpet.mixins;
|
||||
|
||||
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;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_PLACES_BLOCK;
|
||||
import static carpet.script.CarpetEventServer.Event.PLAYER_PLACING_BLOCK;
|
||||
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
@@ -25,4 +27,14 @@ public class BlockItem_scarpetEventMixin
|
||||
if (context.getPlayer() instanceof ServerPlayer && PLAYER_PLACES_BLOCK.isNeeded())
|
||||
PLAYER_PLACES_BLOCK.onBlockPlaced((ServerPlayer) context.getPlayer(), context.getClickedPos(), context.getHand(), context.getItemInHand());
|
||||
}
|
||||
|
||||
@Inject(method = "placeBlock", at = @At("HEAD"), cancellable = true)
|
||||
private void beforePlacement(BlockPlaceContext blockPlaceContext, BlockState blockState, CallbackInfoReturnable<Boolean> cir) {
|
||||
if (blockPlaceContext.getPlayer() instanceof ServerPlayer && PLAYER_PLACING_BLOCK.isNeeded()) {
|
||||
if (PLAYER_PLACING_BLOCK.onBlockPlaced((ServerPlayer) blockPlaceContext.getPlayer(), blockPlaceContext.getClickedPos(), blockPlaceContext.getHand(), blockPlaceContext.getItemInHand())) {
|
||||
cir.setReturnValue(false);
|
||||
cir.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user