mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
Right-clicking blocks with tablet in hand will now allow components to populate a data table. If any is given, a tablet_use
signal is sent to the tablet, with the data passed as a table as the only parameter for the signal. Closes #858.
This commit is contained in:
parent
0fdbd38643
commit
5a4dedf6d1
@ -32,9 +32,9 @@ import li.cil.oc.common.Slot
|
||||
import li.cil.oc.common.Tier
|
||||
import li.cil.oc.common.inventory.ComponentInventory
|
||||
import li.cil.oc.common.item.data.TabletData
|
||||
import li.cil.oc.integration.opencomputers.DriverKeyboard
|
||||
import li.cil.oc.integration.opencomputers.DriverScreen
|
||||
import li.cil.oc.server.component
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import li.cil.oc.util.Rarity
|
||||
import li.cil.oc.util.RotationHelper
|
||||
@ -125,6 +125,24 @@ class Tablet(val parent: Delegator) extends Delegate {
|
||||
case _ =>
|
||||
}
|
||||
|
||||
override def onItemUse(stack: ItemStack, player: EntityPlayer, position: BlockPosition, side: Int, hitX: Float, hitY: Float, hitZ: Float): Boolean = {
|
||||
val world = player.getEntityWorld
|
||||
if (!world.isRemote) try {
|
||||
val computer = Tablet.get(stack, player).machine
|
||||
if (computer.isRunning) {
|
||||
val data = new NBTTagCompound()
|
||||
computer.node.sendToReachable("tablet.use", data, stack, player, position, ForgeDirection.getOrientation(side), float2Float(hitX), float2Float(hitY), float2Float(hitZ))
|
||||
if (!data.hasNoTags) {
|
||||
computer.signal("tablet_use", data)
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
case t: Throwable => OpenComputers.log.warn("Block analysis on tablet right click failed gloriously!", t)
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
override def onItemRightClick(stack: ItemStack, world: World, player: EntityPlayer) = {
|
||||
if (!player.isSneaking) {
|
||||
if (world.isRemote) {
|
||||
|
@ -1,26 +1,32 @@
|
||||
package li.cil.oc.server.component
|
||||
|
||||
import com.google.common.base.Strings
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.driver.EnvironmentHost
|
||||
import li.cil.oc.api.event.GeolyzerEvent
|
||||
import li.cil.oc.api.event.GeolyzerEvent.Analyze
|
||||
import li.cil.oc.api.internal.Rotatable
|
||||
import li.cil.oc.api.internal
|
||||
import li.cil.oc.api.machine.Arguments
|
||||
import li.cil.oc.api.machine.Callback
|
||||
import li.cil.oc.api.machine.Context
|
||||
import li.cil.oc.api.network.Message
|
||||
import li.cil.oc.api.network.Visibility
|
||||
import li.cil.oc.api.prefab
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import li.cil.oc.util.DatabaseAccess
|
||||
import li.cil.oc.util.ExtendedArguments._
|
||||
import li.cil.oc.util.ExtendedWorld._
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.Item
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.MinecraftForge
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
import scala.collection.convert.WrapAsJava._
|
||||
import scala.collection.convert.WrapAsScala._
|
||||
|
||||
class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment {
|
||||
override val node = api.Network.newNode(this, Visibility.Network).
|
||||
@ -51,7 +57,7 @@ class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment {
|
||||
def analyze(computer: Context, args: Arguments): Array[AnyRef] = if (Settings.get.allowItemStackInspection) {
|
||||
val side = args.checkSide(0, ForgeDirection.VALID_DIRECTIONS: _*)
|
||||
val globalSide = host match {
|
||||
case rotatable: Rotatable => rotatable.toGlobal(side)
|
||||
case rotatable: internal.Rotatable => rotatable.toGlobal(side)
|
||||
case _ => side
|
||||
}
|
||||
val options = args.optTable(1, Map.empty[AnyRef, AnyRef])
|
||||
@ -70,7 +76,7 @@ class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment {
|
||||
def store(computer: Context, args: Arguments): Array[AnyRef] = {
|
||||
val side = args.checkSide(0, ForgeDirection.VALID_DIRECTIONS: _*)
|
||||
val globalSide = host match {
|
||||
case rotatable: Rotatable => rotatable.toGlobal(side)
|
||||
case rotatable: internal.Rotatable => rotatable.toGlobal(side)
|
||||
case _ => side
|
||||
}
|
||||
|
||||
@ -93,4 +99,41 @@ class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override def onMessage(message: Message): Unit = {
|
||||
super.onMessage(message)
|
||||
if (message.name == "tablet.use") message.source.host match {
|
||||
case machine: api.machine.Machine => (machine.host, message.data) match {
|
||||
case (tablet: internal.Tablet, Array(nbt: NBTTagCompound, stack: ItemStack, player: EntityPlayer, blockPos: BlockPosition, side: ForgeDirection, hitX: java.lang.Float, hitY: java.lang.Float, hitZ: java.lang.Float)) =>
|
||||
if (node.tryChangeBuffer(-Settings.get.geolyzerScanCost)) {
|
||||
// TODO 1.5 replace with event (change event to allow arbitrary coordinates)
|
||||
val world = player.getEntityWorld
|
||||
val block = world.getBlock(blockPos)
|
||||
|
||||
if (!Strings.isNullOrEmpty(Block.blockRegistry.getNameForObject(block))) {
|
||||
nbt.setString("name", Block.blockRegistry.getNameForObject(block))
|
||||
}
|
||||
nbt.setInteger("metadata", world.getBlockMetadata(blockPos))
|
||||
nbt.setFloat("hardness", world.getBlockHardness(blockPos))
|
||||
nbt.setInteger("harvestLevel", world.getBlockHarvestLevel(blockPos))
|
||||
if (!Strings.isNullOrEmpty(world.getBlockHarvestTool(blockPos))) {
|
||||
nbt.setString("harvestTool", world.getBlockHarvestTool(blockPos))
|
||||
}
|
||||
nbt.setInteger("color", world.getBlockMapColor(blockPos).colorValue)
|
||||
|
||||
// val event = new Analyze(host, Map.empty[AnyRef, AnyRef], side)
|
||||
// MinecraftForge.EVENT_BUS.post(event)
|
||||
// if (!event.isCanceled) {
|
||||
// for ((key, value) <- event.data) value match {
|
||||
// case number: java.lang.Number => nbt.setDouble(key, number.doubleValue())
|
||||
// case string: String if !string.isEmpty => nbt.setString(key, string)
|
||||
// case _ => // Unsupported, ignore.
|
||||
// }
|
||||
// }
|
||||
}
|
||||
case _ => // Ignore.
|
||||
}
|
||||
case _ => // Ignore.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,9 @@
|
||||
package li.cil.oc.server.component
|
||||
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.Network
|
||||
import li.cil.oc.api.driver.EnvironmentHost
|
||||
import li.cil.oc.api.internal
|
||||
import li.cil.oc.api.internal.Rotatable
|
||||
import li.cil.oc.api.machine.Arguments
|
||||
import li.cil.oc.api.machine.Callback
|
||||
@ -9,7 +11,11 @@ import li.cil.oc.api.machine.Context
|
||||
import li.cil.oc.api.network._
|
||||
import li.cil.oc.api.prefab
|
||||
import li.cil.oc.common.item.data.NavigationUpgradeData
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
class UpgradeNavigation(val host: EnvironmentHost with Rotatable) extends prefab.ManagedEnvironment {
|
||||
override val node = Network.newNode(this, Visibility.Network).
|
||||
@ -43,6 +49,21 @@ class UpgradeNavigation(val host: EnvironmentHost with Rotatable) extends prefab
|
||||
result(size / 2)
|
||||
}
|
||||
|
||||
override def onMessage(message: Message): Unit = {
|
||||
super.onMessage(message)
|
||||
if (message.name == "tablet.use") message.source.host match {
|
||||
case machine: api.machine.Machine => (machine.host, message.data) match {
|
||||
case (tablet: internal.Tablet, Array(nbt: NBTTagCompound, stack: ItemStack, player: EntityPlayer, blockPos: BlockPosition, side: ForgeDirection, hitX: java.lang.Float, hitY: java.lang.Float, hitZ: java.lang.Float)) =>
|
||||
val info = data.mapData(host.world)
|
||||
nbt.setInteger("posX", blockPos.x - info.xCenter)
|
||||
nbt.setInteger("posY", blockPos.y)
|
||||
nbt.setInteger("posZ", blockPos.z - info.zCenter)
|
||||
case _ => // Ignore.
|
||||
}
|
||||
case _ => // Ignore.
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def load(nbt: NBTTagCompound) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user