mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
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:
parent
ed7ab6b535
commit
062b530d1d
@ -20,13 +20,12 @@ object BlockRenderer extends ISimpleBlockRenderingHandler {
|
|||||||
GL11.glPushMatrix()
|
GL11.glPushMatrix()
|
||||||
Delegator.subBlock(block, metadata) match {
|
Delegator.subBlock(block, metadata) match {
|
||||||
case Some(cable: Cable) =>
|
case Some(cable: Cable) =>
|
||||||
GL11.glTranslatef(0, 0.3f, 0)
|
|
||||||
GL11.glScalef(1.6f, 1.6f, 1.6f)
|
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)
|
CableRenderer.renderCable(ForgeDirection.DOWN.flag)
|
||||||
case Some(proxy@(_: RobotProxy | _: RobotAfterimage)) =>
|
case Some(proxy@(_: RobotProxy | _: RobotAfterimage)) =>
|
||||||
GL11.glTranslatef(0, -0.1f, 0)
|
|
||||||
GL11.glScalef(1.5f, 1.5f, 1.5f)
|
GL11.glScalef(1.5f, 1.5f, 1.5f)
|
||||||
|
GL11.glTranslatef(-0.5f, -0.45f, -0.5f)
|
||||||
RobotRenderer.renderChassis()
|
RobotRenderer.renderChassis()
|
||||||
case _ =>
|
case _ =>
|
||||||
val renderFace = Array(
|
val renderFace = Array(
|
||||||
|
@ -6,7 +6,7 @@ import net.minecraft.entity.EntityLivingBase
|
|||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.tileentity.TileEntity
|
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.IBlockAccess
|
||||||
import net.minecraft.world.World
|
import net.minecraft.world.World
|
||||||
import net.minecraftforge.common.ForgeDirection
|
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 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 getRenderColor = 0xFFFFFF
|
||||||
|
|
||||||
def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 255
|
def getLightOpacity(world: World, x: Int, y: Int, z: Int) = 255
|
||||||
|
@ -14,7 +14,7 @@ import net.minecraft.entity.player.EntityPlayer
|
|||||||
import net.minecraft.entity.{EnumCreatureType, Entity, EntityLivingBase}
|
import net.minecraft.entity.{EnumCreatureType, Entity, EntityLivingBase}
|
||||||
import net.minecraft.item.{ItemBlock, ItemStack}
|
import net.minecraft.item.{ItemBlock, ItemStack}
|
||||||
import net.minecraft.tileentity.TileEntity
|
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.minecraft.world.{IBlockAccess, World}
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
import powercrystals.minefactoryreloaded.api.rednet.{IRedNetNetworkContainer, RedNetConnectionType, IConnectableRedNet}
|
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)
|
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) =
|
override def getRenderColor(metadata: Int) =
|
||||||
subBlock(metadata) match {
|
subBlock(metadata) match {
|
||||||
case Some(subBlock) => subBlock.getRenderColor
|
case Some(subBlock) => subBlock.getRenderColor
|
||||||
|
@ -5,12 +5,19 @@ import li.cil.oc.common.tileentity
|
|||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.world.{IBlockAccess, World}
|
import net.minecraft.world.{IBlockAccess, World}
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
import net.minecraft.util.MovingObjectPosition
|
||||||
|
|
||||||
class RobotAfterimage(val parent: SpecialDelegator) extends SpecialDelegate {
|
class RobotAfterimage(val parent: SpecialDelegator) extends SpecialDelegate {
|
||||||
val unlocalizedName = "RobotAfterimage"
|
val unlocalizedName = "RobotAfterimage"
|
||||||
|
|
||||||
override val showInItemList = false
|
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) = {
|
override def breakBlock(world: World, x: Int, y: Int, z: Int, blockId: Int) = {
|
||||||
super.breakBlock(world, x, y, z, blockId)
|
super.breakBlock(world, x, y, z, blockId)
|
||||||
findMovingRobot(world, x, y, z) match {
|
findMovingRobot(world, x, y, z) match {
|
||||||
|
@ -8,8 +8,7 @@ import li.cil.oc.{Settings, OpenComputers}
|
|||||||
import net.minecraft.entity.EntityLivingBase
|
import net.minecraft.entity.EntityLivingBase
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.util.{MovingObjectPosition, AxisAlignedBB, Vec3}
|
||||||
import net.minecraft.util.{AxisAlignedBB, Vec3}
|
|
||||||
import net.minecraft.world.{IBlockAccess, World}
|
import net.minecraft.world.{IBlockAccess, World}
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
|
||||||
@ -29,6 +28,12 @@ class RobotProxy(val parent: SpecialDelegator) extends Computer with SpecialDele
|
|||||||
tooltip.addAll(Tooltip.get(unlocalizedName))
|
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) = {
|
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)
|
super.onBlockPlacedBy(world, x, y, z, entity, stack)
|
||||||
if (!world.isRemote) ((entity, world.getBlockTileEntity(x, y, z)) match {
|
if (!world.isRemote) ((entity, world.getBlockTileEntity(x, y, z)) match {
|
||||||
case (player: robot.Player, proxy: tileentity.RobotProxy) =>
|
case (player: robot.Player, proxy: tileentity.RobotProxy) =>
|
||||||
Some((proxy, player.robot.owner))
|
Some((proxy.robot, player.robot.owner))
|
||||||
case (player: EntityPlayer, proxy: tileentity.RobotProxy) =>
|
case (player: EntityPlayer, proxy: tileentity.RobotProxy) =>
|
||||||
Some((proxy, player.getCommandSenderName))
|
Some((proxy.robot, player.getCommandSenderName))
|
||||||
case _ => None
|
case _ => None
|
||||||
}) match {
|
}) match {
|
||||||
case Some((proxy, owner)) =>
|
case Some((robot, owner)) =>
|
||||||
proxy.robot.owner = owner
|
robot.owner = owner
|
||||||
if (stack.hasTagCompound) {
|
robot.parseItemStack(stack)
|
||||||
proxy.robot.battery.changeBuffer(stack.getTagCompound.getInteger(Settings.namespace + "storedEnergy"))
|
|
||||||
}
|
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def onBlockRemovedBy(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) = {
|
override def onBlockRemovedBy(world: World, x: Int, y: Int, z: Int, player: EntityPlayer) = {
|
||||||
if (!world.isRemote) world.getBlockTileEntity(x, y, z) match {
|
if (!world.isRemote) world.getBlockTileEntity(x, y, z) match {
|
||||||
case proxy: tileentity.RobotProxy if !player.capabilities.isCreativeMode || proxy.globalBuffer > 0 =>
|
case proxy: tileentity.RobotProxy if !player.capabilities.isCreativeMode || proxy.globalBuffer > 1 =>
|
||||||
val stack = createItemStack()
|
parent.dropBlockAsItem(world, x, y, z, proxy.robot.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 _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
super.onBlockRemovedBy(world, x, y, z, player)
|
super.onBlockRemovedBy(world, x, y, z, player)
|
||||||
|
@ -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 isAnimatingMove = animationTicksLeft > 0 && moveDirection != ForgeDirection.UNKNOWN
|
||||||
|
|
||||||
def isAnimatingSwing = animationTicksLeft > 0 && swingingTool
|
def isAnimatingSwing = animationTicksLeft > 0 && swingingTool
|
||||||
|
@ -10,7 +10,7 @@ import net.minecraft.entity.{EntityLivingBase, Entity}
|
|||||||
import net.minecraft.entity.item.EntityItem
|
import net.minecraft.entity.item.EntityItem
|
||||||
import net.minecraft.inventory.{IInventory, ISidedInventory}
|
import net.minecraft.inventory.{IInventory, ISidedInventory}
|
||||||
import net.minecraft.item.{ItemStack, ItemBlock}
|
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.common.ForgeDirection
|
||||||
import net.minecraftforge.fluids.FluidRegistry
|
import net.minecraftforge.fluids.FluidRegistry
|
||||||
import scala.Some
|
import scala.Some
|
||||||
@ -504,7 +504,9 @@ class Robot(val robot: tileentity.Robot) extends Computer(robot) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def pick(player: Player, range: Double) = {
|
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 {
|
player.closestEntity[EntityLivingBase]() match {
|
||||||
case Some(entity) if hit == null || player.getPosition(1).distanceTo(hit.hitVec) > player.getDistanceToEntity(entity) => new MovingObjectPosition(entity)
|
case Some(entity) if hit == null || player.getPosition(1).distanceTo(hit.hitVec) > player.getDistanceToEntity(entity) => new MovingObjectPosition(entity)
|
||||||
case _ => hit
|
case _ => hit
|
||||||
|
@ -30,7 +30,7 @@ class Player(val robot: Robot) extends EntityPlayer(robot.world, Settings.get.na
|
|||||||
val robotInventory = new Inventory(this)
|
val robotInventory = new Inventory(this)
|
||||||
inventory = robotInventory
|
inventory = robotInventory
|
||||||
|
|
||||||
var facing = ForgeDirection.UNKNOWN
|
var facing, side = ForgeDirection.UNKNOWN
|
||||||
|
|
||||||
def world = robot.worldObj
|
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) {
|
def updatePositionAndRotation(facing: ForgeDirection, side: ForgeDirection) {
|
||||||
this.facing = facing
|
this.facing = facing
|
||||||
|
this.side = side
|
||||||
// Slightly offset in robot's facing to avoid glitches (e.g. Portal Gun).
|
// Slightly offset in robot's facing to avoid glitches (e.g. Portal Gun).
|
||||||
val direction = Vec3.createVectorHelper(
|
val direction = Vec3.createVectorHelper(
|
||||||
facing.offsetX + side.offsetX * 0.5 + robot.facing.offsetX * 0.01,
|
facing.offsetX + side.offsetX * 0.5 + robot.facing.offsetX * 0.01,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user