From 17a97216aa2f8bc9549b5c06d09fb1d562eb024d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=88=91=28=20=C2=B0=20=E2=96=B3=20=C2=B0=7C=7C=7C=29?= <619856824@qq.com> Date: Wed, 17 Sep 2014 18:46:18 +0800 Subject: [PATCH 1/2] Update zh_CN.lang Add translations for piston upgrade. --- src/main/resources/assets/opencomputers/lang/zh_CN.lang | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/assets/opencomputers/lang/zh_CN.lang b/src/main/resources/assets/opencomputers/lang/zh_CN.lang index 420c3033b..f1610a025 100644 --- a/src/main/resources/assets/opencomputers/lang/zh_CN.lang +++ b/src/main/resources/assets/opencomputers/lang/zh_CN.lang @@ -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格范围内的掉落物. From ec08847b791a2f60ff899092d6bbff0b80badb19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 17 Sep 2014 17:41:52 +0200 Subject: [PATCH 2/2] Added some basic player querying to the debug card. --- .../cil/oc/server/component/DebugCard.scala | 87 ++++++++++++++++--- 1 file changed, 76 insertions(+), 11 deletions(-) diff --git a/src/main/scala/li/cil/oc/server/component/DebugCard.scala b/src/main/scala/li/cil/oc/server/component/DebugCard.scala index 17ee2ae41..bdd18e5a8 100644 --- a/src/main/scala/li/cil/oc/server/component/DebugCard.scala +++ b/src/main/scala/li/cil/oc/server/component/DebugCard.scala @@ -5,8 +5,10 @@ import li.cil.oc.api.driver.Container 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.entity.player.EntityPlayerMP import net.minecraft.nbt.NBTTagCompound -import net.minecraft.world.World +import net.minecraft.server.MinecraftServer +import net.minecraft.world.{EnumGameType, World} import net.minecraftforge.common.DimensionManager import scala.math.ScalaNumber @@ -33,10 +35,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.getPlayerForUsername(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(EnumGameType.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. @@ -154,16 +229,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: _*) - } } } \ No newline at end of file