fixed robot rendering in player hands and adjusted cable in-hand rendering a little; picking of robots now generates a stack with the current energy in the nbt tag; fixed hit tests for robots due to using range from settings directly after switching to player.rayTrace... derp

This commit is contained in:
Florian Nücke 2013-11-28 21:44:46 +01:00
parent ed7ab6b535
commit 062b530d1d
8 changed files with 56 additions and 24 deletions

View File

@ -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(

View File

@ -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

View File

@ -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

View File

@ -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 {

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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,