mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 03:36:47 -04:00
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:
parent
80595a8583
commit
67ed9876ad
@ -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
|
override def tier = 0
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package li.cil.oc.server.component.robot
|
|||||||
|
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.common.tileentity
|
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.block.{BlockPistonBase, BlockFluid, Block}
|
||||||
import net.minecraft.enchantment.EnchantmentHelper
|
import net.minecraft.enchantment.EnchantmentHelper
|
||||||
import net.minecraft.entity.item.EntityItem
|
import net.minecraft.entity.item.EntityItem
|
||||||
@ -247,9 +247,17 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett
|
|||||||
}
|
}
|
||||||
|
|
||||||
val stack = getCurrentEquippedItem
|
val stack = getCurrentEquippedItem
|
||||||
|
if (TinkersConstruct.isInfiTool(stack)) {
|
||||||
|
posY -= 1.62
|
||||||
|
prevPosY = posY
|
||||||
|
}
|
||||||
if (stack != null && stack.getItem.onBlockStartBreak(stack, x, y, z, this)) {
|
if (stack != null && stack.getItem.onBlockStartBreak(stack, x, y, z, this)) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
if (TinkersConstruct.isInfiTool(stack)) {
|
||||||
|
posY += 1.62
|
||||||
|
prevPosY = posY
|
||||||
|
}
|
||||||
|
|
||||||
world.playAuxSFXAtEntity(this, 2001, x, y, z, blockId + (metadata << 12))
|
world.playAuxSFXAtEntity(this, 2001, x, y, z, blockId + (metadata << 12))
|
||||||
|
|
||||||
|
@ -200,6 +200,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
|||||||
result(tryDropIntoInventory(inventory,
|
result(tryDropIntoInventory(inventory,
|
||||||
slot => inventory.isItemValidForSlot(slot, dropped)))
|
slot => inventory.isItemValidForSlot(slot, dropped)))
|
||||||
case _ =>
|
case _ =>
|
||||||
|
val player = robot.player(facing)
|
||||||
for (entity <- player.entitiesOnSide[EntityMinecartContainer](facing) if entity.isUseableByPlayer(player)) {
|
for (entity <- player.entitiesOnSide[EntityMinecartContainer](facing) if entity.isUseableByPlayer(player)) {
|
||||||
if (tryDropIntoInventory(entity, slot => entity.isItemValidForSlot(slot, dropped))) {
|
if (tryDropIntoInventory(entity, slot => entity.isItemValidForSlot(slot, dropped))) {
|
||||||
return result(true)
|
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) =>
|
case inventory: IInventory if inventory.isUseableByPlayer(player) =>
|
||||||
result(trySuckFromInventory(inventory, slot => true))
|
result(trySuckFromInventory(inventory, slot => true))
|
||||||
case _ =>
|
case _ =>
|
||||||
|
val player = robot.player(facing)
|
||||||
for (entity <- player.entitiesOnSide[EntityMinecartContainer](facing) if entity.isUseableByPlayer(player)) {
|
for (entity <- player.entitiesOnSide[EntityMinecartContainer](facing) if entity.isUseableByPlayer(player)) {
|
||||||
if (trySuckFromInventory(entity, slot => true)) {
|
if (trySuckFromInventory(entity, slot => true)) {
|
||||||
return result(true)
|
return result(true)
|
||||||
@ -314,7 +316,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
|||||||
@Callback
|
@Callback
|
||||||
def detect(context: Context, args: Arguments): Array[AnyRef] = {
|
def detect(context: Context, args: Arguments): Array[AnyRef] = {
|
||||||
val side = checkSideForAction(args, 0)
|
val side = checkSideForAction(args, 0)
|
||||||
val (something, what) = blockContent(side)
|
val (something, what) = blockContent(robot.player(side), side)
|
||||||
result(something, what)
|
result(something, what)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +339,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
|||||||
context.pause(delay)
|
context.pause(delay)
|
||||||
robot.animateSwing(Settings.get.swingDelay)
|
robot.animateSwing(Settings.get.swingDelay)
|
||||||
}
|
}
|
||||||
def attack(entity: Entity) = {
|
def attack(player: Player, entity: Entity) = {
|
||||||
beginConsumeDrops(entity)
|
beginConsumeDrops(entity)
|
||||||
player.attackTargetEntityWithCurrentItem(entity)
|
player.attackTargetEntityWithCurrentItem(entity)
|
||||||
// Mine carts have to be hit quickly in succession to break, so we click
|
// 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 _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
endConsumeDrops(entity)
|
endConsumeDrops(player, entity)
|
||||||
triggerDelay()
|
triggerDelay()
|
||||||
(true, "entity")
|
(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 breakTime = player.clickBlock(x, y, z, side)
|
||||||
val broke = breakTime > 0
|
val broke = breakTime > 0
|
||||||
if (broke) {
|
if (broke) {
|
||||||
@ -372,14 +374,14 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
|||||||
case Some(hit) =>
|
case Some(hit) =>
|
||||||
hit.typeOfHit match {
|
hit.typeOfHit match {
|
||||||
case EnumMovingObjectType.ENTITY =>
|
case EnumMovingObjectType.ENTITY =>
|
||||||
attack(hit.entityHit)
|
attack(player, hit.entityHit)
|
||||||
case EnumMovingObjectType.TILE =>
|
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.
|
case _ => // Retry with full block bounds, disregarding swing range.
|
||||||
player.closestEntity[EntityLivingBase]() match {
|
player.closestEntity[EntityLivingBase]() match {
|
||||||
case Some(entity) =>
|
case Some(entity) =>
|
||||||
attack(entity)
|
attack(player, entity)
|
||||||
case _ =>
|
case _ =>
|
||||||
if (world.extinguishFire(player, x, y, z, facing.ordinal)) {
|
if (world.extinguishFire(player, x, y, z, facing.ordinal)) {
|
||||||
triggerDelay()
|
triggerDelay()
|
||||||
@ -430,19 +432,19 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
|||||||
(true, "item_used")
|
(true, "item_used")
|
||||||
case _ => (false, "")
|
case _ => (false, "")
|
||||||
}
|
}
|
||||||
|
def interact(player: Player, entity: Entity) = {
|
||||||
|
beginConsumeDrops(entity)
|
||||||
|
val result = player.interactWith(entity)
|
||||||
|
endConsumeDrops(player, entity)
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
for (side <- sides) {
|
for (side <- sides) {
|
||||||
val player = robot.player(facing, side)
|
val player = robot.player(facing, side)
|
||||||
player.setSneaking(sneaky)
|
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 {
|
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()
|
triggerDelay()
|
||||||
(true, "item_interacted")
|
(true, "item_interacted")
|
||||||
case Some(hit) if hit.typeOfHit == EnumMovingObjectType.TILE =>
|
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")
|
result(false, "already moving")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val (something, what) = blockContent(direction)
|
val (something, what) = blockContent(robot.player(direction), direction)
|
||||||
if (something) {
|
if (something) {
|
||||||
result(false, what)
|
result(false, what)
|
||||||
}
|
}
|
||||||
@ -558,7 +560,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot) with RobotContex
|
|||||||
entity.captureDrops = true
|
entity.captureDrops = true
|
||||||
}
|
}
|
||||||
|
|
||||||
private def endConsumeDrops(entity: Entity) {
|
private def endConsumeDrops(player: Player, entity: Entity) {
|
||||||
entity.captureDrops = false
|
entity.captureDrops = false
|
||||||
for (drop <- entity.capturedDrops) {
|
for (drop <- entity.capturedDrops) {
|
||||||
val stack = drop.getEntityItem
|
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 {
|
player.closestEntity[Entity](side) match {
|
||||||
case Some(_@(_: EntityLivingBase | _: EntityMinecart)) =>
|
case Some(_@(_: EntityLivingBase | _: EntityMinecart)) =>
|
||||||
(true, "entity")
|
(true, "entity")
|
||||||
|
7
src/main/java/li/cil/oc/util/mods/TinkersConstruct.scala
Normal file
7
src/main/java/li/cil/oc/util/mods/TinkersConstruct.scala
Normal 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.""")
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user