Fixed gutter and mixer item render

This commit is contained in:
Calclavia 2014-10-25 19:32:36 +08:00
parent 6fbc93b6cd
commit 79a8147f00
5 changed files with 366 additions and 344 deletions

View file

@ -17,8 +17,9 @@ import org.lwjgl.opengl.GL11
import resonant.api.recipe.{MachineRecipes, RecipeResource}
import resonant.content.factory.resources.RecipeType
import resonant.lib.render.{FluidRenderUtility, RenderUtility}
import resonant.lib.utility.{FluidUtility, WorldUtility}
import resonant.lib.utility.FluidUtility
import resonant.lib.utility.inventory.InventoryUtility
import resonant.lib.wrapper.BitmaskWrapper._
import resonantinduction.core.Reference
import resonantinduction.core.prefab.node.TilePressureNode
import universalelectricity.core.transform.region.Cuboid
@ -26,8 +27,8 @@ import universalelectricity.core.transform.vector.Vector3
object TileGutter
{
@SideOnly(Side.CLIENT) private[gutter] var MODEL: IModelCustom = _;
@SideOnly(Side.CLIENT) private[gutter] var TEXTURE: ResourceLocation = _;
@SideOnly(Side.CLIENT) private var MODEL: IModelCustom = _
@SideOnly(Side.CLIENT) private var TEXTURE: ResourceLocation = _
}
/**
@ -37,184 +38,187 @@ object TileGutter
*/
class TileGutter extends TilePressureNode(Material.rock)
{
tankNode = new FluidGravityNode(this)
setTextureName("material_wood_surface")
isOpaqueCube = false
normalRender = false
bounds = new Cuboid(0, 0, 0, 1, 0.99, 1)
override def getCollisionBoxes: java.lang.Iterable[Cuboid] =
{
val list: List[Cuboid] = new ArrayList[Cuboid]
val thickness = 0.1f
//Constructor
tankNode_$eq(new FluidGravityNode(this))
setTextureName("material_wood_surface")
isOpaqueCube(false)
normalRender(false)
bounds(new Cuboid(0, 0, 0, 1, 0.99, 1))
override def getCollisionBoxes: java.lang.Iterable[Cuboid] =
if (!renderSides.mask(ForgeDirection.DOWN))
{
val list: List[Cuboid] = new ArrayList[Cuboid]
val thickness: Float = 0.1F
if (!WorldUtility.isEnabledSide(renderSides, ForgeDirection.DOWN))
{
list.add(new Cuboid(0.0F, 0.0F, 0.0F, 1.0F, thickness, 1.0F))
}
if (!WorldUtility.isEnabledSide(renderSides, ForgeDirection.WEST))
{
list.add(new Cuboid(0.0F, 0.0F, 0.0F, thickness, 1.0F, 1.0F))
}
if (!WorldUtility.isEnabledSide(renderSides, ForgeDirection.NORTH))
{
list.add(new Cuboid(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, thickness))
}
if (!WorldUtility.isEnabledSide(renderSides, ForgeDirection.EAST))
{
list.add(new Cuboid(1.0F - thickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F))
}
if (!WorldUtility.isEnabledSide(renderSides, ForgeDirection.SOUTH))
{
list.add(new Cuboid(0.0F, 0.0F, 1.0F - thickness, 1.0F, 1.0F, 1.0F))
}
return list
list.add(new Cuboid(0.0F, 0.0F, 0.0F, 1.0F, thickness, 1.0F))
}
override def collide(entity: Entity)
if (!renderSides.mask(ForgeDirection.WEST))
{
if (getTank.getFluidAmount > 0)
{
for (i <- 2 to 6)
{
val dir: ForgeDirection = ForgeDirection.getOrientation(i)
val pressure: Int = getPressure(dir)
val _position: Vector3 = asVector3.add(dir)
val checkTile: TileEntity = _position.getTileEntity(world)
if (checkTile.isInstanceOf[TileGutter])
{
val deltaPressure: Int = pressure - (checkTile.asInstanceOf[TileGutter]).getPressure(dir.getOpposite)
entity.motionX += 0.01 * dir.offsetX * deltaPressure
entity.motionY += 0.01 * dir.offsetY * deltaPressure
entity.motionZ += 0.01 * dir.offsetZ * deltaPressure
}
}
if (getTank.getFluid.getFluid.getTemperature >= 373)
{
entity.setFire(5)
}
else
{
entity.extinguish
}
}
if (entity.isInstanceOf[EntityItem])
{
entity.noClip = true
}
list.add(new Cuboid(0.0F, 0.0F, 0.0F, thickness, 1.0F, 1.0F))
}
override def activate(player: EntityPlayer, side: Int, vector3: Vector3): Boolean =
if (!renderSides.mask(ForgeDirection.NORTH))
{
if (player.getCurrentEquippedItem != null)
{
var itemStack: ItemStack = player.getCurrentEquippedItem
val outputs: Array[RecipeResource] = MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER.name, itemStack)
if (outputs.length > 0)
{
if (!world.isRemote)
{
val drainAmount: Int = 50 + world.rand.nextInt(50)
val _drain: FluidStack = drain(ForgeDirection.UP, drainAmount, false)
if (_drain != null && _drain.amount > 0 && world.rand.nextFloat > 0.9)
{
if (world.rand.nextFloat > 0.1)
{
for (res <- outputs)
{
InventoryUtility.dropItemStack(world, new Vector3(player), res.getItemStack.copy, 0)
}
}
itemStack.stackSize -= 1
if (itemStack.stackSize <= 0)
{
itemStack = null
}
player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack)
}
drain(ForgeDirection.UP, drainAmount, true)
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "liquid.water", 0.5f, 1)
}
return true
}
}
return true
list.add(new Cuboid(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, thickness))
}
override def onFillRain
if (!renderSides.mask(ForgeDirection.EAST))
{
list.add(new Cuboid(1.0F - thickness, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F))
}
if (!renderSides.mask(ForgeDirection.SOUTH))
{
list.add(new Cuboid(0.0F, 0.0F, 1.0F - thickness, 1.0F, 1.0F, 1.0F))
}
return list
}
override def collide(entity: Entity)
{
if (getTank.getFluidAmount > 0)
{
for (i <- 2 to 6)
{
val dir: ForgeDirection = ForgeDirection.getOrientation(i)
val pressure: Int = getPressure(dir)
val _position: Vector3 = asVector3.add(dir)
val checkTile: TileEntity = _position.getTileEntity(world)
if (checkTile.isInstanceOf[TileGutter])
{
val deltaPressure: Int = pressure - (checkTile.asInstanceOf[TileGutter]).getPressure(dir.getOpposite)
entity.motionX += 0.01 * dir.offsetX * deltaPressure
entity.motionY += 0.01 * dir.offsetY * deltaPressure
entity.motionZ += 0.01 * dir.offsetZ * deltaPressure
}
}
if (getTank.getFluid.getFluid.getTemperature >= 373)
{
entity.setFire(5)
}
else
{
entity.extinguish
}
}
if (entity.isInstanceOf[EntityItem])
{
entity.noClip = true
}
}
override def activate(player: EntityPlayer, side: Int, vector3: Vector3): Boolean =
{
if (player.getCurrentEquippedItem != null)
{
var itemStack: ItemStack = player.getCurrentEquippedItem
val outputs: Array[RecipeResource] = MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER.name, itemStack)
if (outputs.length > 0)
{
if (!world.isRemote)
{
fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, 10), true)
val drainAmount: Int = 50 + world.rand.nextInt(50)
val _drain: FluidStack = drain(ForgeDirection.UP, drainAmount, false)
if (_drain != null && _drain.amount > 0 && world.rand.nextFloat > 0.9)
{
if (world.rand.nextFloat > 0.1)
{
for (res <- outputs)
{
InventoryUtility.dropItemStack(world, new Vector3(player), res.getItemStack.copy, 0)
}
}
itemStack.stackSize -= 1
if (itemStack.stackSize <= 0)
{
itemStack = null
}
player.inventory.setInventorySlotContents(player.inventory.currentItem, itemStack)
}
drain(ForgeDirection.UP, drainAmount, true)
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, "liquid.water", 0.5f, 1)
}
return true
}
}
return true
}
override def onFillRain()
{
if (!world.isRemote)
{
fill(ForgeDirection.UP, new FluidStack(FluidRegistry.WATER, 10), true)
}
}
override def renderDynamic(position: Vector3, frame: Float, pass: Int)
{
if (TileGutter.MODEL == null)
{
TileGutter.MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "gutter.tcn"))
}
if (TileGutter.TEXTURE == null)
{
TileGutter.TEXTURE = new ResourceLocation(Reference.domain, Reference.modelPath + "gutter.png")
}
override def renderDynamic(position: Vector3, frame: Float, pass: Int)
GL11.glPushMatrix()
GL11.glTranslated(position.x + 0.5, position.y + 0.5, position.z + 0.5)
render(0, renderSides)
if (world != null)
{
if (TileGutter.MODEL == null)
{
TileGutter.MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "gutter.tcn"))
}
if (TileGutter.TEXTURE == null)
{
TileGutter.TEXTURE = new ResourceLocation(Reference.domain, Reference.modelPath + "gutter.png")
}
GL11.glPushMatrix
GL11.glTranslated(position.x + 0.5, position.y + 0.5, position.z + 0.5)
val liquid: FluidStack = getTank.getFluid
val capacity: Int = getTank.getCapacity
render(0, renderSides)
if (world != null)
{
val tank: IFluidTank = getTank
val percentageFilled: Double = tank.getFluidAmount.asInstanceOf[Double] / tank.getCapacity.asInstanceOf[Double]
if (percentageFilled > 0.1)
{
GL11.glPushMatrix
GL11.glScaled(0.990, 0.99, 0.990)
val ySouthEast: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.SOUTH, ForgeDirection.EAST)
val yNorthEast: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.NORTH, ForgeDirection.EAST)
val ySouthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.SOUTH, ForgeDirection.WEST)
val yNorthWest: Double = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.NORTH, ForgeDirection.WEST)
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest)
GL11.glPopMatrix
}
}
GL11.glPopMatrix
val tank: IFluidTank = getTank
val percentageFilled = tank.getFluidAmount / tank.getCapacity.toDouble
if (percentageFilled > 0.1)
{
GL11.glPushMatrix()
GL11.glScaled(0.99, 0.99, 0.99)
val ySouthEast = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.SOUTH, ForgeDirection.EAST)
val yNorthEast = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.NORTH, ForgeDirection.EAST)
val ySouthWest = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.SOUTH, ForgeDirection.WEST)
val yNorthWest = FluidUtility.getAveragePercentageFilledForSides(classOf[TileGutter], percentageFilled, world, position, ForgeDirection.NORTH, ForgeDirection.WEST)
FluidRenderUtility.renderFluidTesselation(tank, ySouthEast, yNorthEast, ySouthWest, yNorthWest)
GL11.glPopMatrix()
}
}
def render(meta: Int, sides: Byte)
GL11.glPopMatrix()
}
def render(meta: Int, sides: Byte)
{
RenderUtility.bind(TileGutter.TEXTURE)
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
RenderUtility.bind(TileGutter.TEXTURE)
val thickness: Double = 0.055
val height: Double = 0.5
for (dir <- ForgeDirection.VALID_DIRECTIONS)
if (dir != ForgeDirection.UP && dir != ForgeDirection.DOWN)
{
GL11.glPushMatrix()
RenderUtility.rotateBlockBasedOnDirection(dir)
if (sides.mask(ForgeDirection.DOWN))
{
if (dir != ForgeDirection.UP && dir != ForgeDirection.DOWN)
{
GL11.glPushMatrix
RenderUtility.rotateBlockBasedOnDirection(dir)
if (WorldUtility.isEnabledSide(sides, ForgeDirection.DOWN))
{
GL11.glTranslatef(0, -0.075f, 0)
GL11.glScalef(1, 1.15f, 1)
}
if (!WorldUtility.isEnabledSide(sides, dir))
{
TileGutter.MODEL.renderOnly("left")
}
if (!WorldUtility.isEnabledSide(sides, dir) || !WorldUtility.isEnabledSide(sides, dir.getRotation(ForgeDirection.UP)))
{
TileGutter.MODEL.renderOnly("backCornerL")
}
GL11.glPopMatrix
}
GL11.glTranslatef(0, -0.075f, 0)
GL11.glScalef(1, 1.15f, 1)
}
if (!WorldUtility.isEnabledSide(sides, ForgeDirection.DOWN))
if (!sides.mask(dir))
{
TileGutter.MODEL.renderOnly("base")
TileGutter.MODEL.renderOnly("left")
}
if (!sides.mask(dir) || !sides.mask(dir.getRotation(ForgeDirection.UP)))
{
TileGutter.MODEL.renderOnly("backCornerL")
}
GL11.glPopMatrix()
}
}
if (!sides.mask(ForgeDirection.DOWN))
{
TileGutter.MODEL.renderOnly("base")
}
}
}

View file

@ -66,7 +66,6 @@ import universalelectricity.core.transform.vector.Vector3
ItemRenderHandler.register(Item.getItemFromBlock(MechanicalContent.blockWindTurbine), new RenderWindTurbine)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileMechanicalPiston], new RenderMechanicalPiston)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileGrindingWheel], new RenderGrindingWheel)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileMixer], new RenderMixer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileWaterTurbine], new RenderWaterTurbine)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileWindTurbine], new RenderWindTurbine)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[TileElectricTurbine], new RenderElectricTurbine)

View file

@ -25,11 +25,11 @@ class TileTankNode(material: Material) extends TileAdvanced(material) with INode
var tankNode: NodeTank = new NodeTank(this, 16)
protected var colorID: Int = 0
def getFluid(): FluidStack = getTank().getFluid
def getFluid: FluidStack = getTank.getFluid
def getFluidCapacity(): Int = getTank().getCapacity
def getFluidCapacity: Int = getTank.getCapacity
def getTank(): IFluidTank = tankNode
def getTank: IFluidTank = tankNode
override def readFromNBT(nbt: NBTTagCompound)
{

View file

@ -1,59 +1,47 @@
package resonantinduction.mechanical.mech.process.mixer
import org.lwjgl.opengl.GL11.glPopMatrix
import org.lwjgl.opengl.GL11.glPushMatrix
import org.lwjgl.opengl.GL11.glRotatef
import org.lwjgl.opengl.GL11.glTranslatef
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.item.ItemStack
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.IModelCustom
import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11.{glPopMatrix, glPushMatrix, glRotatef, glTranslatef}
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
/**
* @author Calclavia
*
*/
@SideOnly(Side.CLIENT) object RenderMixer
@SideOnly(Side.CLIENT)
object RenderMixer extends TileEntitySpecialRenderer with ISimpleItemRenderer
{
final val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "mixer.tcn"))
var TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "mixer.png")
}
val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "mixer.tcn"))
var TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "mixer.png")
@SideOnly(Side.CLIENT) class RenderMixer extends TileEntitySpecialRenderer with ISimpleItemRenderer
{
def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float)
def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float)
{
if (t.isInstanceOf[TileMixer])
{
if (t.isInstanceOf[TileMixer])
{
val tile: TileMixer = t.asInstanceOf[TileMixer]
glPushMatrix
glTranslatef(x.asInstanceOf[Float] + 0.5F, y.asInstanceOf[Float] + 0.5f, z.asInstanceOf[Float] + 0.5F)
RenderUtility.bind(RenderMixer.TEXTURE)
RenderMixer.MODEL.renderOnly("centerTop", "centerBase")
glPushMatrix
glRotatef(Math.toDegrees(tile.mechanicalNode.renderAngle.asInstanceOf[Float]).asInstanceOf[Float], 0, 1, 0)
RenderMixer. MODEL.renderAllExcept("centerTop", "centerBase")
glPopMatrix
glPopMatrix
}
}
val tile: TileMixer = t.asInstanceOf[TileMixer]
glPushMatrix()
glTranslatef(x.asInstanceOf[Float] + 0.5F, y.asInstanceOf[Float] + 0.5f, z.asInstanceOf[Float] + 0.5F)
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
{
glPushMatrix
GL11.glScalef(0.5f, 0.5f, 0.5f)
glTranslatef(0.5F, 0.5f, 0.5f)
RenderUtility.bind(RenderMixer.TEXTURE)
RenderMixer.MODEL.renderAll
glPopMatrix
glPopMatrix()
}
}
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
{
glPushMatrix()
GL11.glScalef(0.25f, 0.25f, 0.25f)
glTranslatef(0.5F, 0.5f, 0.5f)
RenderUtility.bind(RenderMixer.TEXTURE)
RenderMixer.MODEL.renderAll()
glPopMatrix()
}
}

View file

@ -2,25 +2,32 @@ package resonantinduction.mechanical.mech.process.mixer
import java.util.{LinkedHashSet, List, Set}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.entity.Entity
import net.minecraft.entity.item.EntityItem
import net.minecraft.init.Blocks
import net.minecraft.item.ItemStack
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.{AxisAlignedBB, ResourceLocation}
import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.IFluidBlock
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL11._
import resonant.api.recipe.MachineRecipes
import resonant.content.factory.resources.RecipeType
import resonant.content.factory.resources.block.BlockFluidMixture
import resonant.engine.ResonantEngine
import resonant.lib.render.RenderUtility
import resonant.lib.utility.Timer
import resonantinduction.core.Reference
import resonantinduction.mechanical.mech.TileMechanical
import universalelectricity.api.core.grid.INode
import universalelectricity.core.transform.rotation.Quaternion
import universalelectricity.core.transform.vector.Vector3
import scala.collection.JavaConversions._
/**
@ -28,169 +35,193 @@ import scala.collection.JavaConversions._
*/
object TileMixer
{
final val PROCESS_TIME: Int = 12 * 20
final val MIXER_ITEM_TIMER: Timer[EntityItem] = new Timer[EntityItem]
final val PROCESS_TIME: Int = 12 * 20
final val MIXER_ITEM_TIMER: Timer[EntityItem] = new Timer[EntityItem]
@SideOnly(Side.CLIENT) val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "mixer.tcn"))
@SideOnly(Side.CLIENT) var TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "mixer.png")
}
class TileMixer extends TileMechanical(Material.iron)
{
//Constructor
mechanicalNode = new MixerNode(this)
isOpaqueCube(false)
normalRender(false)
customItemRender(true)
setTextureName("material_metal_top")
private var areaBlockedFromMoving: Boolean = false
override def getNodes(nodes: List[INode])
//Constructor
mechanicalNode = new MixerNode(this)
isOpaqueCube(false)
normalRender(false)
customItemRender(true)
setTextureName("material_metal_top")
override def getNodes(nodes: List[INode])
{
if (mechanicalNode != null) nodes.add(this.mechanicalNode)
}
override def update
{
super.update
if (!world.isRemote && ticks % 3 == 0)
{
if (mechanicalNode != null) nodes.add(this.mechanicalNode)
this.areaBlockedFromMoving = checkIsBlocked
}
if (canWork)
{
doWork
}
}
/** Checks to see if the area around the mixer is blocked (3x3 - excluding center)
* @return true if there is a non-fluid block inside the bounds
*/
def checkIsBlocked: Boolean =
{
for (x <- -1 to 1)
{
for (z <- -1 to 1)
{
if (x != 0 && z != 0)
{
val block: Block = asVector3.add(x, 0, z).getBlock(world)
if (block != null && !(block.isInstanceOf[IFluidBlock]))
{
return true
}
}
}
}
return false
}
/**
* Can this machine work this tick?
*
* @return
*/
def canWork: Boolean =
{
return mechanicalNode.getAngularSpeed(ForgeDirection.UNKNOWN) != 0 && !areaBlockedFromMoving
}
def doWork
{
var didWork: Boolean = false
val aabb: AxisAlignedBB = AxisAlignedBB.getBoundingBox(this.xCoord - 1, this.yCoord, this.zCoord - 1, this.xCoord + 2, this.yCoord + 1, this.zCoord + 2)
val entities: List[_] = this.worldObj.getEntitiesWithinAABB(classOf[Entity], aabb)
val processItems: Set[EntityItem] = new LinkedHashSet[EntityItem]
for (obj <- entities)
{
val entity: Entity = obj.asInstanceOf[Entity]
val originalPosition: Vector3 = new Vector3(entity)
val relativePosition: Vector3 = originalPosition.clone.subtract(asVector3.add(0.5))
relativePosition.transform(new Quaternion(-mechanicalNode.getAngularSpeed(ForgeDirection.UNKNOWN), new Vector3(1, 0, 0)))
val newPosition: Vector3 = asVector3.add(0.5).add(relativePosition)
val difference: Vector3 = newPosition.subtract(originalPosition).multiply(0.5)
entity.addVelocity(difference.x, difference.y, difference.z)
entity.onGround = false
if (entity.isInstanceOf[EntityItem])
{
if (MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER.name, (entity.asInstanceOf[EntityItem]).getEntityItem).length > 0)
{
processItems.add(entity.asInstanceOf[EntityItem])
}
}
}
override def update
for (processingItem <- processItems)
{
super.update
if (!world.isRemote && ticks % 3 == 0)
if (!TileMixer.MIXER_ITEM_TIMER.containsKey(processingItem))
{
TileMixer.MIXER_ITEM_TIMER.put(processingItem, TileMixer.PROCESS_TIME)
}
if (!processingItem.isDead && asVector3.add(0.5).distance(new Vector3(processingItem)) < 2)
{
val timeLeft: Int = TileMixer.MIXER_ITEM_TIMER.decrease(processingItem)
if (timeLeft <= 0)
{
this.areaBlockedFromMoving = checkIsBlocked
}
if (canWork)
{
doWork
}
}
if (doneWork(processingItem))
{
processingItem.getEntityItem.stackSize -= 1
/** Checks to see if the area around the mixer is blocked (3x3 - excluding center)
* @return true if there is a non-fluid block inside the bounds
*/
def checkIsBlocked: Boolean =
{
for (x <- -1 to 1)
{
for (z <- -1 to 1)
if (processingItem.getEntityItem.stackSize <= 0)
{
if (x != 0 && z != 0)
{
val block: Block = asVector3.add(x, 0, z).getBlock(world)
if (block != null && !(block.isInstanceOf[IFluidBlock]))
{
return true
}
}
}
}
return false
}
/**
* Can this machine work this tick?
*
* @return
*/
def canWork: Boolean =
{
return mechanicalNode.getAngularSpeed(ForgeDirection.UNKNOWN) != 0 && !areaBlockedFromMoving
}
def doWork
{
var didWork: Boolean = false
val aabb: AxisAlignedBB = AxisAlignedBB.getBoundingBox(this.xCoord - 1, this.yCoord, this.zCoord - 1, this.xCoord + 2, this.yCoord + 1, this.zCoord + 2)
val entities: List[_] = this.worldObj.getEntitiesWithinAABB(classOf[Entity], aabb)
val processItems: Set[EntityItem] = new LinkedHashSet[EntityItem]
for (obj <- entities)
{
val entity: Entity = obj.asInstanceOf[Entity]
val originalPosition: Vector3 = new Vector3(entity)
val relativePosition: Vector3 = originalPosition.clone.subtract(asVector3.add(0.5))
relativePosition.transform(new Quaternion(-mechanicalNode.getAngularSpeed(ForgeDirection.UNKNOWN), new Vector3(1, 0, 0)))
val newPosition: Vector3 = asVector3.add(0.5).add(relativePosition)
val difference: Vector3 = newPosition.subtract(originalPosition).multiply(0.5)
entity.addVelocity(difference.x, difference.y, difference.z)
entity.onGround = false
if (entity.isInstanceOf[EntityItem])
{
if (MachineRecipes.INSTANCE.getOutput(RecipeType.MIXER.name, (entity.asInstanceOf[EntityItem]).getEntityItem).length > 0)
{
processItems.add(entity.asInstanceOf[EntityItem])
}
}
}
for (processingItem <- processItems)
{
if (!TileMixer.MIXER_ITEM_TIMER.containsKey(processingItem))
{
TileMixer.MIXER_ITEM_TIMER.put(processingItem, TileMixer.PROCESS_TIME)
}
if (!processingItem.isDead && asVector3.add(0.5).distance(new Vector3(processingItem)) < 2)
{
val timeLeft: Int = TileMixer.MIXER_ITEM_TIMER.decrease(processingItem)
if (timeLeft <= 0)
{
if (doneWork(processingItem))
{
if (({
processingItem.getEntityItem.stackSize -= 1;
processingItem.getEntityItem.stackSize
}) <= 0)
{
processingItem.setDead
TileMixer.MIXER_ITEM_TIMER.remove(processingItem)
}
else
{
processingItem.setEntityItemStack(processingItem.getEntityItem)
TileMixer.MIXER_ITEM_TIMER.put(processingItem, TileMixer.PROCESS_TIME)
}
}
}
else
{
processingItem.delayBeforeCanPickup = 20
this.worldObj.spawnParticle("bubble", processingItem.posX, processingItem.posY, processingItem.posZ, (Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3)
}
didWork = true
processingItem.setDead
TileMixer.MIXER_ITEM_TIMER.remove(processingItem)
}
else
{
TileMixer.MIXER_ITEM_TIMER.remove(processingItem)
processingItem.setEntityItemStack(processingItem.getEntityItem)
TileMixer.MIXER_ITEM_TIMER.put(processingItem, TileMixer.PROCESS_TIME)
}
}
}
if (didWork)
else
{
if (this.ticks % 20 == 0)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.prefix + "mixer", 0.5f, 1)
}
processingItem.delayBeforeCanPickup = 20
this.worldObj.spawnParticle("bubble", processingItem.posX, processingItem.posY, processingItem.posZ, (Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3, (Math.random - 0.5f) * 3)
}
didWork = true
}
else
{
TileMixer.MIXER_ITEM_TIMER.remove(processingItem)
}
}
private def doneWork(entity: EntityItem): Boolean =
if (didWork)
{
val mixPosition: Vector3 = new Vector3(entity.posX, yCoord, entity.posZ)
if (mixPosition.getBlock(world) ne getBlockType)
{
val block: Block = mixPosition.getBlock(worldObj)
val blockFluidFinite: Block = ResonantEngine.resourceFactory.getMixture(ResonantEngine.resourceFactory.getName(entity.getEntityItem))
if (blockFluidFinite != null)
{
if (block.isInstanceOf[BlockFluidMixture])
{
val itemStack: ItemStack = entity.getEntityItem.copy
if ((block.asInstanceOf[BlockFluidMixture]).mix(worldObj, mixPosition.xi, mixPosition.yi, mixPosition.zi, itemStack))
{
worldObj.notifyBlocksOfNeighborChange(mixPosition.xi, mixPosition.yi, mixPosition.zi, mixPosition.getBlock(worldObj))
return true
}
}
else if (block != null && (block == Blocks.water || block == Blocks.flowing_water))
{
mixPosition.setBlock(worldObj, blockFluidFinite)
}
}
}
return false
if (this.ticks % 20 == 0)
{
this.worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.prefix + "mixer", 0.5f, 1)
}
}
}
private var areaBlockedFromMoving: Boolean = false
private def doneWork(entity: EntityItem): Boolean =
{
val mixPosition: Vector3 = new Vector3(entity.posX, yCoord, entity.posZ)
if (mixPosition.getBlock(world) ne getBlockType)
{
val block: Block = mixPosition.getBlock(worldObj)
val blockFluidFinite: Block = ResonantEngine.resourceFactory.getMixture(ResonantEngine.resourceFactory.getName(entity.getEntityItem))
if (blockFluidFinite != null)
{
if (block.isInstanceOf[BlockFluidMixture])
{
val itemStack: ItemStack = entity.getEntityItem.copy
if ((block.asInstanceOf[BlockFluidMixture]).mix(worldObj, mixPosition.xi, mixPosition.yi, mixPosition.zi, itemStack))
{
worldObj.notifyBlocksOfNeighborChange(mixPosition.xi, mixPosition.yi, mixPosition.zi, mixPosition.getBlock(worldObj))
return true
}
}
else if (block != null && (block == Blocks.water || block == Blocks.flowing_water))
{
mixPosition.setBlock(worldObj, blockFluidFinite)
}
}
}
return false
}
override def renderDynamic(position: Vector3, frame: Float, pass: Int): Unit =
{
GL11.glPushMatrix()
GL11.glTranslated(position.x + 0.5, position.y + 0.5, position.z + 0.5)
RenderUtility.bind(RenderMixer.TEXTURE)
RenderMixer.MODEL.renderOnly("centerTop", "centerBase")
glPushMatrix()
glRotatef(Math.toDegrees(mechanicalNode.renderAngle.asInstanceOf[Float]).asInstanceOf[Float], 0, 1, 0)
RenderMixer.MODEL.renderAllExcept("centerTop", "centerBase")
glPopMatrix()
GL11.glPopMatrix()
}
override def renderInventory(itemStack: ItemStack)
{
glPushMatrix()
GL11.glScalef(0.7f, 0.7f, 0.7f)
glTranslatef(0.5F, 0.5f, 0.5f)
RenderUtility.bind(RenderMixer.TEXTURE)
RenderMixer.MODEL.renderAll()
glPopMatrix()
}
}