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 04a696d61..e9c8c5261 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -19,6 +19,8 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.ChatMessageComponent import net.minecraftforge.common.ForgeDirection import scala.io.Source +import net.minecraftforge.fluids.{BlockFluidBase, FluidRegistry} +import net.minecraft.block.{BlockFlowing, Block} // Implementation note: this tile entity is never directly added to the world. // It is always wrapped by a `RobotProxy` tile entity, which forwards any @@ -195,7 +197,18 @@ 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 (blockId > 0) { - world.playAuxSFX(2001, nx, ny, nz, blockId + (metadata << 12)) + val block = Block.blocksList(blockId) + if (block != null) { + if (FluidRegistry.lookupFluidForBlock(block) == null && + !block.isInstanceOf[BlockFluidBase] && + !block.isInstanceOf[BlockFlowing]) { + world.playAuxSFX(2001, nx, ny, nz, blockId + (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.markBlockForRenderUpdate(ox, oy, oz) world.markBlockForRenderUpdate(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 49af11d60..b3ae87def 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 @@ -248,8 +248,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) @@ -461,8 +461,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)) { @@ -614,15 +619,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, @@ -643,6 +639,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 f9fa39c5f..9973fe0f4 100644 --- a/src/main/scala/li/cil/oc/server/fs/InputStreamFileSystem.scala +++ b/src/main/scala/li/cil/oc/server/fs/InputStreamFileSystem.scala @@ -94,10 +94,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 } }