Last active
October 26, 2015 20:36
-
-
Save bloodmc/a6c7f0fcf4a9c76cd70d to your computer and use it in GitHub Desktop.
MixinHelp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void detectAndSendChanges() | |
{ | |
for (int i = 0; i < this.inventorySlots.size(); ++i) | |
{ | |
ItemStack itemstack = ((Slot)this.inventorySlots.get(i)).getStack(); | |
ItemStack itemstack1 = (ItemStack)this.inventoryItemStacks.get(i); | |
if (!ItemStack.areItemStacksEqual(itemstack1, itemstack)) | |
{ | |
itemstack1 = itemstack == null ? null : itemstack.copy(); | |
this.inventoryItemStacks.set(i, itemstack1); | |
for (int j = 0; j < this.crafters.size(); ++j) | |
{ | |
((ICrafting)this.crafters.get(j)).sendSlotContents(this, i, itemstack1); | |
} | |
} | |
} | |
} | |
@Overwrite | |
public void detectAndSendChanges() { | |
for (int i = 0; i < this.inventorySlots.size(); ++i) { | |
ItemStack itemstack = ((Slot) this.inventorySlots.get(i)).getStack(); | |
ItemStack itemstack1 = (ItemStack) this.inventoryItemStacks.get(i); | |
if (!ItemStack.areItemStacksEqual(itemstack1, itemstack)) { | |
if (this.captureInventory) { | |
ItemStackSnapshot originalItem = itemstack1 == null ? ItemStackSnapshot.NONE | |
: ((org.spongepowered.api.item.inventory.ItemStack) itemstack1).createSnapshot(); | |
ItemStackSnapshot newItem = itemstack == null ? ItemStackSnapshot.NONE | |
: ((org.spongepowered.api.item.inventory.ItemStack) itemstack).createSnapshot(); | |
SlotTransaction slotTransaction = | |
new SlotTransaction((org.spongepowered.api.item.inventory.Slot) this.inventorySlots.get(i), originalItem, newItem); | |
this.capturedSlotTransactions.add(slotTransaction); | |
} | |
itemstack1 = itemstack == null ? null : itemstack.copy(); | |
this.inventoryItemStacks.set(i, itemstack1); | |
for (int j = 0; j < this.crafters.size(); ++j) { | |
((ICrafting) this.crafters.get(j)).sendSlotContents((Container) (Object) this, i, itemstack1); | |
} | |
} | |
} | |
} | |
NetHandlerPlayServer | |
@SuppressWarnings({"rawtypes", "unchecked"}) | |
@Overwrite | |
public void processClickWindow(C0EPacketClickWindow packetIn) { | |
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (INetHandler) this, this.playerEntity.getServerForPlayer()); | |
this.playerEntity.markPlayerActive(); | |
if (this.playerEntity.openContainer.windowId == packetIn.getWindowId() && this.playerEntity.openContainer.getCanCraft(this.playerEntity)) { | |
if (this.playerEntity.isSpectator()) { | |
ArrayList arraylist = Lists.newArrayList(); | |
for (int i = 0; i < this.playerEntity.openContainer.inventorySlots.size(); ++i) { | |
arraylist.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(i)).getStack()); | |
} | |
this.playerEntity.updateCraftingInventory(this.playerEntity.openContainer, arraylist); | |
} else { | |
((IMixinContainer) this.playerEntity.openContainer).setCaptureInventory(true); | |
ItemStack itemstack = this.playerEntity.openContainer.slotClick(packetIn.getSlotId(), packetIn.getUsedButton(), packetIn.getMode(), this.playerEntity); | |
if (ItemStack.areItemStacksEqual(packetIn.getClickedItem(), itemstack)) { | |
this.playerEntity.playerNetServerHandler.sendPacket(new S32PacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), true)); | |
this.playerEntity.isChangingQuantityOnly = true; | |
this.playerEntity.openContainer.detectAndSendChanges(); | |
this.playerEntity.updateHeldItem(); | |
this.playerEntity.isChangingQuantityOnly = false; | |
} else { | |
this.field_147372_n.addKey(this.playerEntity.openContainer.windowId, Short.valueOf(packetIn.getActionNumber())); | |
this.playerEntity.playerNetServerHandler.sendPacket( | |
new S32PacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), false)); | |
this.playerEntity.openContainer.setCanCraft(this.playerEntity, false); | |
ArrayList arraylist1 = Lists.newArrayList(); | |
for (int j = 0; j < this.playerEntity.openContainer.inventorySlots.size(); ++j) { | |
arraylist1.add(((Slot)this.playerEntity.openContainer.inventorySlots.get(j)).getStack()); | |
} | |
this.playerEntity.updateCraftingInventory(this.playerEntity.openContainer, arraylist1); | |
} | |
((IMixinContainer) this.playerEntity.openContainer).setCaptureInventory(false); | |
} | |
} | |
} | |
@Overwrite | |
public void processHeldItemChange(C09PacketHeldItemChange packetIn) { | |
PacketThreadUtil.checkThreadAndEnqueue(packetIn, (NetHandlerPlayServer)(Object)this, this.playerEntity.getServerForPlayer()); | |
if (packetIn.getSlotId() >= 0 && packetIn.getSlotId() < InventoryPlayer.getHotbarSize()) { | |
SpongeCommonEventFactory.callInteractInventoryHeldEvent(this.playerEntity, packetIn); | |
} else { | |
logger.warn(this.playerEntity.getCommandSenderName() + " tried to set an invalid carried item"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment