From 67ed9876adca93aa9597afa87b9a0e23d1a5419e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 12 Feb 2014 01:42:04 +0100 Subject: [PATCH] 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 --- .../li/cil/oc/common/tileentity/Robot.scala | 2 +- .../oc/server/component/robot/Player.scala | 10 +++++- .../cil/oc/server/component/robot/Robot.scala | 36 ++++++++++--------- .../cil/oc/util/mods/TinkersConstruct.scala | 7 ++++ 4 files changed, 36 insertions(+), 19 deletions(-) create mode 100644 src/main/java/li/cil/oc/util/mods/TinkersConstruct.scala diff --git a/src/main/java/li/cil/oc/common/tileentity/Robot.scala b/src/main/java/li/cil/oc/common/tileentity/Robot.scala index cbf5a48cf..054811d5b 100644 --- a/src/main/java/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/java/li/cil/oc/common/tileentity/Robot.scala @@ -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 diff --git a/src/main/java/li/cil/oc/server/component/robot/Player.scala b/src/main/java/li/cil/oc/server/component/robot/Player.scala index 36652f3eb..bb969cec8 100644 --- a/src/main/java/li/cil/oc/server/component/robot/Player.scala +++ b/src/main/java/li/cil/oc/server/component/robot/Player.scala @@ -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)) diff --git a/src/main/java/li/cil/oc/server/component/robot/Robot.scala b/src/main/java/li/cil/oc/server/component/robot/Robot.scala index d63ae4ddd..c59c8fc0c 100644 --- a/src/main/java/li/cil/oc/server/component/robot/Robot.scala +++ b/src/main/java/li/cil/oc/server/component/robot/Robot.scala @@ -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") diff --git a/src/main/java/li/cil/oc/util/mods/TinkersConstruct.scala b/src/main/java/li/cil/oc/util/mods/TinkersConstruct.scala new file mode 100644 index 000000000..140b43d42 --- /dev/null +++ b/src/main/java/li/cil/oc/util/mods/TinkersConstruct.scala @@ -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.""") +}