Added EnumDistributorMode to distinguish between variable modes, Moved TileDistributor to its own Package and Added Functional inventory Scanning and handling, not to be activated till 1.7
This commit is contained in:
parent
5cf5b41dc1
commit
9e7a346406
3 changed files with 104 additions and 14 deletions
|
@ -1,14 +0,0 @@
|
|||
package resonantinduction.electrical
|
||||
|
||||
import calclavia.lib.content.prefab.{TraitElectrical, TraitInventory}
|
||||
import net.minecraft.block.material.Material
|
||||
import calclavia.lib.content.module.TileBase
|
||||
|
||||
/**
|
||||
* @since 22/03/14
|
||||
* @author tgame14
|
||||
*/
|
||||
class TileDistributor extends TileBase(Material.rock) with TraitInventory with TraitElectrical
|
||||
{
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package resonantinduction.electrical.distributor;
|
||||
|
||||
/**
|
||||
* @since 25/03/14
|
||||
* @author tgame14
|
||||
*/
|
||||
public enum EnumDistributorMode
|
||||
{
|
||||
PULL, PUSH
|
||||
}
|
|
@ -0,0 +1,94 @@
|
|||
package resonantinduction.electrical.distributor
|
||||
|
||||
import calclavia.lib.content.prefab.{TraitElectrical, TraitInventory}
|
||||
import net.minecraft.block.material.Material
|
||||
import calclavia.lib.content.module.TileBase
|
||||
import universalelectricity.api.vector.Vector3
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import calclavia.lib.utility.inventory.InventoryUtility
|
||||
import net.minecraft.item.ItemStack
|
||||
import java.util.Collections
|
||||
import java.util
|
||||
|
||||
/**
|
||||
* A Block that interacts with connected inventories
|
||||
*
|
||||
* @since 22/03/14
|
||||
* @author tgame14
|
||||
*/
|
||||
class TileDistributor extends TileBase(Material.rock) with TraitInventory with TraitElectrical
|
||||
{
|
||||
var state: EnumDistributorMode = EnumDistributorMode.PUSH
|
||||
var targetNode: Vector3 = new Vector3(this)
|
||||
|
||||
override def updateEntity(): Unit =
|
||||
{
|
||||
super.updateEntity()
|
||||
val prevNode = targetNode.clone()
|
||||
|
||||
val shuffledDirs = util.Arrays.asList(ForgeDirection.VALID_DIRECTIONS)
|
||||
Collections.shuffle(shuffledDirs)
|
||||
|
||||
var hasInventoriesAround = false
|
||||
for (dir: ForgeDirection <- shuffledDirs)
|
||||
{
|
||||
targetNode = prevNode.clone().translate(ForgeDirection.getOrientation(world().rand.nextInt(6)))
|
||||
if (!(targetNode.getTileEntity(world()) isInstanceOf IInventory))
|
||||
{
|
||||
hasInventoriesAround = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!targetNode.equals(prevNode) && hasInventoriesAround)
|
||||
{
|
||||
callAction(targetNode.getTileEntity())
|
||||
}
|
||||
|
||||
else
|
||||
targetNode = new Vector3(this)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected def callAction(inv: IInventory)
|
||||
{
|
||||
state match
|
||||
{
|
||||
case EnumDistributorMode.PUSH =>
|
||||
{
|
||||
InventoryUtility.putStackInInventory(inv, getStackInSlot(0), false)
|
||||
}
|
||||
|
||||
case EnumDistributorMode.PULL =>
|
||||
{
|
||||
val filterStack: ItemStack = getStackInSlot(1)
|
||||
if (filterStack == null)
|
||||
{
|
||||
InventoryUtility.putStackInInventory(this, InventoryUtility.takeTopItemFromInventory(inv, ForgeDirection.UP.ordinal()), false)
|
||||
return
|
||||
}
|
||||
|
||||
for (index: Int <- inv.getSizeInventory)
|
||||
{
|
||||
if (inv.getStackInSlot(index) != null && inv.getStackInSlot(index).isItemEqual(filterStack))
|
||||
{
|
||||
var removeAmount = 0
|
||||
|
||||
if (getStackInSlot(0) != null && getStackInSlot(0).isItemEqual(filterStack))
|
||||
{
|
||||
removeAmount = getStackInSlot(0).getItem.getItemStackLimit - getStackInSlot(0).stackSize
|
||||
}
|
||||
|
||||
inv.getStackInSlot(index).stackSize -= removeAmount
|
||||
InventoryUtility.putStackInInventory(this, inv.getStackInSlot(index), false)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue