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