mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 18:30:27 -04:00
Changed GeolyzerEvent.Analyze to take an absolute position instead of the side of the host for more flexibility.
This commit is contained in:
parent
9c86caa7da
commit
578df68bc7
@ -3,7 +3,6 @@ package li.cil.oc.api.event;
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import cpw.mods.fml.common.eventhandler.Event;
|
||||
import li.cil.oc.api.driver.EnvironmentHost;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -71,18 +70,22 @@ public abstract class GeolyzerEvent extends Event {
|
||||
*/
|
||||
public static class Analyze extends GeolyzerEvent {
|
||||
/**
|
||||
* The side of the geolyzer on which the block to scan is located.
|
||||
* The position of the block to scan.
|
||||
* <p/>
|
||||
* Note: get the world via the host if you need it.
|
||||
*/
|
||||
public final ForgeDirection side;
|
||||
public final int x, y, z;
|
||||
|
||||
/**
|
||||
* The retrieved data for the block being scanned.
|
||||
*/
|
||||
public final Map<String, Object> data = new HashMap<String, Object>();
|
||||
|
||||
public Analyze(EnvironmentHost host, Map<?, ?> options, ForgeDirection side) {
|
||||
public Analyze(EnvironmentHost host, Map<?, ?> options, int x, int y, int z) {
|
||||
super(host, options);
|
||||
this.side = side;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ object GeolyzerHandler {
|
||||
@SubscribeEvent
|
||||
def onGeolyzerAnalyze(e: GeolyzerEvent.Analyze) {
|
||||
val world = e.host.world
|
||||
val blockPos = BlockPosition(e.host).offset(e.side)
|
||||
val blockPos = BlockPosition(e.x, e.y, e.z, world)
|
||||
val block = world.getBlock(blockPos)
|
||||
|
||||
e.data += "name" -> Block.blockRegistry.getNameForObject(block)
|
||||
|
@ -1,6 +1,5 @@
|
||||
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
|
||||
@ -17,7 +16,6 @@ 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
|
||||
@ -65,7 +63,8 @@ class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment {
|
||||
if (!node.tryChangeBuffer(-Settings.get.geolyzerScanCost))
|
||||
return result(Unit, "not enough energy")
|
||||
|
||||
val event = new Analyze(host, options, globalSide)
|
||||
val globalPos = BlockPosition(host).offset(globalSide)
|
||||
val event = new Analyze(host, options, globalPos.x, globalPos.y, globalPos.z)
|
||||
MinecraftForge.EVENT_BUS.post(event)
|
||||
if (event.isCanceled) result(Unit, "scan was canceled")
|
||||
else result(event.data)
|
||||
@ -106,30 +105,15 @@ class Geolyzer(val host: EnvironmentHost) extends prefab.ManagedEnvironment {
|
||||
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))
|
||||
val event = new Analyze(host, Map.empty[AnyRef, AnyRef], blockPos.x, blockPos.y, blockPos.z)
|
||||
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.
|
||||
}
|
||||
}
|
||||
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.
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user