Merge branch 'development' of https://bitbucket.org/calclavia/resonant-induction into development
This commit is contained in:
commit
1c7724933d
3 changed files with 117 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,107 @@
|
|||
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
|
||||
|
||||
import scala.util.control.Breaks._
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
scala.util.control.Breaks.breakable
|
||||
{
|
||||
var index: Int = 0
|
||||
while (index < shuffledDirs.toArray().size)
|
||||
{
|
||||
targetNode = prevNode.clone().translate(ForgeDirection.getOrientation(index))
|
||||
val tile: TileEntity = targetNode.getTileEntity(world())
|
||||
if (tile.isInstanceOf[IInventory])
|
||||
{
|
||||
hasInventoriesAround = true
|
||||
scala.util.control.Breaks.break()
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
if (!targetNode.equals(prevNode) && hasInventoriesAround)
|
||||
{
|
||||
val inv: IInventory = targetNode.getTileEntity(world()).asInstanceOf[IInventory]
|
||||
callAction(inv)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
var index = 0
|
||||
while (index < 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)
|
||||
}
|
||||
index += 1
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue