Search in sources :

Example 6 with SPacketSetSlot

use of net.minecraft.network.play.server.SPacketSetSlot in project artisan-worktables by codetaylor.

the class ArtisanRecipe method onCraftCheckAndSwapWeightedOutput.

@Nonnull
protected ItemStack onCraftCheckAndSwapWeightedOutput(ICraftingContext context) {
    EntityPlayer player = context.getPlayer();
    if (!player.inventory.getItemStack().isEmpty()) {
        if (this.hasMultipleWeightedOutputs()) {
            ItemStack itemStack = this.selectOutput(context, Util.RANDOM).toItemStack();
            player.inventory.setItemStack(itemStack);
            ((EntityPlayerMP) player).connection.sendPacket(new SPacketSetSlot(-1, -1, itemStack));
        }
    }
    return player.inventory.getItemStack();
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 7 with SPacketSetSlot

use of net.minecraft.network.play.server.SPacketSetSlot in project minecolonies by Minecolonies.

the class CraftingGUIBuilding method onCraftMatrixChanged.

/**
 * Callback for when the crafting matrix is changed.
 */
@Override
public void onCraftMatrixChanged(final IInventory inventoryIn) {
    if (!worldObj.isRemote) {
        final EntityPlayerMP entityplayermp = (EntityPlayerMP) player;
        ItemStack itemstack = ItemStack.EMPTY;
        final IRecipe irecipe = CraftingManager.findMatchingRecipe(craftMatrix, worldObj);
        if (irecipe != null && (irecipe.isDynamic() || !worldObj.getGameRules().getBoolean("doLimitedCrafting") || entityplayermp.getRecipeBook().isUnlocked(irecipe) || entityplayermp.isCreative())) {
            this.craftResult.setRecipeUsed(irecipe);
            itemstack = irecipe.getCraftingResult(this.craftMatrix);
        }
        this.craftResult.setInventorySlotContents(0, itemstack);
        entityplayermp.connection.sendPacket(new SPacketSetSlot(this.windowId, 0, itemstack));
    }
    super.onCraftMatrixChanged(inventoryIn);
}
Also used : IRecipe(net.minecraft.item.crafting.IRecipe) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(net.minecraft.item.ItemStack)

Example 8 with SPacketSetSlot

use of net.minecraft.network.play.server.SPacketSetSlot in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method restorePacketItem.

@Override
public void restorePacketItem(EnumHand hand) {
    if (this.packetItem.isEmpty()) {
        return;
    }
    this.isChangingQuantityOnly = true;
    this.setHeldItem(hand, this.packetItem);
    Slot slot = this.openContainer.getSlotFromInventory(this.inventory, this.inventory.currentItem);
    this.openContainer.detectAndSendChanges();
    this.isChangingQuantityOnly = false;
    // force client itemstack update if place event was cancelled
    this.connection.sendPacket(new SPacketSetSlot(this.openContainer.windowId, slot.slotNumber, this.packetItem));
}
Also used : SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) Slot(net.minecraft.inventory.Slot) SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot)

Example 9 with SPacketSetSlot

use of net.minecraft.network.play.server.SPacketSetSlot in project SpongeCommon by SpongePowered.

the class MixinContainer method onThrowClick.

@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 = 3))
public EntityItem onThrowClick(EntityPlayer player, ItemStack itemStackIn, boolean unused) {
    final EntityItem entityItem = player.dropItem(itemStackIn, true);
    if (entityItem == null && ((IMixinEntityPlayer) player).shouldRestoreInventory()) {
        final ItemStack original = ItemStackUtil.toNative(this.itemStackSnapshot.createStack());
        this.lastSlotUsed.putStack(original);
        player.openContainer.detectAndSendChanges();
        ((EntityPlayerMP) player).isChangingQuantityOnly = false;
        ((EntityPlayerMP) player).connection.sendPacket(new SPacketSetSlot(player.openContainer.windowId, this.lastSlotUsed.slotNumber, original));
    }
    this.itemStackSnapshot = null;
    this.lastSlotUsed = null;
    ((IMixinEntityPlayer) player).shouldRestoreInventory(false);
    return entityItem;
}
Also used : SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(net.minecraft.item.ItemStack) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) EntityItem(net.minecraft.entity.item.EntityItem) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 10 with SPacketSetSlot

use of net.minecraft.network.play.server.SPacketSetSlot in project SpongeCommon by SpongePowered.

the class PacketPhaseUtil method handleCustomCursor.

public static void handleCustomCursor(EntityPlayerMP player, ItemStackSnapshot customCursor) {
    ItemStack cursor = ItemStackUtil.fromSnapshotToNative(customCursor);
    player.inventory.setItemStack(cursor);
    player.connection.sendPacket(new SPacketSetSlot(-1, -1, cursor));
}
Also used : SPacketSetSlot(net.minecraft.network.play.server.SPacketSetSlot) ItemStack(net.minecraft.item.ItemStack)

Aggregations

SPacketSetSlot (net.minecraft.network.play.server.SPacketSetSlot)15 ItemStack (net.minecraft.item.ItemStack)11 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 EntityItem (net.minecraft.entity.item.EntityItem)5 Slot (net.minecraft.inventory.Slot)4 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 IMixinEntityPlayer (org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)2 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)2 TileEntity (net.minecraft.tileentity.TileEntity)2 CraftItemEvent (org.spongepowered.api.event.item.inventory.CraftItemEvent)2 ItemStackSnapshot (org.spongepowered.api.item.inventory.ItemStackSnapshot)2 Overwrite (org.spongepowered.asm.mixin.Overwrite)2 IMixinEntityPlayerMP (org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP)2 TileEntityBase (com.codetaylor.mc.artisanworktables.modules.worktables.tile.spi.TileEntityBase)1 SPacketTileEntityBase (com.codetaylor.mc.athenaeum.spi.packet.SPacketTileEntityBase)1 Vector3d (com.flowpowered.math.vector.Vector3d)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1