Search in sources :

Example 1 with S2FPacketSetSlot

use of net.minecraft.network.play.server.S2FPacketSetSlot in project BetterStorage by copygirl.

the class ItemBackpack method onPlaceBackpack.

/** Places an equipped backpack when the player right clicks
	 *  on the ground while sneaking and holding nothing. */
public static boolean onPlaceBackpack(EntityPlayer player, int x, int y, int z, int side) {
    if (player.getCurrentEquippedItem() != null || !player.isSneaking())
        return false;
    ItemStack backpack = ItemBackpack.getBackpack(player);
    if (backpack == null)
        return false;
    boolean success = false;
    if (!ItemBackpack.isBackpackOpen(player)) {
        // Try to place the backpack as if it was being held and used by the player.
        success = backpack.getItem().onItemUse(backpack, player, player.worldObj, x, y, z, side, 0, 0, 0);
        if (backpack.stackSize <= 0) {
            ItemBackpack.setBackpack(player, null, null);
            backpack = null;
        }
    }
    // Make sure the client has the same information as the server. It does not sync when backpackChestplate is disabled because there are no changes to the slot in that case.
    if (!player.worldObj.isRemote && success && player instanceof EntityPlayerMP && BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate)) {
        ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S2FPacketSetSlot(0, 6, backpack));
    }
    if (success)
        player.swingItem();
    return success;
}
Also used : S2FPacketSetSlot(net.minecraft.network.play.server.S2FPacketSetSlot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack)

Example 2 with S2FPacketSetSlot

use of net.minecraft.network.play.server.S2FPacketSetSlot in project BetterStorage by copygirl.

the class ContainerCrate method transferStackInSlot.

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotId) {
    // use ContainerBetterStorage.transferStackInSlot.
    if (playerView == null)
        return super.transferStackInSlot(player, slotId);
    Slot slot = (Slot) inventorySlots.get(slotId);
    ItemStack slotStack = slot.getStack();
    if (slotStack == null)
        return null;
    ItemStack stackBefore = slotStack.copy();
    // If slot is in the container inventory, try to transfer the item to the player.
    if (slotId < getColumns() * getRows()) {
        int count = slotStack.stackSize;
        boolean success = mergeItemStack(slotStack, playerView.getSizeInventory(), inventorySlots.size(), true);
        int amount = count - slotStack.stackSize;
        slotStack.stackSize = count;
        playerView.decrStackSize(slotId, amount);
        if (!success)
            return null;
    // If slot is in the player inventory, try to transfer the item to the container.
    } else {
        boolean success = playerView.canFitSome(slotStack);
        ItemStack overflow = playerView.data.addItems(slotStack);
        slot.putStack(overflow);
        // Send slot contents to player if it doesn't match the calculated overflow.
        ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S2FPacketSetSlot(player.openContainer.windowId, slotId, overflow));
        if (!success)
            return null;
    }
    return stackBefore;
}
Also used : S2FPacketSetSlot(net.minecraft.network.play.server.S2FPacketSetSlot) S2FPacketSetSlot(net.minecraft.network.play.server.S2FPacketSetSlot) Slot(net.minecraft.inventory.Slot) ItemStack(net.minecraft.item.ItemStack)

Example 3 with S2FPacketSetSlot

use of net.minecraft.network.play.server.S2FPacketSetSlot in project BetterStorage by copygirl.

the class VanillaArmorStandEquipHandler method setEquipment.

@Override
public void setEquipment(EntityPlayer player, ItemStack item) {
    player.setCurrentItemOrArmor(region.ordinal() + 1, item);
    // Shouldn't this be done automatically?
    ((EntityPlayerMP) player).playerNetServerHandler.sendPacket(new S2FPacketSetSlot(player.openContainer.windowId, 8 - region.ordinal(), item));
}
Also used : S2FPacketSetSlot(net.minecraft.network.play.server.S2FPacketSetSlot)

Aggregations

S2FPacketSetSlot (net.minecraft.network.play.server.S2FPacketSetSlot)3 ItemStack (net.minecraft.item.ItemStack)2 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 Slot (net.minecraft.inventory.Slot)1