use of net.minecraft.entity.player.InventoryPlayer in project LogisticsPipes by RS485.
the class DummyContainer method superSlotClick.
@SuppressWarnings({ "unchecked", "rawtypes" })
public ItemStack superSlotClick(int par1, int par2, int par3, EntityPlayer par4EntityPlayer) {
ItemStack itemstack = null;
InventoryPlayer inventoryplayer = par4EntityPlayer.inventory;
int i1;
ItemStack itemstack3;
if (par3 == 5) {
int l = field_94536_g;
field_94536_g = Container.func_94532_c(par2);
if ((l != 1 || field_94536_g != 2) && l != field_94536_g) {
func_94533_d();
} else if (inventoryplayer.getItemStack() == null) {
func_94533_d();
} else if (field_94536_g == 0) {
field_94535_f = Container.func_94529_b(par2);
if (Container.func_94528_d(field_94535_f)) {
field_94536_g = 1;
field_94537_h.clear();
} else {
func_94533_d();
}
} else if (field_94536_g == 1) {
Slot slot = (Slot) inventorySlots.get(par1);
if (slot != null && Container.func_94527_a(slot, inventoryplayer.getItemStack(), true) && slot.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize > field_94537_h.size() && canDragIntoSlot(slot)) {
field_94537_h.add(slot);
}
} else if (field_94536_g == 2) {
if (!field_94537_h.isEmpty()) {
itemstack3 = inventoryplayer.getItemStack().copy();
i1 = inventoryplayer.getItemStack().stackSize;
Iterator iterator = field_94537_h.iterator();
while (iterator.hasNext()) {
Slot slot1 = (Slot) iterator.next();
if (slot1 != null && Container.func_94527_a(slot1, inventoryplayer.getItemStack(), true) && slot1.isItemValid(inventoryplayer.getItemStack()) && inventoryplayer.getItemStack().stackSize >= field_94537_h.size() && canDragIntoSlot(slot1)) {
ItemStack itemstack1 = itemstack3.copy();
int j1 = slot1.getHasStack() ? slot1.getStack().stackSize : 0;
Container.func_94525_a(field_94537_h, field_94535_f, itemstack1, j1);
if (itemstack1.stackSize > itemstack1.getMaxStackSize()) {
itemstack1.stackSize = itemstack1.getMaxStackSize();
}
if (itemstack1.stackSize > slot1.getSlotStackLimit()) {
itemstack1.stackSize = slot1.getSlotStackLimit();
}
i1 -= itemstack1.stackSize - j1;
slot1.putStack(itemstack1);
}
}
itemstack3.stackSize = i1;
if (itemstack3.stackSize <= 0) {
itemstack3 = null;
}
inventoryplayer.setItemStack(itemstack3);
}
func_94533_d();
} else {
func_94533_d();
}
} else if (field_94536_g != 0) {
func_94533_d();
} else {
Slot slot2;
int l1;
ItemStack itemstack5;
if ((par3 == 0 || par3 == 1) && (par2 == 0 || par2 == 1)) {
if (par1 == -999) {
if (inventoryplayer.getItemStack() != null && par1 == -999) {
if (par2 == 0) {
par4EntityPlayer.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack(), true);
inventoryplayer.setItemStack(null);
}
if (par2 == 1) {
par4EntityPlayer.dropPlayerItemWithRandomChoice(inventoryplayer.getItemStack().splitStack(1), true);
if (inventoryplayer.getItemStack().stackSize == 0) {
inventoryplayer.setItemStack(null);
}
}
}
} else if (par3 == 1) {
if (par1 < 0) {
return null;
}
slot2 = (Slot) inventorySlots.get(par1);
if (slot2 != null && slot2.canTakeStack(par4EntityPlayer)) {
itemstack3 = transferStackInSlot(par4EntityPlayer, par1);
if (itemstack3 != null) {
Item item = itemstack3.getItem();
itemstack = itemstack3.copy();
if (slot2.getStack() != null && slot2.getStack().getItem() == item) {
retrySlotClick(par1, par2, true, par4EntityPlayer);
}
}
}
} else {
if (par1 < 0) {
return null;
}
slot2 = (Slot) inventorySlots.get(par1);
if (slot2 != null) {
itemstack3 = slot2.getStack();
ItemStack itemstack4 = inventoryplayer.getItemStack();
if (itemstack3 != null) {
itemstack = itemstack3.copy();
}
if (itemstack3 == null) {
if (itemstack4 != null && slot2.isItemValid(itemstack4)) {
l1 = par2 == 0 ? itemstack4.stackSize : 1;
if (l1 > slot2.getSlotStackLimit()) {
l1 = slot2.getSlotStackLimit();
}
if (itemstack4.stackSize >= l1) {
slot2.putStack(itemstack4.splitStack(l1));
}
if (itemstack4.stackSize == 0) {
inventoryplayer.setItemStack(null);
}
}
} else if (slot2.canTakeStack(par4EntityPlayer)) {
if (itemstack4 == null) {
l1 = par2 == 0 ? itemstack3.stackSize : (itemstack3.stackSize + 1) / 2;
itemstack5 = slot2.decrStackSize(l1);
inventoryplayer.setItemStack(itemstack5);
if (itemstack3.stackSize == 0) {
slot2.putStack(null);
}
slot2.onPickupFromSlot(par4EntityPlayer, inventoryplayer.getItemStack());
} else if (slot2.isItemValid(itemstack4)) {
if (itemstack3.getItem() == itemstack4.getItem() && itemstack3.getItemDamage() == itemstack4.getItemDamage() && areEqualForMerge(itemstack3, itemstack4, slot2)) {
// XXX replaced ItemStack.areItemStackTagsEqual with areEqualForMerge for slot based handling
l1 = par2 == 0 ? itemstack4.stackSize : 1;
if (l1 > slot2.getSlotStackLimit() - itemstack3.stackSize) {
l1 = slot2.getSlotStackLimit() - itemstack3.stackSize;
}
if (l1 > itemstack4.getMaxStackSize() - itemstack3.stackSize) {
l1 = itemstack4.getMaxStackSize() - itemstack3.stackSize;
}
itemstack4.splitStack(l1);
if (itemstack4.stackSize == 0) {
inventoryplayer.setItemStack(null);
}
itemstack3.stackSize += l1;
// XXX added reinserting of the modified itemStack (Fix ItemIdentifierInventory's disappearing items)
slot2.putStack(itemstack3);
} else if (itemstack4.stackSize <= slot2.getSlotStackLimit()) {
// XXX added Slot switching handle method
handleSwitch(slot2, itemstack3, itemstack4, par4EntityPlayer);
slot2.putStack(itemstack4);
inventoryplayer.setItemStack(itemstack3);
}
} else if (itemstack3.getItem() == itemstack4.getItem() && itemstack4.getMaxStackSize() > 1 && (!itemstack3.getHasSubtypes() || itemstack3.getItemDamage() == itemstack4.getItemDamage()) && areEqualForMerge(itemstack3, itemstack4, slot2)) {
// XXX replaced ItemStack.areItemStackTagsEqual with areEqualForMerge for slot based handling
l1 = itemstack3.stackSize;
if (l1 > 0 && l1 + itemstack4.stackSize <= itemstack4.getMaxStackSize()) {
itemstack4.stackSize += l1;
itemstack3 = slot2.decrStackSize(l1);
if (itemstack3.stackSize == 0) {
slot2.putStack(null);
}
slot2.onPickupFromSlot(par4EntityPlayer, inventoryplayer.getItemStack());
}
}
}
slot2.onSlotChanged();
}
}
} else if (par3 == 2 && par2 >= 0 && par2 < 9) {
slot2 = (Slot) inventorySlots.get(par1);
if (slot2.canTakeStack(par4EntityPlayer)) {
itemstack3 = inventoryplayer.getStackInSlot(par2);
boolean flag = itemstack3 == null || slot2.inventory == inventoryplayer && slot2.isItemValid(itemstack3);
l1 = -1;
if (!flag) {
l1 = inventoryplayer.getFirstEmptyStack();
flag |= l1 > -1;
}
if (slot2.getHasStack() && flag) {
itemstack5 = slot2.getStack();
inventoryplayer.setInventorySlotContents(par2, itemstack5.copy());
if ((slot2.inventory != inventoryplayer || !slot2.isItemValid(itemstack3)) && itemstack3 != null) {
if (l1 > -1) {
inventoryplayer.addItemStackToInventory(itemstack3);
slot2.decrStackSize(itemstack5.stackSize);
slot2.putStack(null);
slot2.onPickupFromSlot(par4EntityPlayer, itemstack5);
}
} else {
slot2.decrStackSize(itemstack5.stackSize);
slot2.putStack(itemstack3);
slot2.onPickupFromSlot(par4EntityPlayer, itemstack5);
}
} else if (!slot2.getHasStack() && itemstack3 != null && slot2.isItemValid(itemstack3)) {
inventoryplayer.setInventorySlotContents(par2, null);
slot2.putStack(itemstack3);
}
}
} else if (par3 == 3 && par4EntityPlayer.capabilities.isCreativeMode && inventoryplayer.getItemStack() == null && par1 >= 0) {
slot2 = (Slot) inventorySlots.get(par1);
if (slot2 != null && slot2.getHasStack()) {
itemstack3 = slot2.getStack().copy();
itemstack3.stackSize = itemstack3.getMaxStackSize();
inventoryplayer.setItemStack(itemstack3);
}
} else if (par3 == 4 && inventoryplayer.getItemStack() == null && par1 >= 0) {
slot2 = (Slot) inventorySlots.get(par1);
if (slot2 != null && slot2.getHasStack() && slot2.canTakeStack(par4EntityPlayer)) {
itemstack3 = slot2.decrStackSize(par2 == 0 ? 1 : slot2.getStack().stackSize);
slot2.onPickupFromSlot(par4EntityPlayer, itemstack3);
par4EntityPlayer.dropPlayerItemWithRandomChoice(itemstack3, true);
}
} else if (par3 == 6 && par1 >= 0) {
slot2 = (Slot) inventorySlots.get(par1);
itemstack3 = inventoryplayer.getItemStack();
if (itemstack3 != null && (slot2 == null || !slot2.getHasStack() || !slot2.canTakeStack(par4EntityPlayer))) {
i1 = par2 == 0 ? 0 : inventorySlots.size() - 1;
l1 = par2 == 0 ? 1 : -1;
for (int i2 = 0; i2 < 2; ++i2) {
for (int j2 = i1; j2 >= 0 && j2 < inventorySlots.size() && itemstack3.stackSize < itemstack3.getMaxStackSize(); j2 += l1) {
Slot slot3 = (Slot) inventorySlots.get(j2);
if (slot3.getHasStack() && Container.func_94527_a(slot3, itemstack3, true) && slot3.canTakeStack(par4EntityPlayer) && func_94530_a(itemstack3, slot3) && (i2 != 0 || slot3.getStack().stackSize != slot3.getStack().getMaxStackSize())) {
int k1 = Math.min(itemstack3.getMaxStackSize() - itemstack3.stackSize, slot3.getStack().stackSize);
ItemStack itemstack2 = slot3.decrStackSize(k1);
itemstack3.stackSize += k1;
if (itemstack2.stackSize <= 0) {
slot3.putStack(null);
}
slot3.onPickupFromSlot(par4EntityPlayer, itemstack2);
}
}
}
}
detectAndSendChanges();
}
}
return itemstack;
}
use of net.minecraft.entity.player.InventoryPlayer in project LogisticsPipes by RS485.
the class DummyContainer method slotClick.
/**
* Clone/clear itemstacks for items
*/
@Override
public ItemStack slotClick(int slotId, int mouseButton, int isShift, EntityPlayer entityplayer) {
lastClicked = System.currentTimeMillis();
if (slotId < 0) {
return superSlotClick(slotId, mouseButton, isShift, entityplayer);
}
Slot slot = (Slot) inventorySlots.get(slotId);
//debug dump
if (LPConstants.DEBUG && slot != null) {
ItemStack stack = slot.getStack();
if (stack != null) {
ItemIdentifier.get(stack).debugDumpData(entityplayer.worldObj.isRemote);
}
}
if (slot == null || (!(slot instanceof DummySlot) && !(slot instanceof UnmodifiableSlot) && !(slot instanceof FluidSlot) && !(slot instanceof ColorSlot) && !(slot instanceof HandelableSlot))) {
ItemStack stack1 = superSlotClick(slotId, mouseButton, isShift, entityplayer);
ItemStack stack2 = slot.getStack();
if (stack2 != null && stack2.getItem() == LogisticsPipes.ModuleItem) {
if (entityplayer instanceof EntityPlayerMP && MainProxy.isServer(entityplayer.worldObj)) {
((EntityPlayerMP) entityplayer).sendSlotContents(this, slotId, stack2);
}
}
return stack1;
}
InventoryPlayer inventoryplayer = entityplayer.inventory;
ItemStack currentlyEquippedStack = inventoryplayer.getItemStack();
// we get a leftclick *and* a doubleclick message if there's a doubleclick with no item on the pointer, filter it out
if (currentlyEquippedStack == null && isShift == 6) {
return currentlyEquippedStack;
}
if (slot instanceof HandelableSlot) {
overrideMCAntiSend = true;
if (currentlyEquippedStack == null) {
inventoryplayer.setItemStack(((HandelableSlot) slot).getProvidedStack());
return null;
}
return currentlyEquippedStack;
}
if (slot instanceof UnmodifiableSlot) {
return currentlyEquippedStack;
}
handleDummyClick(slot, slotId, currentlyEquippedStack, mouseButton, isShift, entityplayer);
return currentlyEquippedStack;
}
use of net.minecraft.entity.player.InventoryPlayer in project ImmersiveEngineering by BluSunrize.
the class ContainerSorter method slotClick.
@Override
public ItemStack slotClick(int id, int button, ClickType modifier, EntityPlayer player) {
Slot slot = id < 0 ? null : this.inventorySlots.get(id);
if (!(slot instanceof IESlot.Ghost))
return super.slotClick(id, button, modifier, player);
ItemStack stack = null;
ItemStack stackSlot = slot.getStack();
if (stackSlot != null)
stack = stackSlot.copy();
if (button == 2)
slot.putStack(null);
else if (button == 0 || button == 1) {
InventoryPlayer playerInv = player.inventory;
ItemStack stackHeld = playerInv.getItemStack();
if (stackSlot == null) {
if (stackHeld != null && slot.isItemValid(stackHeld)) {
slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
}
} else if (stackHeld == null) {
slot.putStack(null);
} else if (slot.isItemValid(stackHeld)) {
slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
}
} else if (button == 5) {
InventoryPlayer playerInv = player.inventory;
ItemStack stackHeld = playerInv.getItemStack();
if (!slot.getHasStack()) {
slot.putStack(Utils.copyStackWithAmount(stackHeld, 1));
}
}
return stack;
}
use of net.minecraft.entity.player.InventoryPlayer in project SpongeCommon by SpongePowered.
the class SwitchHotbarScrollState method unwind.
@Override
public void unwind(InventoryPacketContext context) {
final EntityPlayerMP player = context.getPacketPlayer();
final CPacketHeldItemChange itemChange = context.getPacket();
final int previousSlot = context.getHighlightedSlotId();
final net.minecraft.inventory.Container inventoryContainer = player.inventoryContainer;
final InventoryPlayer inventory = player.inventory;
// Crafting Grid & Result
int preHotbarSize = inventory.mainInventory.size() - InventoryPlayer.getHotbarSize() + inventory.armorInventory.size() + 4 + 1;
final Slot sourceSlot = inventoryContainer.getSlot(previousSlot + preHotbarSize);
final Slot targetSlot = inventoryContainer.getSlot(itemChange.getSlotId() + preHotbarSize);
ItemStackSnapshot sourceSnapshot = ItemStackUtil.snapshotOf(sourceSlot.getStack());
ItemStackSnapshot targetSnapshot = ItemStackUtil.snapshotOf(targetSlot.getStack());
SlotTransaction sourceTransaction = new SlotTransaction(ContainerUtil.getSlot(inventoryContainer, previousSlot + preHotbarSize), sourceSnapshot, sourceSnapshot);
SlotTransaction targetTransaction = new SlotTransaction(ContainerUtil.getSlot(inventoryContainer, itemChange.getSlotId() + preHotbarSize), targetSnapshot, targetSnapshot);
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(player);
ImmutableList<SlotTransaction> transactions = new ImmutableList.Builder<SlotTransaction>().add(sourceTransaction).add(targetTransaction).build();
final ChangeInventoryEvent.Held changeInventoryEventHeld = SpongeEventFactory.createChangeInventoryEventHeld(Sponge.getCauseStackManager().getCurrentCause(), (Inventory) inventoryContainer, transactions);
net.minecraft.inventory.Container openContainer = player.openContainer;
SpongeImpl.postEvent(changeInventoryEventHeld);
if (changeInventoryEventHeld.isCancelled() || PacketPhaseUtil.allTransactionsInvalid(changeInventoryEventHeld.getTransactions())) {
player.connection.sendPacket(new SPacketHeldItemChange(previousSlot));
inventory.currentItem = previousSlot;
} else {
PacketPhaseUtil.handleSlotRestore(player, openContainer, changeInventoryEventHeld.getTransactions(), false);
inventory.currentItem = itemChange.getSlotId();
player.markPlayerActive();
}
}
}
use of net.minecraft.entity.player.InventoryPlayer in project SpongeCommon by SpongePowered.
the class BookFaker method fakeBookView.
public static void fakeBookView(BookView bookView, Player player) {
EntityPlayerMP mcPlayer = (EntityPlayerMP) player;
NetHandlerPlayServer receiver = mcPlayer.connection;
// First we need to send a fake a Book ItemStack with the BookView's
// contents to the player's hand
ItemStack item = ItemStack.of(ItemTypes.WRITTEN_BOOK, 1);
item.offer(Keys.DISPLAY_NAME, bookView.getTitle());
item.offer(Keys.BOOK_AUTHOR, bookView.getAuthor());
item.offer(Keys.BOOK_PAGES, bookView.getPages());
InventoryPlayer inventory = mcPlayer.inventory;
int bookSlot = inventory.mainInventory.size() + inventory.currentItem;
receiver.sendPacket(new SPacketSetSlot(WINDOW_PLAYER_INVENTORY, bookSlot, ItemStackUtil.toNative(item)));
// Next we tell the client to open the Book GUI
PacketBuffer packetbuffer = new PacketBuffer(Unpooled.buffer());
packetbuffer.writeEnumValue(EnumHand.MAIN_HAND);
receiver.sendPacket(new SPacketCustomPayload("MC|BOpen", packetbuffer));
// Now we can remove the fake Book since it's contents will have already
// been transferred to the GUI
receiver.sendPacket(new SPacketSetSlot(WINDOW_PLAYER_INVENTORY, bookSlot, inventory.getCurrentItem()));
}
Aggregations