diff --git a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala index cb7098c30..2d1e6001a 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -11,7 +11,7 @@ import li.cil.oc.server.component.robot import li.cil.oc.server.driver.Registry import li.cil.oc.server.{PacketSender => ServerPacketSender, driver, component} import li.cil.oc.util.ExtendedNBT._ -import net.minecraft.block.Block +import net.minecraft.block.{BlockLiquid, BlockDynamicLiquid, Block} import net.minecraft.client.Minecraft import net.minecraft.entity.player.EntityPlayer import net.minecraft.inventory.ISidedInventory @@ -20,6 +20,7 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.ChatComponentTranslation import net.minecraftforge.common.util.ForgeDirection import scala.io.Source +import net.minecraftforge.fluids.{BlockFluidBase, FluidRegistry} // Implementation note: this tile entity is never directly added to the world. // It is always wrapped by a `RobotProxy` tile entity, which forwards any @@ -197,7 +198,17 @@ class Robot(val isRemote: Boolean) extends traits.Computer with traits.TextBuffe else { // If we broke some replaceable block (like grass) play its break sound. if (!wasAir) { - world.playAuxSFX(2001, nx, ny, nz, Block.getIdFromBlock(block) + (metadata << 12)) + if (block != null) { + if (FluidRegistry.lookupFluidForBlock(block) == null && + !block.isInstanceOf[BlockFluidBase] && + !block.isInstanceOf[BlockLiquid]) { + world.playAuxSFX(2001, nx, ny, nz, Block.getIdFromBlock(block) + (metadata << 12)) + } + else { + world.playSound(nx + 0.5, ny + 0.5, nz + 0.5, "liquid.water", + world.rand.nextFloat * 0.25F + 0.75F, world.rand.nextFloat * 1.0F + 0.5F, false) + } + } } world.markBlockForUpdate(ox, oy, oz) world.markBlockForUpdate(nx, ny, nz) diff --git a/src/main/scala/li/cil/oc/server/component/robot/Robot.scala b/src/main/scala/li/cil/oc/server/component/robot/Robot.scala index 41661a311..902b15a58 100644 --- a/src/main/scala/li/cil/oc/server/component/robot/Robot.scala +++ b/src/main/scala/li/cil/oc/server/component/robot/Robot.scala @@ -250,8 +250,8 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { val (bx, by, bz, hx, hy, hz) = clickParamsFromHit(hit) player.placeBlock(robot.selectedSlot, bx, by, bz, hit.sideHit, hx, hy, hz) case None if hasAngelUpgrade && player.closestEntity[Entity]().isEmpty => - val (bx, by, bz, hx, hy, hz) = clickParamsFromFacing(facing, side) - player.placeBlock(robot.selectedSlot, bx, by, bz, side.getOpposite.ordinal, hx, hy, hz) + val (bx, by, bz, hx, hy, hz) = clickParamsForPlace(facing) + player.placeBlock(robot.selectedSlot, bx, by, bz, facing.ordinal, hx, hy, hz) case _ => false } player.setSneaking(false) @@ -467,8 +467,13 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { activationResult(player.activateBlockOrUseItem(bx, by, bz, hit.sideHit, hx, hy, hz, duration)) case _ => (if (hasAngelUpgrade) { - val (bx, by, bz, hx, hy, hz) = clickParamsFromFacing(facing, side) - player.activateBlockOrUseItem(bx, by, bz, side.getOpposite.ordinal, hx, hy, hz, duration) + val (bx, by, bz, hx, hy, hz) = clickParamsForPlace(facing) + if (player.placeBlock(0, bx, by, bz, facing.ordinal, hx, hy, hz)) + ActivationType.ItemPlaced + else { + val (bx, by, bz, hx, hy, hz) = clickParamsForItemUse(facing, side) + player.activateBlockOrUseItem(bx, by, bz, side.getOpposite.ordinal, hx, hy, hz, duration) + } } else ActivationType.None) match { case ActivationType.None => if (player.useEquippedItem(duration)) { @@ -619,15 +624,6 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { } } - private def clickParamsFromFacing(facing: ForgeDirection, side: ForgeDirection) = { - (x + facing.offsetX + side.offsetX, - y + facing.offsetY + side.offsetY, - z + facing.offsetZ + side.offsetZ, - 0.5f - side.offsetX * 0.5f, - 0.5f - side.offsetY * 0.5f, - 0.5f - side.offsetZ * 0.5f) - } - private def pick(player: Player, range: Double) = { val origin = world.getWorldVec3Pool.getVecFromPool( player.posX + player.facing.offsetX * 0.5, @@ -648,6 +644,22 @@ class Robot(val robot: tileentity.Robot) extends ManagedComponent { } } + private def clickParamsForPlace(facing: ForgeDirection) = { + (x, y, z, + 0.5f + facing.offsetX * 0.5f, + 0.5f + facing.offsetY * 0.5f, + 0.5f + facing.offsetZ * 0.5f) + } + + private def clickParamsForItemUse(facing: ForgeDirection, side: ForgeDirection) = { + (x + facing.offsetX + side.offsetX, + y + facing.offsetY + side.offsetY, + z + facing.offsetZ + side.offsetZ, + 0.5f - side.offsetX * 0.5f, + 0.5f - side.offsetY * 0.5f, + 0.5f - side.offsetZ * 0.5f) + } + private def clickParamsFromHit(hit: MovingObjectPosition) = { (hit.blockX, hit.blockY, hit.blockZ, (hit.hitVec.xCoord - hit.blockX).toFloat, diff --git a/src/main/scala/li/cil/oc/server/fs/InputStreamFileSystem.scala b/src/main/scala/li/cil/oc/server/fs/InputStreamFileSystem.scala index 856fac148..d58600c32 100644 --- a/src/main/scala/li/cil/oc/server/fs/InputStreamFileSystem.scala +++ b/src/main/scala/li/cil/oc/server/fs/InputStreamFileSystem.scala @@ -95,10 +95,10 @@ trait InputStreamFileSystem extends api.fs.FileSystem { read(dst.array()) } else { - val count = dst.limit - dst.position + val count = math.max(0, dst.limit - dst.position) val buffer = new Array[Byte](count) val n = read(buffer) - dst.put(buffer, 0, n) + if (n > 0) dst.put(buffer, 0, n) n } }