Include block drones are in when looking for items to suck in, to make that less awkward.

This commit is contained in:
Florian Nücke 2014-12-15 06:38:58 +01:00
parent fafa9e42ae
commit 95e2feef65
3 changed files with 15 additions and 3 deletions

View File

@ -26,7 +26,6 @@ import net.minecraft.entity.item.EntityItem
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.MovingObjectPosition
import net.minecraft.util.Vec3
import net.minecraft.world.World

View File

@ -8,6 +8,7 @@ import li.cil.oc.api.machine.Context
import li.cil.oc.api.network.Visibility
import li.cil.oc.api.prefab
import li.cil.oc.common.entity
import li.cil.oc.util.BlockPosition
import li.cil.oc.util.ExtendedArguments._
import li.cil.oc.util.InventoryUtils
import net.minecraft.entity.item.EntityItem
@ -45,6 +46,8 @@ class Drone(val host: entity.Drone) extends prefab.ManagedEnvironment with trait
override protected def checkSideForAction(args: Arguments, n: Int) =
args.checkSide(n, ForgeDirection.VALID_DIRECTIONS: _*)
override protected def suckableItems(side: ForgeDirection) = entitiesInBlock(BlockPosition(host)) ++ super.suckableItems(side)
override protected def onSuckCollect(entity: EntityItem) = {
world.playSoundAtEntity(host, "random.pop", 0.2f, ((world.rand.nextFloat - world.rand.nextFloat) * 0.7f + 1) * 2)
InventoryUtils.insertIntoInventory(entity.getEntityItem, inventory, slots = Option(insertionSlots))
@ -52,6 +55,8 @@ class Drone(val host: entity.Drone) extends prefab.ManagedEnvironment with trait
// ----------------------------------------------------------------------- //
// ----------------------------------------------------------------------- //
@Callback(doc = "function(dx:number, dy:number, dz:number) -- Change the target position by the specified offset.")
def move(context: Context, args: Arguments): Array[AnyRef] = {
val dx = args.checkDouble(0).toFloat
@ -67,10 +72,15 @@ class Drone(val host: entity.Drone) extends prefab.ManagedEnvironment with trait
def getOffset(context: Context, args: Arguments): Array[AnyRef] =
result(host.getDistance(host.targetX, host.targetY, host.targetZ))
@Callback(doc = "function():number -- Get the current velocity.")
@Callback(doc = "function():number -- Get the current velocity in m/s.")
def getVelocity(context: Context, args: Arguments): Array[AnyRef] =
result(math.sqrt(host.motionX * host.motionX + host.motionY * host.motionY + host.motionZ * host.motionZ) * 20) // per second
@Callback(doc = "function():number -- Get the maximum velocity, in m/s.")
def getMaxVelocity(context: Context, args: Arguments): Array[AnyRef] = {
result(host.maxVelocity * 20) // per second
}
@Callback(doc = "function():number -- Get the currently set acceleration.")
def getAcceleration(context: Context, args: Arguments): Array[AnyRef] = {
result(host.targetAcceleration * 20) // per second

View File

@ -11,6 +11,7 @@ import li.cil.oc.util.InventoryUtils
import li.cil.oc.util.ResultWrapper.result
import net.minecraft.entity.item.EntityItem
import net.minecraft.item.ItemBlock
import net.minecraftforge.common.util.ForgeDirection
trait InventoryWorldInterop extends InventoryAware with WorldAware with SideRestricted {
@Callback
@ -74,7 +75,7 @@ trait InventoryWorldInterop extends InventoryAware with WorldAware with SideRest
result(true)
}
else {
for (entity <- entitiesOnSide[EntityItem](facing) if !entity.isDead && entity.delayBeforeCanPickup <= 0) {
for (entity <- suckableItems(facing) if !entity.isDead && entity.delayBeforeCanPickup <= 0) {
val stack = entity.getEntityItem
val size = stack.stackSize
onSuckCollect(entity)
@ -87,5 +88,7 @@ trait InventoryWorldInterop extends InventoryAware with WorldAware with SideRest
}
}
protected def suckableItems(side: ForgeDirection) = entitiesOnSide[EntityItem](side)
protected def onSuckCollect(entity: EntityItem): Unit = entity.onCollideWithPlayer(fakePlayer)
}