use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class ServerGamePacketListenerImplMixin_Inventory method impl$onHandlePlayerCommandOpenInventory.
@Redirect(method = "handlePlayerCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/animal/horse/AbstractHorse;openInventory(Lnet/minecraft/world/entity/player/Player;)V"))
private void impl$onHandlePlayerCommandOpenInventory(final AbstractHorse abstractHorse, final Player player) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
try (final EffectTransactor ignored = context.getTransactor().logOpenInventory(player)) {
abstractHorse.openInventory(player);
context.getTransactor().logContainerSet(player);
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class ItemEntityMixin_Inventory method spongeImpl$throwPickupEventForAddItem.
@Redirect(method = "playerTouch", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Inventory;add(Lnet/minecraft/world/item/ItemStack;)Z"))
private boolean spongeImpl$throwPickupEventForAddItem(final Inventory inventory, final ItemStack itemStack, final Player player) {
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
final boolean added;
try (final EffectTransactor ignored = transactor.logPlayerInventoryChangeWithEffect(player, PlayerInventoryTransaction.EventCreator.PICKUP)) {
added = inventory.add(itemStack);
}
if (!TrackingUtil.processBlockCaptures(context)) {
// if PickupEvent was cancelled return false
return false;
}
return added;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class AbstractContainerMenuMixin_Inventory method inventory$wrapDoClickWithTransaction.
@Redirect(method = "clicked", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/AbstractContainerMenu;doClick(IILnet/minecraft/world/inventory/ClickType;Lnet/minecraft/world/entity/player/Player;)Lnet/minecraft/world/item/ItemStack;"))
private ItemStack inventory$wrapDoClickWithTransaction(final AbstractContainerMenu menu, final int slotId, final int dragType, final ClickType clickType, final Player player) {
if (((LevelBridge) player.level).bridge$isFake()) {
return this.shadow$doClick(slotId, dragType, clickType, player);
}
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
final TransactionalCaptureSupplier transactor = context.getTransactor();
try (final EffectTransactor ignored = transactor.logClickContainer(menu, slotId, dragType, clickType, player)) {
this.impl$isClicking = true;
return this.shadow$doClick(slotId, dragType, clickType, player);
} finally {
this.impl$isClicking = false;
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class CraftingMenuMixin_Inventory method beforeSlotChangedCraftingGrid.
// Crafting Preview
@Redirect(method = "slotChangedCraftingGrid", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/inventory/ResultContainer;setItem(ILnet/minecraft/world/item/ItemStack;)V"))
private static void beforeSlotChangedCraftingGrid(final ResultContainer resultContainer, final int slotId, final ItemStack itemStack, final int param0, final Level param1, final Player player, final CraftingContainer craftingContainer, final ResultContainer resultcontainer) {
resultContainer.setItem(slotId, itemStack);
final Inventory inv = ((Inventory) player.containerMenu).query(QueryTypes.INVENTORY_TYPE.get().of(CraftingInventory.class));
if (!(inv instanceof CraftingInventory)) {
SpongeCommon.logger().warn("Detected crafting but Sponge could not get a CraftingInventory for " + player.containerMenu.getClass().getName());
return;
}
final PhaseContext<@NonNull ?> context = PhaseTracker.SERVER.getPhaseContext();
if (!context.isRestoring()) {
final TransactionalCaptureSupplier transactor = context.getTransactor();
transactor.logCraftingPreview((ServerPlayer) player, (CraftingInventory) inv, craftingContainer);
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class SkullBlockEntityMixin method onUpdateProfile.
/**
* @reason Don't block the main thread while attempting to lookup a game profile.
*/
@Redirect(method = "updateOwnerProfile()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/SkullBlockEntity;updateGameprofile(Lcom/mojang/authlib/GameProfile;)Lcom/mojang/authlib/GameProfile;"))
private GameProfile onUpdateProfile(final GameProfile input) {
this.cancelResolveFuture();
if (input == null) {
return null;
}
if (input.isComplete() && input.getProperties().containsKey("textures")) {
return input;
}
final GameProfileManager manager = Sponge.server().gameProfileManager();
CompletableFuture<org.spongepowered.api.profile.GameProfile> future = null;
if (input.getId() != null) {
future = manager.profile(input.getId());
} else if (!StringUtil.isNullOrEmpty(input.getName())) {
future = manager.profile(input.getName());
}
if (future == null) {
return input;
}
future.thenAcceptAsync(profile -> {
this.owner = SpongeGameProfile.toMcProfile(profile);
this.setChanged();
}, SpongeCommon.server());
this.impl$currentProfileFuture = future;
return input;
}
Aggregations