mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-08-04 03:27:19 -04:00
Made tractor beam upgrade work in tablets and added pfx.
This commit is contained in:
parent
4c379bdc37
commit
e75b25c06e
@ -47,8 +47,11 @@ class Tablet(val parent: Delegator) extends Delegate {
|
|||||||
iconOff = Option(iconRegister.registerIcon(Settings.resourceDomain + ":TabletOff"))
|
iconOff = Option(iconRegister.registerIcon(Settings.resourceDomain + ":TabletOff"))
|
||||||
}
|
}
|
||||||
|
|
||||||
override def update(stack: ItemStack, world: World, player: Entity, slot: Int, selected: Boolean) =
|
override def update(stack: ItemStack, world: World, entity: Entity, slot: Int, selected: Boolean) =
|
||||||
Tablet.get(stack, player).update(world, player, slot, selected)
|
entity match {
|
||||||
|
case player: EntityPlayer => Tablet.get(stack, player).update(world, player, slot, selected)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
|
||||||
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer) = {
|
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer) = {
|
||||||
if (!player.isSneaking) {
|
if (!player.isSneaking) {
|
||||||
@ -68,7 +71,7 @@ class Tablet(val parent: Delegator) extends Delegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TabletWrapper(var stack: ItemStack, var holder: Entity) extends ComponentInventory with Container with Owner with Rotatable {
|
class TabletWrapper(var stack: ItemStack, var holder: EntityPlayer) extends ComponentInventory with Container with Owner with Rotatable {
|
||||||
lazy val computer = if (holder.worldObj.isRemote) null else Machine.create(this)
|
lazy val computer = if (holder.worldObj.isRemote) null else Machine.create(this)
|
||||||
|
|
||||||
val data = new TabletData()
|
val data = new TabletData()
|
||||||
@ -232,7 +235,7 @@ class TabletWrapper(var stack: ItemStack, var holder: Entity) extends ComponentI
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
def update(world: World, player: Entity, slot: Int, selected: Boolean) {
|
def update(world: World, player: EntityPlayer, slot: Int, selected: Boolean) {
|
||||||
holder = player
|
holder = player
|
||||||
if (!world.isRemote) {
|
if (!world.isRemote) {
|
||||||
computer.node.asInstanceOf[Connector].changeBuffer(500)
|
computer.node.asInstanceOf[Connector].changeBuffer(500)
|
||||||
@ -254,7 +257,7 @@ class TabletWrapper(var stack: ItemStack, var holder: Entity) extends ComponentI
|
|||||||
}
|
}
|
||||||
|
|
||||||
object Tablet extends ITickHandler {
|
object Tablet extends ITickHandler {
|
||||||
def get(stack: ItemStack, holder: Entity) = {
|
def get(stack: ItemStack, holder: EntityPlayer) = {
|
||||||
if (holder.worldObj.isRemote) Client.get(stack, holder)
|
if (holder.worldObj.isRemote) Client.get(stack, holder)
|
||||||
else Server.get(stack, holder)
|
else Server.get(stack, holder)
|
||||||
}
|
}
|
||||||
@ -291,9 +294,9 @@ object Tablet extends ITickHandler {
|
|||||||
// To allow access in cache entry init.
|
// To allow access in cache entry init.
|
||||||
private var currentStack: ItemStack = _
|
private var currentStack: ItemStack = _
|
||||||
|
|
||||||
private var currentHolder: Entity = _
|
private var currentHolder: EntityPlayer = _
|
||||||
|
|
||||||
def get(stack: ItemStack, holder: Entity) = {
|
def get(stack: ItemStack, holder: EntityPlayer) = {
|
||||||
if (!stack.hasTagCompound) {
|
if (!stack.hasTagCompound) {
|
||||||
stack.setTagCompound(new NBTTagCompound())
|
stack.setTagCompound(new NBTTagCompound())
|
||||||
}
|
}
|
||||||
|
@ -2,22 +2,23 @@ package li.cil.oc.server.component
|
|||||||
|
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api.Network
|
import li.cil.oc.api.Network
|
||||||
import li.cil.oc.api.machine.Robot
|
import li.cil.oc.api.driver.Container
|
||||||
import li.cil.oc.api.network.{Arguments, Callback, Context, Visibility}
|
import li.cil.oc.api.network.{Arguments, Callback, Context, Visibility}
|
||||||
import li.cil.oc.common.component
|
import li.cil.oc.common.component
|
||||||
import net.minecraft.entity.item.EntityItem
|
import net.minecraft.entity.item.EntityItem
|
||||||
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.util.AxisAlignedBB
|
import net.minecraft.util.AxisAlignedBB
|
||||||
|
|
||||||
import scala.collection.convert.WrapAsScala._
|
import scala.collection.convert.WrapAsScala._
|
||||||
|
|
||||||
class UpgradeTractorBeam(owner: Robot) extends component.ManagedComponent {
|
class UpgradeTractorBeam(owner: Container, player: () => EntityPlayer) extends component.ManagedComponent {
|
||||||
val node = Network.newNode(this, Visibility.Network).
|
val node = Network.newNode(this, Visibility.Network).
|
||||||
withComponent("tractor_beam").
|
withComponent("tractor_beam").
|
||||||
create()
|
create()
|
||||||
|
|
||||||
private val pickupRadius = 3
|
private val pickupRadius = 3
|
||||||
|
|
||||||
private def world = owner.player.getEntityWorld
|
private def world = owner.world
|
||||||
|
|
||||||
@Callback(doc = """function():boolean -- Tries to pick up a random item in the robots' vicinity.""")
|
@Callback(doc = """function():boolean -- Tries to pick up a random item in the robots' vicinity.""")
|
||||||
def suck(context: Context, args: Arguments): Array[AnyRef] = {
|
def suck(context: Context, args: Arguments): Array[AnyRef] = {
|
||||||
@ -28,9 +29,10 @@ class UpgradeTractorBeam(owner: Robot) extends component.ManagedComponent {
|
|||||||
val item = items(world.rand.nextInt(items.size))
|
val item = items(world.rand.nextInt(items.size))
|
||||||
val stack = item.getEntityItem
|
val stack = item.getEntityItem
|
||||||
val size = stack.stackSize
|
val size = stack.stackSize
|
||||||
item.onCollideWithPlayer(owner.player)
|
item.onCollideWithPlayer(player())
|
||||||
if (stack.stackSize < size || item.isDead) {
|
if (stack.stackSize < size || item.isDead) {
|
||||||
context.pause(Settings.get.suckDelay)
|
context.pause(Settings.get.suckDelay)
|
||||||
|
world.playAuxSFX(2003, math.floor(item.posX).toInt, math.floor(item.posY).toInt, math.floor(item.posZ).toInt, 0)
|
||||||
return result(true)
|
return result(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,7 +40,7 @@ class UpgradeTractorBeam(owner: Robot) extends component.ManagedComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def pickupBounds = {
|
private def pickupBounds = {
|
||||||
val player = owner.player
|
val player = this.player()
|
||||||
val x = player.posX
|
val x = player.posX
|
||||||
val y = player.posY
|
val y = player.posY
|
||||||
val z = player.posZ
|
val z = player.posZ
|
||||||
|
@ -4,6 +4,7 @@ import li.cil.oc.api
|
|||||||
import li.cil.oc.api.driver.{Container, Slot}
|
import li.cil.oc.api.driver.{Container, Slot}
|
||||||
import li.cil.oc.api.machine.Robot
|
import li.cil.oc.api.machine.Robot
|
||||||
import li.cil.oc.common.Tier
|
import li.cil.oc.common.Tier
|
||||||
|
import li.cil.oc.common.item.TabletWrapper
|
||||||
import li.cil.oc.server.component
|
import li.cil.oc.server.component
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
|
|
||||||
@ -11,7 +12,8 @@ object UpgradeTractorBeam extends Item {
|
|||||||
override def worksWith(stack: ItemStack) = isOneOf(stack, api.Items.get("tractorBeamUpgrade"))
|
override def worksWith(stack: ItemStack) = isOneOf(stack, api.Items.get("tractorBeamUpgrade"))
|
||||||
|
|
||||||
override def createEnvironment(stack: ItemStack, container: Container) = container match {
|
override def createEnvironment(stack: ItemStack, container: Container) = container match {
|
||||||
case robot: Robot => new component.UpgradeTractorBeam(robot)
|
case robot: Robot => new component.UpgradeTractorBeam(container, robot.player)
|
||||||
|
case tablet: TabletWrapper => new component.UpgradeTractorBeam(container, () => tablet.holder)
|
||||||
case _ => null
|
case _ => null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user