Now pushes topleft stack instead of bottom one
Does not manipulate client inventory in SMP
Code cleanup
Closes #47
This commit is contained in:
Krapht 2012-06-06 13:17:33 +02:00
parent 8eda6c45d8
commit f4409810d6
3 changed files with 17 additions and 29 deletions

View file

@ -18,17 +18,13 @@ public class InventoryUtil {
for (int i = 0; i < _inventory.getSizeInventory(); i++) {
ItemStack stack = _inventory.getStackInSlot(i);
if (stack == null) {
totalRoom += Math.min(_inventory.getInventoryStackLimit(),
itemToTest.getMaxStackSize());
totalRoom += Math.min(_inventory.getInventoryStackLimit(), itemToTest.getMaxStackSize());
continue;
}
if (itemToTest.itemID != stack.itemID
|| (!itemToTest.getItem().isDamageable() && itemToTest
.getItemDamage() != stack.getItemDamage()))
if (itemToTest.itemID != stack.itemID || (!itemToTest.getItem().isDamageable() && itemToTest.getItemDamage() != stack.getItemDamage()))
continue;
totalRoom += (Math.min(_inventory.getInventoryStackLimit(),
itemToTest.getMaxStackSize()) - stack.stackSize);
totalRoom += (Math.min(_inventory.getInventoryStackLimit(), itemToTest.getMaxStackSize()) - stack.stackSize);
}
return totalRoom;
}
@ -56,11 +52,8 @@ public class InventoryUtil {
_inventory.setInventorySlotContents(i, stackToMove);
return null;
}
if (stackToMove.itemID == stack.itemID
&& (stackToMove.getItem().isDamageable() || stackToMove
.getItemDamage() == stack.getItemDamage())) {
if (stackToMove.stackSize + stack.stackSize <= stack
.getMaxStackSize()) {
if (stackToMove.itemID == stack.itemID && (stackToMove.getItem().isDamageable() || stackToMove.getItemDamage() == stack.getItemDamage())) {
if (stackToMove.stackSize + stack.stackSize <= stack.getMaxStackSize()) {
stack.stackSize += stackToMove.stackSize;
return null;
}

View file

@ -17,10 +17,10 @@ public class ContainerHopper extends BuildCraftContainer {
hopper = tile;
// Adding hopper inventory
addSlot(new Slot(tile, 3, 62, 18));
addSlot(new Slot(tile, 2, 80, 18));
addSlot(new Slot(tile, 1, 98, 18));
addSlot(new Slot(tile, 0, 80, 36));
addSlot(new Slot(tile, 0, 62, 18));
addSlot(new Slot(tile, 1, 80, 18));
addSlot(new Slot(tile, 2, 98, 18));
addSlot(new Slot(tile, 3, 80, 36));
// Player inventory
for (int i1 = 0; i1 < 3; i1++)

View file

@ -5,6 +5,7 @@ import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.TileEntity;
import net.minecraft.src.buildcraft.api.APIProxy;
import net.minecraft.src.buildcraft.api.ISpecialInventory;
import net.minecraft.src.buildcraft.api.Orientations;
import net.minecraft.src.buildcraft.core.TileBuildCraft;
@ -15,10 +16,8 @@ import net.minecraft.src.forge.ISidedInventory;
public class TileHopper extends TileBuildCraft implements IInventory {
private final SimpleInventory _inventory = new SimpleInventory(4, "Hopper",
64);
private final InventoryUtil _internalInventory = new InventoryUtil(
_inventory);
private final SimpleInventory _inventory = new SimpleInventory(4, "Hopper", 64);
private final InventoryUtil _internalInventory = new InventoryUtil(_inventory);
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {
@ -38,19 +37,17 @@ public class TileHopper extends TileBuildCraft implements IInventory {
@Override
public void updateEntity() {
super.updateEntity();
if (worldObj.getWorldTime() % 5 != 0)
if (APIProxy.isClient(worldObj) || worldObj.getWorldTime() % 5 != 0)
return;
int internalSlot = _internalInventory.getIdForFirstSlot();
if (internalSlot < 0)
return;
TileEntity tile = this.worldObj.getBlockTileEntity(xCoord, yCoord - 1,
zCoord);
TileEntity tile = this.worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord);
if (tile instanceof ISpecialInventory) {
ISpecialInventory special = (ISpecialInventory) tile;
ItemStack clonedStack = _inventory.getStackInSlot(internalSlot)
.copy().splitStack(1);
ItemStack clonedStack = _inventory.getStackInSlot(internalSlot).copy().splitStack(1);
if (special.addItem(clonedStack, true, Orientations.YPos)) {
_inventory.decrStackSize(internalSlot, 1);
}
@ -61,13 +58,11 @@ public class TileHopper extends TileBuildCraft implements IInventory {
return;
IInventory inventory = (IInventory) tile;
if (tile instanceof ISidedInventory) {
inventory = new SidedInventoryAdapter((ISidedInventory) tile,
Orientations.YPos);
inventory = new SidedInventoryAdapter((ISidedInventory) tile, Orientations.YPos);
}
InventoryUtil externalInventory = new InventoryUtil(inventory);
if (externalInventory.hasRoomForItem(_inventory
.getStackInSlot(internalSlot))) {
if (externalInventory.hasRoomForItem(_inventory.getStackInSlot(internalSlot))) {
ItemStack stackToMove = _inventory.decrStackSize(internalSlot, 1);
externalInventory.addToInventory(stackToMove);
}