use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ResultSlotMixin_Inventory method impl$afterTake.
@Inject(method = "onTake", cancellable = true, at = @At("RETURN"))
private void impl$afterTake(final Player thePlayer, final ItemStack stack, final CallbackInfoReturnable<ItemStack> cir) {
if (((LevelBridge) thePlayer.level).bridge$isFake()) {
return;
}
final AbstractContainerMenu container = thePlayer.containerMenu;
final Inventory craftInv = ((Inventory) container).query(QueryTypes.INVENTORY_TYPE.get().of(CraftingInventory.class));
if (!(craftInv instanceof CraftingInventory)) {
SpongeCommon.logger().warn("Detected crafting without a InventoryCrafting!? Crafting Event will not fire.");
return;
}
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
transactor.logCrafting(thePlayer, this.impl$craftedStack, (CraftingInventory) craftInv, this.impl$onTakeRecipe);
this.impl$craftedStack = null;
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Inventory method impl$onHandleSelectTrade.
@Inject(method = "handleSelectTrade", at = @At("RETURN"))
private void impl$onHandleSelectTrade(final ServerboundSelectTradePacket param0, final CallbackInfo ci) {
if (this.player.containerMenu instanceof MerchantMenu) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
transactor.logSelectTrade(this.player, param0.getItem());
// capture
this.player.containerMenu.broadcastChanges();
}
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Inventory method impl$onHandleContainerClose.
@Redirect(method = "handleContainerClose", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;doCloseContainer()V"))
private void impl$onHandleContainerClose(final ServerPlayer player) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
try (final EffectTransactor ignored = transactor.logCloseInventory(player, true)) {
this.player.containerMenu.removed(player);
this.player.containerMenu.broadcastChanges();
}
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ServerPlayerGameModeMixin_Vanilla_Tracker method vanillaTracker$onMineBlock.
// @formatter:on
@Redirect(method = "destroyBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/ItemStack;mineBlock(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;)V"))
public void vanillaTracker$onMineBlock(final ItemStack itemStack, final Level param0, final BlockState param1, final BlockPos param2, final Player param3) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
itemStack.mineBlock(param0, param1, param2, param3);
// Needs to get logged as a sideeffect under the BlockChange
try (final EffectTransactor ignored = context.getTransactor().pushEffect(new ResultingTransactionBySideEffect(InventoryEffect.getInstance()))) {
transactor.logPlayerInventoryChange(this.player, PlayerInventoryTransaction.EventCreator.STANDARD);
this.player.inventoryMenu.broadcastChanges();
}
}
use of org.spongepowered.common.event.tracking.context.transaction.TransactionalCaptureSupplier in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Vanilla method vanilla$onPlaceRecipe.
@SuppressWarnings({ "UnresolvedMixinReference", "unchecked", "rawtypes" })
@Redirect(method = "lambda$handlePlaceRecipe$10", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/RecipeBookMenu;handlePlacement(ZLnet/minecraft/world/item/crafting/Recipe;Lnet/minecraft/server/level/ServerPlayer;)V"))
private void vanilla$onPlaceRecipe(final RecipeBookMenu recipeBookMenu, final boolean shift, final Recipe<?> recipe, final net.minecraft.server.level.ServerPlayer player) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
final Inventory craftInv = ((Inventory) player.containerMenu).query(QueryTypes.INVENTORY_TYPE.get().of(CraftingInventory.class));
if (!(craftInv instanceof CraftingInventory)) {
recipeBookMenu.handlePlacement(shift, recipe, player);
SpongeCommon.logger().warn("Detected crafting without a InventoryCrafting!? Crafting Event will not fire.");
return;
}
try (final EffectTransactor ignored = transactor.logPlaceRecipe(shift, recipe, player, (CraftingInventory) craftInv)) {
recipeBookMenu.handlePlacement(shift, recipe, player);
player.containerMenu.broadcastChanges();
}
}
Aggregations