Fixed up TileDistributor foreach loops and casing errors

This commit is contained in:
tgame14 2014-03-25 20:34:42 +02:00
parent 9e7a346406
commit c72b87a006

View file

@ -8,9 +8,13 @@ import net.minecraft.inventory.IInventory
import net.minecraftforge.common.ForgeDirection import net.minecraftforge.common.ForgeDirection
import calclavia.lib.utility.inventory.InventoryUtility import calclavia.lib.utility.inventory.InventoryUtility
import net.minecraft.item.ItemStack import net.minecraft.item.ItemStack
import java.util.Collections import java.util.Collections
import java.util import java.util
import scala.util.control.Breaks._
import net.minecraft.tileentity.TileEntity
/** /**
* A Block that interacts with connected inventories * A Block that interacts with connected inventories
* *
@ -31,18 +35,26 @@ class TileDistributor extends TileBase(Material.rock) with TraitInventory with T
Collections.shuffle(shuffledDirs) Collections.shuffle(shuffledDirs)
var hasInventoriesAround = false var hasInventoriesAround = false
for (dir: ForgeDirection <- shuffledDirs)
scala.util.control.Breaks.breakable
{ {
targetNode = prevNode.clone().translate(ForgeDirection.getOrientation(world().rand.nextInt(6))) var index: Int = 0
if (!(targetNode.getTileEntity(world()) isInstanceOf IInventory)) while (index < shuffledDirs.toArray().size)
{ {
hasInventoriesAround = true targetNode = prevNode.clone().translate(ForgeDirection.getOrientation(index))
break val tile: TileEntity = targetNode.getTileEntity(world())
if (tile.isInstanceOf[IInventory])
{
hasInventoriesAround = true
scala.util.control.Breaks.break()
}
index += 1
} }
} }
if (!targetNode.equals(prevNode) && hasInventoriesAround) if (!targetNode.equals(prevNode) && hasInventoriesAround)
{ {
callAction(targetNode.getTileEntity()) val inv: IInventory = targetNode.getTileEntity(world()).asInstanceOf[IInventory]
callAction(inv)
} }
else else
@ -70,8 +82,8 @@ class TileDistributor extends TileBase(Material.rock) with TraitInventory with T
InventoryUtility.putStackInInventory(this, InventoryUtility.takeTopItemFromInventory(inv, ForgeDirection.UP.ordinal()), false) InventoryUtility.putStackInInventory(this, InventoryUtility.takeTopItemFromInventory(inv, ForgeDirection.UP.ordinal()), false)
return return
} }
var index = 0
for (index: Int <- inv.getSizeInventory) while (index < inv.getSizeInventory)
{ {
if (inv.getStackInSlot(index) != null && inv.getStackInSlot(index).isItemEqual(filterStack)) if (inv.getStackInSlot(index) != null && inv.getStackInSlot(index).isItemEqual(filterStack))
{ {
@ -85,6 +97,7 @@ class TileDistributor extends TileBase(Material.rock) with TraitInventory with T
inv.getStackInSlot(index).stackSize -= removeAmount inv.getStackInSlot(index).stackSize -= removeAmount
InventoryUtility.putStackInInventory(this, inv.getStackInSlot(index), false) InventoryUtility.putStackInInventory(this, inv.getStackInSlot(index), false)
} }
index += 1
} }