Skip to content

Commit

Permalink
Fix interacting with the rift browser in complex situations such as w…
Browse files Browse the repository at this point in the history
…ith the Storage Drawers.
  • Loading branch information
gigaherz committed Apr 22, 2016
1 parent aa673cc commit 64424a1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {

apply plugin: 'net.minecraftforge.gradle.forge'

version = "0.12.1"
version = "0.12.2"
group= "gigaherz.enderRift"
archivesBaseName = "EnderRift-1.9"

Expand Down
51 changes: 39 additions & 12 deletions src/main/java/gigaherz/enderRift/gui/ContainerBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.SPacketSetSlot;
import net.minecraftforge.items.IItemHandlerModifiable;

import java.util.List;
Expand All @@ -34,6 +35,7 @@ public class ContainerBrowser
public int scroll;
public SortMode sortMode = SortMode.StackSize;
private String filterText = "";
private ItemStack stackInCursor;

final static int Left = 8;
final static int Top = 18;
Expand Down Expand Up @@ -140,6 +142,23 @@ public void detectAndSendChanges()
}
}
}

for (ICrafting crafter : this.listeners)
{
if (!(crafter instanceof EntityPlayerMP))
continue;

EntityPlayerMP player = (EntityPlayerMP)crafter;
ItemStack newStack = player.inventory.getItemStack();

if (!ItemStack.areItemStacksEqual(stackInCursor, newStack))
{
stackInCursor = newStack == null ? null : newStack.copy();

player.playerNetServerHandler.sendPacket(new SPacketSetSlot(-1, -1, newStack));
}
}

}

@Override
Expand Down Expand Up @@ -437,40 +456,48 @@ public ItemStack addToPlayer(ItemStack stack)
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotIndex)
{
Slot slot = this.inventorySlots.get(slotIndex);

if (slot == null || !slot.getHasStack())
{
return null;
}

if (slotIndex < FakeSlots)
{
// Shouldn't even happen, handled above.
return null;
}
else
{
Slot slot = this.inventorySlots.get(slotIndex);
if (slot == null || !slot.getHasStack())
{
return null;
}

IInventoryAutomation parent = tile.getAutomation();
if (parent == null)
return null;

ItemStack stack = slot.getStack();
ItemStack stackCopy = stack.copy();

ItemStack remaining = parent.insertItems(stack);

if (remaining != null)
{
if (remaining.stackSize != stack.stackSize)
tile.markDirty();
if (remaining.stackSize == stackCopy.stackSize)
{
return null;
}

tile.markDirty();
stack.stackSize = remaining.stackSize;
slot.onSlotChanged();
}
else
{
tile.markDirty();
stack.stackSize = 0;
slot.putStack(null);
}

slot.putStack(remaining);

return remaining;
slot.onPickupFromSlot(player, stack);
return stackCopy;
}
}

Expand Down

0 comments on commit 64424a1

Please sign in to comment.