Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added keyboard walking feature #3328

Open
wants to merge 3 commits into
base: master-MC1.7.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
/*.iws
/.idea
/out
/classes

# Debugging
/eclipse
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
3 changes: 3 additions & 0 deletions src/main/scala/li/cil/oc/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
26 changes: 24 additions & 2 deletions src/main/scala/li/cil/oc/common/block/Keyboard.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 =>
Expand Down