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;
}
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;
}
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));
}
Aggregations