mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-15 18:30:27 -04:00
using actual break time based on equipped tool for robots when breaking blocks; swing time is only used for attacking and extinguishing fires; fixed fire extinguishing by robots
This commit is contained in:
parent
7b136183ea
commit
bc8ebd2508
@ -314,9 +314,14 @@ class Robot(val robot: tileentity.Robot) extends Computer(robot) with RobotConte
|
||||
(true, "entity")
|
||||
}
|
||||
def click(x: Int, y: Int, z: Int, side: Int) = {
|
||||
val broke = player.clickBlock(x, y, z, side)
|
||||
val breakTime = player.clickBlock(x, y, z, side)
|
||||
val broke = breakTime > 0
|
||||
if (broke) {
|
||||
triggerDelay()
|
||||
// Subtract one tick because we take one to trigger the action - a bit
|
||||
// more than one tick avoid floating point inaccuracy incurring another
|
||||
// tick of delay.
|
||||
context.pause(breakTime - 0.055)
|
||||
robot.animateSwing(Settings.get.swingDelay)
|
||||
}
|
||||
(broke, "block")
|
||||
}
|
||||
@ -336,7 +341,11 @@ class Robot(val robot: tileentity.Robot) extends Computer(robot) with RobotConte
|
||||
case Some(entity) =>
|
||||
attack(entity)
|
||||
case _ =>
|
||||
(false, "air")
|
||||
if (world.extinguishFire(player, x, y, z, facing.ordinal)) {
|
||||
triggerDelay()
|
||||
(true, "fire")
|
||||
}
|
||||
else (false, "air")
|
||||
}
|
||||
}
|
||||
if (success) {
|
||||
|
@ -23,6 +23,7 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na
|
||||
capabilities.allowFlying = true
|
||||
capabilities.disableDamage = true
|
||||
capabilities.isFlying = true
|
||||
onGround = true
|
||||
yOffset = 0.5f
|
||||
eyeHeight = 0f
|
||||
setSize(1, 1)
|
||||
@ -185,15 +186,15 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na
|
||||
}
|
||||
}
|
||||
|
||||
def clickBlock(x: Int, y: Int, z: Int, side: Int): Boolean = {
|
||||
def clickBlock(x: Int, y: Int, z: Int, side: Int): Double = {
|
||||
val event = ForgeEventFactory.onPlayerInteract(this, Action.LEFT_CLICK_BLOCK, x, y, z, side)
|
||||
if (event.isCanceled) {
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
// TODO Is this already handled via the event?
|
||||
if (MinecraftServer.getServer.isBlockProtected(world, x, y, z, this)) {
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
val blockId = world.getBlockId(x, y, z)
|
||||
@ -205,7 +206,7 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na
|
||||
FluidRegistry.lookupFluidForBlock(block) == null &&
|
||||
!block.isInstanceOf[BlockFluid]
|
||||
if (!canClickBlock) {
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
block.onBlockClicked(world, x, y, z, this)
|
||||
@ -214,24 +215,28 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na
|
||||
val isBlockUnbreakable = block.getBlockHardness(world, x, y, z) < 0
|
||||
val canDestroyBlock = !isBlockUnbreakable && block.canEntityDestroy(world, x, y, z, this)
|
||||
if (!canDestroyBlock) {
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
if (world.getWorldInfo.getGameType.isAdventure && !isCurrentToolAdventureModeExempt(x, y, z)) {
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
if (!ForgeHooks.canHarvestBlock(block, this, metadata)) {
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
val stack = getCurrentEquippedItem
|
||||
if (stack != null && stack.getItem.onBlockStartBreak(stack, x, y, z, this)) {
|
||||
return false
|
||||
return 0
|
||||
}
|
||||
|
||||
world.playAuxSFXAtEntity(this, 2001, x, y, z, blockId + (metadata << 12))
|
||||
|
||||
val hardness = block.getBlockHardness(world, x, y, z)
|
||||
val strength = getCurrentPlayerStrVsBlock(block, false, metadata)
|
||||
val breakTime = hardness * 1.5 / strength
|
||||
|
||||
if (stack != null) {
|
||||
val oldDamage = stack.getItemDamage
|
||||
stack.onBlockDestroyed(world, blockId, x, y, z, this)
|
||||
@ -246,8 +251,10 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na
|
||||
val itemsBefore = entitiesInBlock[EntityItem](x, y, z)
|
||||
block.onBlockHarvested(world, x, y, z, metadata, this)
|
||||
if (block.removeBlockByPlayer(world, this, x, y, z)) {
|
||||
block.onBlockDestroyedByPlayer(world, x, y, z, metadata)
|
||||
// Note: the block has been destroyed by `removeBlockByPlayer`. This
|
||||
// check only serves to test whether the block can drop anything at all.
|
||||
if (block.canHarvestBlock(this, metadata)) {
|
||||
block.onBlockDestroyedByPlayer(world, x, y, z, metadata)
|
||||
block.harvestBlock(world, this, x, y, z, metadata)
|
||||
val itemsAfter = entitiesInBlock[EntityItem](x, y, z)
|
||||
val itemsDropped = itemsAfter -- itemsBefore
|
||||
@ -255,13 +262,13 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na
|
||||
drop.delayBeforeCanPickup = 0
|
||||
drop.onCollideWithPlayer(this)
|
||||
}
|
||||
if (stack != null) {
|
||||
robot.addXp(Settings.get.robotActionXp)
|
||||
}
|
||||
}
|
||||
return true
|
||||
if (stack != null) {
|
||||
robot.addXp(Settings.get.robotActionXp)
|
||||
}
|
||||
return breakTime
|
||||
}
|
||||
false
|
||||
0
|
||||
}
|
||||
|
||||
override def dropPlayerItemWithRandomChoice(stack: ItemStack, inPlace: Boolean) =
|
||||
|
@ -238,8 +238,10 @@ opencomputers {
|
||||
|
||||
# The time in seconds to pause execution after a robot successfully
|
||||
# swung a tool (or it's 'hands' if nothing is equipped). Successful in
|
||||
# this case means that it hit something, either by attacking an entity
|
||||
# or by breaking a block.
|
||||
# this case means that it hit something, i.e. it attacked an entity or
|
||||
# extinguishing fires.
|
||||
# When breaking blocks the normal harvest time scaled with the
|
||||
# `harvestRatio` (see below) applies.
|
||||
swing: 0.4
|
||||
|
||||
# The time in seconds to pause execution after a robot successfully
|
||||
@ -252,17 +254,24 @@ opencomputers {
|
||||
# item use is taken.
|
||||
use: 0.4
|
||||
|
||||
# This is the *ratio* of the time a player would require to harvest a
|
||||
# block. Note that robots cannot break blocks they cannot harvest. So
|
||||
# the time a robot is forced to sleep after harvesting a block is
|
||||
# breakTime * harvestRatio
|
||||
# Breaking a block will always at least take one tick, 0.05 seconds.
|
||||
harvestRatio: 1.0
|
||||
|
||||
# The time in seconds to pause execution after a robot successfully
|
||||
# placed an item from its inventory.
|
||||
place: 0.4
|
||||
|
||||
# The time in seconds to pause execution after an item was
|
||||
# successfully dropped from a robot's inventory.
|
||||
drop: 0.25
|
||||
drop: 0.3
|
||||
|
||||
# The time in seconds to pause execution after a robot successfully
|
||||
# picked up an item after triggering a suck command.
|
||||
suck: 0.25
|
||||
suck: 0.3
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user