Merge branch 'master' of github.com:MightyPirates/OpenComputers into master-MC1.7.10

Conflicts:
	src/main/scala/li/cil/oc/server/component/DebugCard.scala
This commit is contained in:
Florian Nücke 2014-09-17 17:48:56 +02:00
commit bd289be003
2 changed files with 79 additions and 11 deletions

View File

@ -101,6 +101,7 @@ oc:item.UpgradeGenerator.name=发电机升级
oc:item.UpgradeInventory.name=物品栏升级
oc:item.UpgradeInventoryController.name=高级物品栏升级
oc:item.UpgradeNavigation.name=导航升级
oc:item.UpgradePiston.name=活塞升级
oc:item.UpgradeSign.name=告示牌升级
oc:item.UpgradeSolarGenerator.name=太阳能发电机升级
oc:item.UpgradeTractorBeam.name=牵引光束升级
@ -246,7 +247,7 @@ oc:tooltip.Terminal=可以远程控制服务器, 不过前提是你处于信号
oc:tooltip.Tier=§8等级 %s
oc:tooltip.TooLong=按住 [§f%s§7] 显示详细物品信息.
oc:tooltip.Transistor=大多数电脑组件中最基础的元素. 看上去有些扭曲, 但它是有用的.
oc:tooltip.UpgradeAngel=允许机器人凭空放置方块, 甚至是在没有参考点的情况下.
oc:tooltip.UpgradeAngel=允许机器人凭空放置方块, 甚至是在没有任何依附的情况下.
oc:tooltip.UpgradeBattery=增加机器人存储能量的上限, 让其能够运作很长一段时间也不必充电. [nl] 电容: §f%s§7.
oc:tooltip.UpgradeChunkloader=如果机器人走进了一片森林, 周围没有任何生物载入区块, 那么它还能继续移动吗? 这个升级组件可以让你确定这点. 它能让机器人所处的区块保持载入, 但这会让能量不断地消耗.
oc:tooltip.UpgradeContainerCard=卡容器组件可以让你方便随意的将卡装入机器人或从中移出. [nl] 最高等级: §f%s§7.
@ -257,6 +258,7 @@ oc:tooltip.UpgradeGenerator=可以让机器人通过燃料充能. 燃烧物品
oc:tooltip.UpgradeInventory=这个升级组件为机器人提供了物品背包. 如果没有这个升级, 机器人将不能存储物品.
oc:tooltip.UpgradeInventoryController=这个升级组件可以控制机器人使其与外部容器互动, 并能允许机器人将装备上的工具替换成其物品栏中的其它物品.
oc:tooltip.UpgradeNavigation=可以让机器人确认所处位置以及定位. 定位地点即为用于合成此升级组件用到的地图的中心点.
oc:tooltip.UpgradePiston=这个升级十分有用. 它能让机器人像活塞那样移动方块, 但 §l不能§7 移动实体.
oc:tooltip.UpgradeSign=允许机器人读写告示牌.
oc:tooltip.UpgradeSolarGenerator=可以让机器人在太阳光的照射下四处奔走. 机器人顶部需要无任何方块阻挡. 发电效率是斯特林发电机的 %s%% 倍.
oc:tooltip.UpgradeTractorBeam=十分先进的高科技, 别名 "物品磁铁". 它能让机器人在任何地方捡起3格范围内的掉落物.

View File

@ -6,8 +6,11 @@ import li.cil.oc.api.network.{Arguments, Callback, Context, Visibility}
import li.cil.oc.api.prefab.AbstractValue
import li.cil.oc.common.component
import net.minecraft.block.Block
import net.minecraft.entity.player.EntityPlayerMP
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.server.MinecraftServer
import net.minecraft.world.World
import net.minecraft.world.WorldSettings.GameType
import net.minecraftforge.common.DimensionManager
import scala.math.ScalaNumber
@ -34,10 +37,83 @@ class DebugCard(owner: Container) extends component.ManagedComponent {
@Callback(doc = """function():userdata -- Get the container's world object.""")
def getWorld(context: Context, args: Arguments): Array[AnyRef] = result(new DebugCard.WorldValue(owner.world))
@Callback(doc = """function(name:string):userdata -- Get the entity of a player.""")
def getPlayer(context: Context, args: Arguments): Array[AnyRef] = result(new DebugCard.PlayerValue(args.checkString(0)))
}
object DebugCard {
final private def result(args: Any*): Array[AnyRef] = {
def unwrap(arg: Any): AnyRef = arg match {
case x: ScalaNumber => x.underlying
case x => x.asInstanceOf[AnyRef]
}
Array(args map unwrap: _*)
}
class PlayerValue(var name: String) extends AbstractValue {
def this() = this("") // For loading.
// ----------------------------------------------------------------------- //
def withPlayer(f: (EntityPlayerMP) => Array[AnyRef]) = {
MinecraftServer.getServer.getConfigurationManager.func_152612_a(name) match {
case player: EntityPlayerMP => f(player)
case _ => Array(Unit, "player is offline")
}
}
@Callback(doc = """function():string -- Get the player's game type.""")
def getGameType(context: Context, args: Arguments): Array[AnyRef] =
withPlayer(player => Array(player.theItemInWorldManager.getGameType.getName))
@Callback(doc = """function(gametype:string) -- Set the player's game type (survival, creative, adventure).""")
def setGameType(context: Context, args: Arguments): Array[AnyRef] =
withPlayer(player => {
player.setGameType(GameType.getByName(args.checkString(0).toLowerCase))
null
})
@Callback(doc = """function():number, number, number -- Get the player's position.""")
def getPosition(context: Context, args: Arguments): Array[AnyRef] =
withPlayer(player => Array(double2Double(player.posX), double2Double(player.posY), double2Double(player.posZ)))
@Callback(doc = """function(x:number, y:number, z:number) -- Set the player's position.""")
def setPosition(context: Context, args: Arguments): Array[AnyRef] =
withPlayer(player => {
player.setPositionAndUpdate(args.checkDouble(0), args.checkDouble(1), args.checkDouble(2))
null
})
@Callback(doc = """function():number, number, number -- Get the player's position.""")
def getHealth(context: Context, args: Arguments): Array[AnyRef] =
withPlayer(player => Array(float2Float(player.getHealth)))
@Callback(doc = """function():number, number, number -- Get the player's position.""")
def getMaxHealth(context: Context, args: Arguments): Array[AnyRef] =
withPlayer(player => Array(float2Float(player.getMaxHealth)))
@Callback(doc = """function():number, number, number -- Get the player's position.""")
def setHealth(context: Context, args: Arguments): Array[AnyRef] =
withPlayer(player => {
player.setHealth(args.checkDouble(0).toFloat)
null
})
// ----------------------------------------------------------------------- //
override def load(nbt: NBTTagCompound) {
super.load(nbt)
name = nbt.getString("name")
}
override def save(nbt: NBTTagCompound) {
super.save(nbt)
nbt.setString("name", name)
}
}
class WorldValue(var world: World) extends AbstractValue {
def this() = this(null) // For loading.
@ -158,16 +234,6 @@ object DebugCard {
super.save(nbt)
nbt.setInteger("dimension", world.provider.dimensionId)
}
// ----------------------------------------------------------------------- //
final protected def result(args: Any*): Array[AnyRef] = {
def unwrap(arg: Any): AnyRef = arg match {
case x: ScalaNumber => x.underlying
case x => x.asInstanceOf[AnyRef]
}
Array(args map unwrap: _*)
}
}
}