use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinContainer method redirectTransferStackInSlot.
@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/Container;transferStackInSlot(Lnet/minecraft/entity/player/EntityPlayer;I)Lnet/minecraft/item/ItemStack;"))
private ItemStack redirectTransferStackInSlot(Container thisContainer, EntityPlayer player, int slotId) {
Slot slot = thisContainer.getSlot(slotId);
if (!(slot instanceof SlotCrafting)) {
return thisContainer.transferStackInSlot(player, slotId);
}
this.lastCraft = null;
this.shiftCraft = true;
ItemStack result = thisContainer.transferStackInSlot(player, slotId);
if (this.lastCraft != null) {
if (this.lastCraft.isCancelled()) {
// Return empty to stop shift-crafting
result = ItemStack.EMPTY;
}
}
this.shiftCraft = false;
return result;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinContainer method onDragDropSplit.
@Redirect(method = "slotClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/EntityPlayer;dropItem(Lnet/minecraft/item/ItemStack;Z)Lnet/minecraft/entity/item/EntityItem;", ordinal = 1))
public EntityItem onDragDropSplit(EntityPlayer player, ItemStack itemStackIn, boolean unused) {
final EntityItem entityItem = player.dropItem(itemStackIn, unused);
if (!((IMixinEntityPlayer) player).shouldRestoreInventory()) {
return entityItem;
}
if (entityItem == null) {
ItemStack original = null;
if (player.inventory.getItemStack().isEmpty()) {
original = itemStackIn;
} else {
player.inventory.getItemStack().grow(1);
original = player.inventory.getItemStack();
}
player.inventory.setItemStack(original);
((EntityPlayerMP) player).connection.sendPacket(new SPacketSetSlot(-1, -1, original));
}
((IMixinEntityPlayer) player).shouldRestoreInventory(false);
return entityItem;
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeCommon by SpongePowered.
the class MixinContainer method beforeSlotChangedCraftingGrid.
@Redirect(method = "slotChangedCraftingGrid", at = @At(value = "INVOKE", target = "Lnet/minecraft/inventory/InventoryCraftResult;setInventorySlotContents(ILnet/minecraft/item/ItemStack;)V"))
private void beforeSlotChangedCraftingGrid(InventoryCraftResult output, int index, ItemStack itemstack) {
if (!this.captureInventory) {
// Capture Inventory is true when caused by a vanilla inventory packet
// This is to prevent infinite loops when a client mod re-requests the recipe result after we modified/cancelled it
output.setInventorySlotContents(index, itemstack);
return;
}
this.spongeInit();
this.capturedCraftPreviewTransactions.clear();
ItemStackSnapshot orig = ItemStackUtil.snapshotOf(output.getStackInSlot(index));
output.setInventorySlotContents(index, itemstack);
ItemStackSnapshot repl = ItemStackUtil.snapshotOf(output.getStackInSlot(index));
SlotAdapter slot = this.adapters.get(index);
this.capturedCraftPreviewTransactions.add(new SlotTransaction(slot, orig, repl));
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeForge by SpongePowered.
the class MixinGameRegistry method onGenerateWorld.
@Redirect(method = "generateWorld", at = @At(value = "INVOKE", target = WORLD_GENERATOR_GENERATE, remap = false))
private static void onGenerateWorld(IWorldGenerator worldGenerator, Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) {
Timing timing = null;
if (Timings.isTimingsEnabled()) {
timing = worldGeneratorTimings.get(worldGenerator.getClass());
if (timing == null) {
String modId = StaticMixinForgeHelper.getModIdFromClass(worldGenerator.getClass());
timing = SpongeTimingsFactory.ofSafe("worldGenerator (" + modId + ":" + worldGenerator.getClass().getName() + ")");
worldGeneratorTimings.put(worldGenerator.getClass(), timing);
}
timing.startTimingIfSync();
}
worldGenerator.generate(random, chunkX, chunkZ, world, chunkGenerator, chunkProvider);
if (Timings.isTimingsEnabled()) {
timing.stopTimingIfSync();
}
}
use of org.spongepowered.asm.mixin.injection.Redirect in project SpongeForge by SpongePowered.
the class MixinVanillaInventoryCodeHooks method onPullItemOut.
@Redirect(remap = false, method = "extractHook", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/items/IItemHandler;extractItem(IIZ)Lnet/minecraft/item/ItemStack;", ordinal = 1))
private static ItemStack onPullItemOut(IItemHandler handler, int slot, int amount, boolean simulate, IHopper dest) {
if (ShouldFire.CHANGE_INVENTORY_EVENT_TRANSFER_POST) {
Object inv = getItemHandler(dest, EnumFacing.UP).getValue();
// Capture Origin
ItemStack origin = handler.getStackInSlot(slot).copy();
ItemStack result = handler.extractItem(slot, amount, simulate);
SpongeCommonEventFactory.captureTransaction(InventoryUtil.forCapture(dest), InventoryUtil.toInventory(inv, handler), slot, origin);
return result;
}
return handler.extractItem(slot, amount, simulate);
}
Aggregations