diff --git a/.gitignore b/.gitignore index 7988aa7c03..71c59a027d 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ /*.iws /.idea /out +/classes # Debugging /eclipse diff --git a/src/main/resources/application.conf b/src/main/resources/application.conf index 70b8432c53..f2ecebd1f8 100644 --- a/src/main/resources/application.conf +++ b/src/main/resources/application.conf @@ -1603,4 +1603,9 @@ opencomputers { # default is .5, which gives: .5, 1, 4 bitbltCost: 0.5 } + + keyboard { + # Allow entities perform random keyboard events when they walk on it + keyboardWalking: true + } } diff --git a/src/main/scala/li/cil/oc/Settings.scala b/src/main/scala/li/cil/oc/Settings.scala index 72c06a1d26..b2ee68b994 100644 --- a/src/main/scala/li/cil/oc/Settings.scala +++ b/src/main/scala/li/cil/oc/Settings.scala @@ -413,6 +413,9 @@ class Settings(val config: Config) { val chunkloadDimensionBlacklist = Settings.getIntList(config, "chunkloader.dimBlacklist") val chunkloadDimensionWhitelist = Settings.getIntList(config, "chunkloader.dimWhitelist") + //keyboard + val keyboardWalking = config.getBoolean("keyboard.keyboardWalking") + // ----------------------------------------------------------------------- // // integration val modBlacklist = config.getStringList("integration.modBlacklist") diff --git a/src/main/scala/li/cil/oc/common/block/Keyboard.scala b/src/main/scala/li/cil/oc/common/block/Keyboard.scala index 67877a9f6b..2d05aa93db 100644 --- a/src/main/scala/li/cil/oc/common/block/Keyboard.scala +++ b/src/main/scala/li/cil/oc/common/block/Keyboard.scala @@ -2,14 +2,14 @@ package li.cil.oc.common.block import java.util.Random -import li.cil.oc.Constants -import li.cil.oc.api +import li.cil.oc.{Constants, Settings, api} import li.cil.oc.common.tileentity import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedWorld._ import li.cil.oc.util.InventoryUtils import net.minecraft.block.Block import net.minecraft.block.material.Material +import net.minecraft.entity.Entity import net.minecraft.entity.player.EntityPlayer import net.minecraft.world.IBlockAccess import net.minecraft.world.World @@ -104,6 +104,28 @@ class Keyboard extends SimpleBlock(Material.rock) with traits.SpecialBlock { case _ => false } + override def onEntityWalking(world: World, x: Int, y: Int, z: Int, entity: Entity): Unit = { + if (!world.isRemote && Settings.get.keyboardWalking) + world.getTileEntity(x, y, z) match { + case keyboard: tileentity.Keyboard => + val node = keyboard.node + + val randChar: Int = world.rand.nextInt('z' - 'A') + 'A' + + val javaCharRepr = Character.valueOf(randChar.toChar) + val javaIntRepr = Integer.valueOf(randChar) + + + if (Settings.get.inputUsername) + node.sendToReachable("computer.signal", "key_down", javaCharRepr, javaIntRepr, entity.getCommandSenderName) + else + node.sendToReachable("computer.signal", "key_down", javaCharRepr, javaIntRepr) + + + case _ => + } + } + def adjacencyInfo(world: World, position: BlockPosition) = world.getTileEntity(position) match { case keyboard: tileentity.Keyboard =>