fixed robot "orientation" not being properly set when breaking blocks, which made some tools behave incorrectly if they did custom raytracing; added special check for TC tools to offset fake player position for raytracing

This commit is contained in:
Florian Nücke 2014-02-12 01:42:04 +01:00
parent 80595a8583
commit 67ed9876ad
4 changed files with 36 additions and 19 deletions

View File

@ -489,7 +489,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
// ----------------------------------------------------------------------- //
override def installedMemory = 64 * 1024
override def installedMemory = 96 * 1024
override def tier = 0

View File

@ -2,7 +2,7 @@ package li.cil.oc.server.component.robot
import li.cil.oc.Settings
import li.cil.oc.common.tileentity
import li.cil.oc.util.mods.PortalGun
import li.cil.oc.util.mods.{TinkersConstruct, PortalGun}
import net.minecraft.block.{BlockPistonBase, BlockFluid, Block}
import net.minecraft.enchantment.EnchantmentHelper
import net.minecraft.entity.item.EntityItem
@ -247,9 +247,17 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett
}
val stack = getCurrentEquippedItem
if (TinkersConstruct.isInfiTool(stack)) {
posY -= 1.62
prevPosY = posY
}
if (stack != null && stack.getItem.onBlockStartBreak(stack, x, y, z, this)) {
return 0
}
if (TinkersConstruct.isInfiTool(stack)) {
posY += 1.62
prevPosY = posY
}
world.playAuxSFXAtEntity(this, 2001, x, y, z, blockId + (metadata << 12))

View File

@ -200,6 +200,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
result(tryDropIntoInventory(inventory,
slot => inventory.isItemValidForSlot(slot, dropped)))
case _ =>
val player = robot.player(facing)
for (entity <- player.entitiesOnSide[EntityMinecartContainer](facing) if entity.isUseableByPlayer(player)) {
if (tryDropIntoInventory(entity, slot => entity.isItemValidForSlot(slot, dropped))) {
return result(true)
@ -291,6 +292,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
case inventory: IInventory if inventory.isUseableByPlayer(player) =>
result(trySuckFromInventory(inventory, slot => true))
case _ =>
val player = robot.player(facing)
for (entity <- player.entitiesOnSide[EntityMinecartContainer](facing) if entity.isUseableByPlayer(player)) {
if (trySuckFromInventory(entity, slot => true)) {
return result(true)
@ -314,7 +316,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
@Callback
def detect(context: Context, args: Arguments): Array[AnyRef] = {
val side = checkSideForAction(args, 0)
val (something, what) = blockContent(side)
val (something, what) = blockContent(robot.player(side), side)
result(something, what)
}
@ -337,7 +339,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
context.pause(delay)
robot.animateSwing(Settings.get.swingDelay)
}
def attack(entity: Entity) = {
def attack(player: Player, entity: Entity) = {
beginConsumeDrops(entity)
player.attackTargetEntityWithCurrentItem(entity)
// Mine carts have to be hit quickly in succession to break, so we click
@ -348,11 +350,11 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
}
case _ =>
}
endConsumeDrops(entity)
endConsumeDrops(player, entity)
triggerDelay()
(true, "entity")
}
def click(x: Int, y: Int, z: Int, side: Int) = {
def click(player: Player, x: Int, y: Int, z: Int, side: Int) = {
val breakTime = player.clickBlock(x, y, z, side)
val broke = breakTime > 0
if (broke) {
@ -372,14 +374,14 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
case Some(hit) =>
hit.typeOfHit match {
case EnumMovingObjectType.ENTITY =>
attack(hit.entityHit)
attack(player, hit.entityHit)
case EnumMovingObjectType.TILE =>
click(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit)
click(player, hit.blockX, hit.blockY, hit.blockZ, hit.sideHit)
}
case _ => // Retry with full block bounds, disregarding swing range.
player.closestEntity[EntityLivingBase]() match {
case Some(entity) =>
attack(entity)
attack(player, entity)
case _ =>
if (world.extinguishFire(player, x, y, z, facing.ordinal)) {
triggerDelay()
@ -430,19 +432,19 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
(true, "item_used")
case _ => (false, "")
}
def interact(player: Player, entity: Entity) = {
beginConsumeDrops(entity)
val result = player.interactWith(entity)
endConsumeDrops(player, entity)
result
}
for (side <- sides) {
val player = robot.player(facing, side)
player.setSneaking(sneaky)
def interact(entity: Entity) = {
beginConsumeDrops(entity)
val result = player.interactWith(entity)
endConsumeDrops(entity)
result
}
val (success, what) = Option(pick(player, Settings.get.useAndPlaceRange)) match {
case Some(hit) if hit.typeOfHit == EnumMovingObjectType.ENTITY && interact(hit.entityHit) =>
case Some(hit) if hit.typeOfHit == EnumMovingObjectType.ENTITY && interact(player, hit.entityHit) =>
triggerDelay()
(true, "item_interacted")
case Some(hit) if hit.typeOfHit == EnumMovingObjectType.TILE =>
@ -495,7 +497,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
result(false, "already moving")
}
else {
val (something, what) = blockContent(direction)
val (something, what) = blockContent(robot.player(direction), direction)
if (something) {
result(false, what)
}
@ -558,7 +560,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
entity.captureDrops = true
}
private def endConsumeDrops(entity: Entity) {
private def endConsumeDrops(player: Player, entity: Entity) {
entity.captureDrops = false
for (drop <- entity.capturedDrops) {
val stack = drop.getEntityItem
@ -572,7 +574,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
// ----------------------------------------------------------------------- //
private def blockContent(side: ForgeDirection) = {
private def blockContent(player: Player, side: ForgeDirection) = {
player.closestEntity[Entity](side) match {
case Some(_@(_: EntityLivingBase | _: EntityMinecart)) =>
(true, "entity")

View File

@ -0,0 +1,7 @@
package li.cil.oc.util.mods
import net.minecraft.item.ItemStack
object TinkersConstruct {
def isInfiTool(stack: ItemStack) = stack != null && stack.getItem.getClass.getName.startsWith("""tconstruct.""")
}