diff --git a/li/cil/oc/client/renderer/block/BlockRenderer.scala b/li/cil/oc/client/renderer/block/BlockRenderer.scala index 0f37f8a6d..47a5d730c 100644 --- a/li/cil/oc/client/renderer/block/BlockRenderer.scala +++ b/li/cil/oc/client/renderer/block/BlockRenderer.scala @@ -20,13 +20,12 @@ object BlockRenderer extends ISimpleBlockRenderingHandler { GL11.glPushMatrix() Delegator.subBlock(block, metadata) match { case Some(cable: Cable) => - GL11.glTranslatef(0, 0.3f, 0) GL11.glScalef(1.6f, 1.6f, 1.6f) - GL11.glTranslatef(-0.5f, -0.5f, -0.5f) + GL11.glTranslatef(-0.5f, -0.3f, -0.5f) CableRenderer.renderCable(ForgeDirection.DOWN.flag) case Some(proxy@(_: RobotProxy | _: RobotAfterimage)) => - GL11.glTranslatef(0, -0.1f, 0) GL11.glScalef(1.5f, 1.5f, 1.5f) + GL11.glTranslatef(-0.5f, -0.45f, -0.5f) RobotRenderer.renderChassis() case _ => val renderFace = Array( diff --git a/li/cil/oc/common/block/Delegate.scala b/li/cil/oc/common/block/Delegate.scala index 5a8ce0019..7287eb5e8 100644 --- a/li/cil/oc/common/block/Delegate.scala +++ b/li/cil/oc/common/block/Delegate.scala @@ -6,7 +6,7 @@ import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack import net.minecraft.tileentity.TileEntity -import net.minecraft.util.{Vec3, AxisAlignedBB, Icon} +import net.minecraft.util.{MovingObjectPosition, Vec3, AxisAlignedBB, Icon} import net.minecraft.world.IBlockAccess import net.minecraft.world.World import net.minecraftforge.common.ForgeDirection @@ -56,6 +56,8 @@ trait Delegate { def dropBlockAsItemWithChance(world: World, x: Int, y: Int, z: Int, chance: Float, fortune: Int) = false + def pickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int): ItemStack = createItemStack() + def getRenderColor = 0xFFFFFF def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 255 diff --git a/li/cil/oc/common/block/Delegator.scala b/li/cil/oc/common/block/Delegator.scala index 7cf7d82e3..e2da27adf 100644 --- a/li/cil/oc/common/block/Delegator.scala +++ b/li/cil/oc/common/block/Delegator.scala @@ -14,7 +14,7 @@ import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.{EnumCreatureType, Entity, EntityLivingBase} import net.minecraft.item.{ItemBlock, ItemStack} import net.minecraft.tileentity.TileEntity -import net.minecraft.util.{Vec3, AxisAlignedBB} +import net.minecraft.util.{MovingObjectPosition, Vec3, AxisAlignedBB} import net.minecraft.world.{IBlockAccess, World} import net.minecraftforge.common.ForgeDirection import powercrystals.minefactoryreloaded.api.rednet.{IRedNetNetworkContainer, RedNetConnectionType, IConnectableRedNet} @@ -143,6 +143,12 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) { dropBlockAsItem_do(world, x, y, z, stack) } + override def getPickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) = + subBlock(world, x, y, z) match { + case Some(subBlock) => subBlock.pickBlock(target, world, x, y, z) + case _ => super.getPickBlock(target, world, x, y, z) + } + override def getRenderColor(metadata: Int) = subBlock(metadata) match { case Some(subBlock) => subBlock.getRenderColor diff --git a/li/cil/oc/common/block/RobotAfterimage.scala b/li/cil/oc/common/block/RobotAfterimage.scala index f4c00f951..b09349278 100644 --- a/li/cil/oc/common/block/RobotAfterimage.scala +++ b/li/cil/oc/common/block/RobotAfterimage.scala @@ -5,12 +5,19 @@ import li.cil.oc.common.tileentity import net.minecraft.entity.player.EntityPlayer import net.minecraft.world.{IBlockAccess, World} import net.minecraftforge.common.ForgeDirection +import net.minecraft.util.MovingObjectPosition class RobotAfterimage(val parent: SpecialDelegator) extends SpecialDelegate { val unlocalizedName = "RobotAfterimage" override val showInItemList = false + override def pickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) = + findMovingRobot(world, x, y, z) match { + case Some(robot) => robot.createItemStack() + case _ => null + } + override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int) = { super.breakBlock(world, x, y, z, blockId) findMovingRobot(world, x, y, z) match { diff --git a/li/cil/oc/common/block/RobotProxy.scala b/li/cil/oc/common/block/RobotProxy.scala index 99cf642e3..d29757abe 100644 --- a/li/cil/oc/common/block/RobotProxy.scala +++ b/li/cil/oc/common/block/RobotProxy.scala @@ -8,8 +8,7 @@ import li.cil.oc.{Settings, OpenComputers} import net.minecraft.entity.EntityLivingBase import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack -import net.minecraft.nbt.NBTTagCompound -import net.minecraft.util.{AxisAlignedBB, Vec3} +import net.minecraft.util.{MovingObjectPosition, AxisAlignedBB, Vec3} import net.minecraft.world.{IBlockAccess, World} import net.minecraftforge.common.ForgeDirection @@ -29,6 +28,12 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele tooltip.addAll(Tooltip.get(unlocalizedName)) } + override def pickBlock(target: MovingObjectPosition, world: World, x: Int, y: Int, z: Int) = + world.getBlockTileEntity(x, y, z) match { + case proxy: tileentity.RobotProxy => proxy.robot.createItemStack() + case _ => null + } + // ----------------------------------------------------------------------- // override def createTileEntity(world: World) = { @@ -90,29 +95,22 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele super.onBlockPlacedBy(world, x, y, z, entity, stack) if (!world.isRemote) ((entity, world.getBlockTileEntity(x, y, z)) match { case (player: robot.Player, proxy: tileentity.RobotProxy) => - Some((proxy, player.robot.owner)) + Some((proxy.robot, player.robot.owner)) case (player: EntityPlayer, proxy: tileentity.RobotProxy) => - Some((proxy, player.getCommandSenderName)) + Some((proxy.robot, player.getCommandSenderName)) case _ => None }) match { - case Some((proxy, owner)) => - proxy.robot.owner = owner - if (stack.hasTagCompound) { - proxy.robot.battery.changeBuffer(stack.getTagCompound.getInteger(Settings.namespace + "storedEnergy")) - } + case Some((robot, owner)) => + robot.owner = owner + robot.parseItemStack(stack) case _ => } } override def onBlockRemovedBy(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) = { if (!world.isRemote) world.getBlockTileEntity(x, y, z) match { - case proxy: tileentity.RobotProxy if !player.capabilities.isCreativeMode || proxy.globalBuffer > 0 => - val stack = createItemStack() - if (proxy.globalBuffer > 1) { - stack.setTagCompound(new NBTTagCompound("tag")) - stack.getTagCompound.setInteger(Settings.namespace + "storedEnergy", proxy.globalBuffer.toInt) - } - parent.dropBlockAsItem(world, x, y, z, stack) + case proxy: tileentity.RobotProxy if !player.capabilities.isCreativeMode || proxy.globalBuffer > 1 => + parent.dropBlockAsItem(world, x, y, z, proxy.robot.createItemStack()) case _ => } super.onBlockRemovedBy(world, x, y, z, player) diff --git a/li/cil/oc/common/tileentity/Robot.scala b/li/cil/oc/common/tileentity/Robot.scala index 0aa596cc3..75bf54701 100644 --- a/li/cil/oc/common/tileentity/Robot.scala +++ b/li/cil/oc/common/tileentity/Robot.scala @@ -137,6 +137,23 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w } } + def createItemStack() = { + val stack = Blocks.robotProxy.createItemStack() + if (globalBuffer > 1) { + stack.setTagCompound(new NBTTagCompound("tag")) + stack.getTagCompound.setInteger(Settings.namespace + "storedEnergy", globalBuffer.toInt) + } + stack + } + + def parseItemStack(stack: ItemStack) { + if (stack.hasTagCompound) { + battery.changeBuffer(stack.getTagCompound.getInteger(Settings.namespace + "storedEnergy")) + } + } + + // ----------------------------------------------------------------------- // + def isAnimatingMove = animationTicksLeft > 0 && moveDirection != ForgeDirection.UNKNOWN def isAnimatingSwing = animationTicksLeft > 0 && swingingTool diff --git a/li/cil/oc/server/component/Robot.scala b/li/cil/oc/server/component/Robot.scala index 54b965441..4cd9f294f 100644 --- a/li/cil/oc/server/component/Robot.scala +++ b/li/cil/oc/server/component/Robot.scala @@ -10,7 +10,7 @@ import net.minecraft.entity.{EntityLivingBase, Entity} import net.minecraft.entity.item.EntityItem import net.minecraft.inventory.{IInventory, ISidedInventory} import net.minecraft.item.{ItemStack, ItemBlock} -import net.minecraft.util.{MovingObjectPosition, EnumMovingObjectType} +import net.minecraft.util.{Vec3, MovingObjectPosition, EnumMovingObjectType} import net.minecraftforge.common.ForgeDirection import net.minecraftforge.fluids.FluidRegistry import scala.Some @@ -504,7 +504,9 @@ class Robot(val robot: tileentity.Robot) extends Computer(robot) { } private def pick(player: Player, range: Double) = { - val hit = player.rayTrace(range, 1) + val blockCenter = Vec3.createVectorHelper(player.posX + player.facing.offsetX, player.posY + player.facing.offsetY, player.posZ + player.facing.offsetZ) + val realRange = player.getDistance(blockCenter.xCoord + player.side.offsetX * range, blockCenter.yCoord + player.side.offsetY * range, blockCenter.zCoord + player.side.offsetZ * range) + val hit = player.rayTrace(realRange, 1) player.closestEntity[EntityLivingBase]() match { case Some(entity) if hit == null || player.getPosition(1).distanceTo(hit.hitVec) > player.getDistanceToEntity(entity) => new MovingObjectPosition(entity) case _ => hit diff --git a/li/cil/oc/server/component/robot/Player.scala b/li/cil/oc/server/component/robot/Player.scala index e9672753f..50e469657 100644 --- a/li/cil/oc/server/component/robot/Player.scala +++ b/li/cil/oc/server/component/robot/Player.scala @@ -30,7 +30,7 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na val robotInventory = new Inventory(this) inventory = robotInventory - var facing = ForgeDirection.UNKNOWN + var facing, side = ForgeDirection.UNKNOWN def world = robot.worldObj @@ -40,6 +40,7 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na def updatePositionAndRotation(facing: ForgeDirection, side: ForgeDirection) { this.facing = facing + this.side = side // Slightly offset in robot's facing to avoid glitches (e.g. Portal Gun). val direction = Vec3.createVectorHelper( facing.offsetX + side.offsetX * 0.5 + robot.facing.offsetX * 0.01,