mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 17:56:34 -04:00
created locator
made components use context instead of owner
This commit is contained in:
parent
d49040945a
commit
c66ecb0f1e
@ -91,6 +91,7 @@ oc:tooltip.Generator=Kann verwendet werden um unterwegs Energie aus Brennstoffen
|
||||
oc:tooltip.GraphicsCard=Erlaubt es den angezeigten Inhalt von Bildschirmen zu ändern.[nl] Höchstauflösung: §f%sx%s§7.[nl] Maximale Farbtiefe: §f%s§7.[nl] Operationen/Tick: §f%s§7.
|
||||
oc:tooltip.IronNugget=Ein Nugget das aus Eisen besteht, darum wird es ja auch Eisennugget genannt, duh...
|
||||
oc:tooltip.Keyboard=Kann an Bildschirmen befestigt werden um auf ihnen zu tippen.
|
||||
oc:tooltip.Locator=Kann benutzt werden um die Position des Robters zu bestimmen. Die Position ist relativ zur Mitte der Karte, die im Locator verbaut wurde.
|
||||
oc:tooltip.Memory=Braucht ein jeder Computer um zu starten. Je mehr vorhanden, desto komplexere Programme können ausgeführt werden.
|
||||
oc:tooltip.Microchip=Tritt auch unter dem Alias Integrierter Schaltkreis auf. Keine Ahnung warum das auch mit Redstone klappt, aber es funktioniert.
|
||||
oc:tooltip.NetworkCard=Erlaubt es Computern die über mehrere Blöcke miteinander verbunden sind (z.B. Kabel) mittels Netzwerknachrichten zu kommunizieren.
|
||||
|
@ -42,6 +42,7 @@ oc:item.GraphicsCard2.name=Superior Graphics Card
|
||||
oc:item.Acid.name=Grog
|
||||
oc:item.HardDiskDrive.name=Hard Disk Drive
|
||||
oc:item.IronNugget.name=Iron Nugget
|
||||
oc:item.Locator.name=Locator
|
||||
oc:item.Memory.name=Memory
|
||||
oc:item.Microchip0.name=Simple Microchip
|
||||
oc:item.Microchip1.name=Advanced Microchip
|
||||
@ -96,6 +97,7 @@ oc:tooltip.Generator=Can be used to generate energy from fuel on the go. Burns i
|
||||
oc:tooltip.GraphicsCard=Used to change what's displayed on screens.[nl] Maximum resolution: §f%sx%s§7.[nl] Maximum color depth: §f%s§7.[nl] Operations/tick: §f%s§7.
|
||||
oc:tooltip.IronNugget=A nugget made of iron, that's why it's called an Iron Nugget, duh...
|
||||
oc:tooltip.Keyboard=Can be attached to screens to allow typing on them.
|
||||
oc:tooltip.Locator=Can be used to identify the position of the Robot. The position is relative to the center of the Map that is built in to the Locator.
|
||||
oc:tooltip.Memory=Required to get computers to run. The more you have, the more complex the programs you can run.
|
||||
oc:tooltip.Microchip=The chip formerly known as Integrated Circuit. I have no idea why this works with redstone, but it does.
|
||||
oc:tooltip.NetworkCard=Allows distant computers connected by other blocks (such as cable) to communicate by sending messages to each other.
|
||||
|
@ -3,7 +3,10 @@ package li.cil.oc
|
||||
import cpw.mods.fml.common.ICraftingHandler
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.IInventory
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraft.item.{ItemMap, Item, ItemStack}
|
||||
import net.minecraftforge.oredict.OreDictionary
|
||||
import net.minecraft.world.storage.MapInfo
|
||||
import li.cil.oc.server.driver.Registry
|
||||
|
||||
object CraftingHandler extends ICraftingHandler {
|
||||
override def onCrafting(player: EntityPlayer, craftedStack: ItemStack, inventory: IInventory) = {
|
||||
@ -28,6 +31,26 @@ object CraftingHandler extends ICraftingHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!player.getEntityWorld.isRemote&&craftedStack.isItemEqual(Items.locator.createItemStack())) {
|
||||
for (i <- 0 to inventory.getSizeInventory) {
|
||||
val stack = inventory.getStackInSlot(i)
|
||||
if(stack != null && stack.getItem== Item.map)
|
||||
{
|
||||
var map = stack.getItem.asInstanceOf[ItemMap]
|
||||
val info = map.getMapData(stack, player.getEntityWorld)
|
||||
|
||||
val nbt = Registry.driverFor(craftedStack) match {
|
||||
case Some(driver)=>driver.dataTag(craftedStack)
|
||||
case _ => null
|
||||
}
|
||||
nbt.setInteger(Settings.namespace +"xCenter",info.xCenter)
|
||||
nbt.setInteger(Settings.namespace +"xCenter",info.zCenter)
|
||||
nbt.setInteger(Settings.namespace +"scale",128*(1<<info.scale))
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def onSmelting(player: EntityPlayer, item: ItemStack) {}
|
||||
|
@ -33,6 +33,7 @@ object Items {
|
||||
var generator: item.Generator = null
|
||||
var solarGenerator: item.SolarGenerator = null
|
||||
var reader:item.Reader = null
|
||||
var locator:item.Locator = null
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
// Crafting
|
||||
@ -108,6 +109,7 @@ object Items {
|
||||
//new for next release
|
||||
solarGenerator = new item.SolarGenerator(multi)
|
||||
reader = new item.Reader(multi)
|
||||
locator = new item.Locator(multi)
|
||||
|
||||
OreDictionary.registerOre("nuggetIron", ironNugget.createItemStack())
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import cpw.mods.fml.common.registry.GameRegistry
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.item.crafting.FurnaceRecipes
|
||||
import net.minecraft.item.{Item, ItemStack}
|
||||
import net.minecraftforge.oredict.{ShapelessOreRecipe, ShapedOreRecipe}
|
||||
import net.minecraftforge.oredict.{OreDictionary, ShapelessOreRecipe, ShapedOreRecipe}
|
||||
|
||||
object Recipes {
|
||||
def init() {
|
||||
@ -79,7 +79,7 @@ object Recipes {
|
||||
FurnaceRecipes.smelting().addSmelting(rawBoard.itemID, rawBoard.getItemDamage, board, 0)
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(acid, Item.bucketWater, sugar, roseRed, slimeBall, spiderEye, boneMeal))
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(pcb, acid, Item.goldNugget, board))
|
||||
|
||||
GameRegistry.addRecipe(new ShapelessOreRecipe(Items.locator.createItemStack(),new ItemStack(Item.map,1,OreDictionary.WILDCARD_VALUE),pcb) )
|
||||
addRecipe(ironIngot,
|
||||
"xxx",
|
||||
"xxx",
|
||||
@ -486,6 +486,8 @@ object Recipes {
|
||||
'b', pcb)
|
||||
}
|
||||
|
||||
|
||||
|
||||
private def addRecipe(output: ItemStack, args: Any*) = {
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(output, args.map(_.asInstanceOf[AnyRef]): _*))
|
||||
}
|
||||
|
@ -32,6 +32,7 @@ class Proxy {
|
||||
api.Driver.add(driver.item.Generator)
|
||||
api.Driver.add(driver.item.SolarGenerator)
|
||||
api.Driver.add(driver.item.GraphicsCard)
|
||||
api.Driver.add(driver.item.Locator)
|
||||
api.Driver.add(driver.item.Memory)
|
||||
api.Driver.add(driver.item.NetworkCard)
|
||||
api.Driver.add(driver.item.Reader)
|
||||
|
28
li/cil/oc/common/item/Locator.scala
Normal file
28
li/cil/oc/common/item/Locator.scala
Normal file
@ -0,0 +1,28 @@
|
||||
package li.cil.oc.common.item
|
||||
|
||||
import java.util
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.util.Tooltip
|
||||
import net.minecraft.client.renderer.texture.IconRegister
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.{EnumRarity, ItemStack}
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.server.driver.Registry
|
||||
|
||||
class Locator(val parent: Delegator) extends Delegate {
|
||||
val unlocalizedName = "Locator"
|
||||
|
||||
override def rarity = EnumRarity.epic
|
||||
|
||||
override def tooltipLines(stack: ItemStack, player: EntityPlayer, tooltip: util.List[String], advanced: Boolean) {
|
||||
tooltip.addAll(Tooltip.get(unlocalizedName, (Settings.get.generatorEfficiency * 100).toInt))
|
||||
super.tooltipLines(stack, player, tooltip, advanced)
|
||||
}
|
||||
|
||||
override def registerIcons(iconRegister: IconRegister) = {
|
||||
super.registerIcons(iconRegister)
|
||||
|
||||
icon = iconRegister.registerIcon(Settings.resourceDomain + ":upgrade_locator")
|
||||
}
|
||||
|
||||
}
|
50
li/cil/oc/server/component/Locator.scala
Normal file
50
li/cil/oc/server/component/Locator.scala
Normal file
@ -0,0 +1,50 @@
|
||||
package li.cil.oc.server.component
|
||||
|
||||
import li.cil.oc.api.network._
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import li.cil.oc.{Settings, api}
|
||||
import net.minecraft.entity.item.EntityItem
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.{TileEntity => MCTileEntity, TileEntitySign, TileEntityFurnace}
|
||||
import scala.Some
|
||||
import li.cil.oc.common.tileentity.Rotatable
|
||||
import li.cil.oc.util.RotationHelper
|
||||
|
||||
class Locator(val owner: MCTileEntity, val xCenter: Int, val zCenter: Int,val scale:Int) extends ManagedComponent {
|
||||
val node = api.Network.newNode(this, Visibility.Network).
|
||||
withComponent("locator", Visibility.Neighbors).
|
||||
|
||||
create()
|
||||
|
||||
@LuaCallback("getPosition")
|
||||
def getPosition(context: RobotContext, args: Arguments): Array[AnyRef] = {
|
||||
val player = context.player()
|
||||
println("start: "+xCenter+","+zCenter)
|
||||
val x = player.posX.floor.toInt
|
||||
val z = player.posZ.floor.toInt
|
||||
println("curr: "+x+","+z)
|
||||
val xDist = x - xCenter
|
||||
val zDist = z - zCenter
|
||||
|
||||
if (math.abs(xDist) <= scale/2 && math.abs(zDist) <= scale/2)
|
||||
result(xDist, zDist)
|
||||
else
|
||||
result(Unit, "out of range")
|
||||
}
|
||||
@LuaCallback("getFacing")
|
||||
def getFacing(context: RobotContext, args: Arguments): Array[AnyRef] = {
|
||||
val player = context.player()
|
||||
val d = RotationHelper.fromYaw(player.rotationYaw)
|
||||
|
||||
result(d.offsetX,d.offsetY,d.offsetZ)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override val canUpdate = false
|
||||
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
}
|
@ -9,6 +9,9 @@ import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.tileentity.{TileEntity => MCTileEntity, TileEntitySign, TileEntityFurnace}
|
||||
import scala.Some
|
||||
import li.cil.oc.common.tileentity.Rotatable
|
||||
import li.cil.oc.util.RotationHelper._
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
import li.cil.oc.util.RotationHelper
|
||||
|
||||
class Reader(val owner: MCTileEntity) extends ManagedComponent {
|
||||
val node = api.Network.newNode(this, Visibility.Network).
|
||||
@ -21,48 +24,43 @@ class Reader(val owner: MCTileEntity) extends ManagedComponent {
|
||||
|
||||
@LuaCallback("read")
|
||||
def read(context: RobotContext, args: Arguments): Array[AnyRef] = {
|
||||
owner match {
|
||||
case rotatable: Rotatable => {
|
||||
val te = rotatable.getWorldObj.getBlockTileEntity(rotatable.xCoord+rotatable.facing.offsetX,rotatable.yCoord+rotatable.facing.offsetY,rotatable.zCoord+rotatable.facing.offsetZ)
|
||||
te match{
|
||||
case sign:TileEntitySign=>{
|
||||
val text = sign.signText.mkString("\n")
|
||||
val player = context.player()
|
||||
val d = RotationHelper.fromYaw(player.rotationYaw)
|
||||
val te = player.getEntityWorld.getBlockTileEntity(player.posX.floor.toInt + d.offsetX, player.posY.floor.toInt + d.offsetY, player.posZ.floor.toInt + d.offsetZ)
|
||||
te match {
|
||||
case sign: TileEntitySign => {
|
||||
val text = sign.signText.mkString("\n")
|
||||
|
||||
return result(text)
|
||||
}
|
||||
case _=>
|
||||
}
|
||||
return result(text)
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
|
||||
result(Unit, "no sign")
|
||||
}
|
||||
|
||||
@LuaCallback("write")
|
||||
def write(context: Context, args: Arguments): Array[AnyRef] = {
|
||||
owner match {
|
||||
case rotatable: Rotatable => {
|
||||
val te = rotatable.getWorldObj.getBlockTileEntity(rotatable.xCoord+rotatable.facing.offsetX,rotatable.yCoord+rotatable.facing.offsetY,rotatable.zCoord+rotatable.facing.offsetZ)
|
||||
te match{
|
||||
case sign:TileEntitySign=>{
|
||||
def write(context: RobotContext, args: Arguments): Array[AnyRef] = {
|
||||
val player = context.player()
|
||||
val d = RotationHelper.fromYaw(player.rotationYaw)
|
||||
val te = player.getEntityWorld.getBlockTileEntity(player.posX.floor.toInt + d.offsetX, player.posY.floor.toInt + d.offsetY, player.posZ.floor.toInt + d.offsetZ)
|
||||
te match {
|
||||
case sign: TileEntitySign => {
|
||||
val text = args.checkString(0).split("\n")
|
||||
val number = Math.min(4,text.size)
|
||||
for(i <-0 to number-1){
|
||||
val number = Math.min(4, text.size)
|
||||
for (i <- 0 to number - 1) {
|
||||
var line = text(i)
|
||||
if(line.size>15){
|
||||
line = line.substring(0,15)
|
||||
if (line.size > 15) {
|
||||
line = line.substring(0, 15)
|
||||
}
|
||||
sign.signText(i)= line
|
||||
sign.signText(i) = line
|
||||
}
|
||||
|
||||
sign.worldObj.markBlockForUpdate(rotatable.xCoord+rotatable.facing.offsetX,rotatable.yCoord+rotatable.facing.offsetY,rotatable.zCoord+rotatable.facing.offsetZ)
|
||||
sign.worldObj.markBlockForUpdate(player.posX.floor.toInt + d.offsetX, player.posY.floor.toInt + d.offsetY, player.posZ.floor.toInt + d.offsetZ)
|
||||
return result(true)
|
||||
}
|
||||
case _=>
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
result(Unit, "no sign")
|
||||
}
|
||||
|
||||
|
28
li/cil/oc/server/driver/item/Locator.scala
Normal file
28
li/cil/oc/server/driver/item/Locator.scala
Normal file
@ -0,0 +1,28 @@
|
||||
package li.cil.oc.server.driver.item
|
||||
|
||||
import li.cil.oc.{Settings, Items}
|
||||
import li.cil.oc.api.driver.Slot
|
||||
import li.cil.oc.server.component
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.tileentity.{TileEntity => MCTileEntity}
|
||||
import li.cil.oc.server.driver.Registry
|
||||
|
||||
object Locator extends Item {
|
||||
override def worksWith(stack: ItemStack) = isOneOf(stack, Items.locator)
|
||||
|
||||
override def createEnvironment(stack: ItemStack, container: MCTileEntity) ={
|
||||
val nbt = Registry.driverFor(stack) match {
|
||||
case Some(driver)=>driver.dataTag(stack)
|
||||
case _ => null
|
||||
}
|
||||
val x = if(nbt.hasKey(Settings.namespace +"xCenter")) nbt.getInteger(Settings.namespace +"xCenter")
|
||||
else container.xCoord
|
||||
val z = if(nbt.hasKey(Settings.namespace +"zCenter")) nbt.getInteger(Settings.namespace +"zCenter")
|
||||
else container.zCoord
|
||||
val scale = if(nbt.hasKey(Settings.namespace +"scale")) nbt.getInteger(Settings.namespace +"scale")
|
||||
else container.zCoord
|
||||
new component.Locator(container,x,z,scale)
|
||||
}
|
||||
|
||||
override def slot(stack: ItemStack) = Slot.Upgrade
|
||||
}
|
18
li/cil/oc/util/RotationHelper.scala
Normal file
18
li/cil/oc/util/RotationHelper.scala
Normal file
@ -0,0 +1,18 @@
|
||||
package li.cil.oc.util
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection
|
||||
|
||||
|
||||
object RotationHelper {
|
||||
|
||||
def fromYaw(yaw: Float ) = {
|
||||
(yaw / 360 * 4).round & 3 match {
|
||||
case 0 => ForgeDirection.SOUTH
|
||||
case 1 => ForgeDirection.WEST
|
||||
case 2 => ForgeDirection.NORTH
|
||||
case 3 => ForgeDirection.EAST
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user