1.7 update work

This commit is contained in:
Calclavia 2014-07-16 20:07:57 -04:00
parent eeee9532ab
commit ffc011cbb5
20 changed files with 330 additions and 384 deletions

View file

@ -83,7 +83,7 @@ public class ItemBlockTank extends ItemBlock implements IFluidContainerItem
if (tile instanceof TileFluidDistribution)
{
((TileFluidDistribution) tile).setSubID(stack.getItemDamage());
((TileFluidDistribution) tile).getInternalTank().fill(getFluid(stack), true);
((TileFluidDistribution) tile).getTank().fill(getFluid(stack), true);
}
return true;

View file

@ -30,7 +30,7 @@ import resonant.lib.utility.render.RenderBlockUtility;
import archaic.Archaic;
import resonantinduction.core.Reference;
import resonantinduction.core.grid.fluid.distribution.FluidDistributionGrid;
import resonantinduction.core.grid.fluid.distribution.IFluidDistributor;
import resonantinduction.core.grid.fluid.distribution.TFluidDistributor;
import resonantinduction.core.grid.fluid.distribution.TankNetwork;
import resonantinduction.core.grid.fluid.distribution.TileFluidDistribution;
import universalelectricity.api.UniversalElectricity;
@ -85,9 +85,9 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
@Override
public int getLightValue(IBlockAccess access)
{
if (getInternalTank().getFluid() != null)
if (getTank().getFluid() != null)
{
return getInternalTank().getFluid().getFluid().getLuminosity();
return getTank().getFluid().getFluid().getLuminosity();
}
return super.getLightValue(access);
}
@ -119,7 +119,7 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
{
if (tileEntity instanceof TileTank)
{
getNetwork().merge(((IFluidDistributor) tileEntity).getNetwork());
getNetwork().merge(((TFluidDistributor) tileEntity).getNetwork());
renderSides = WorldUtility.setEnableSide(renderSides, side, true);
connectedBlocks[side.ordinal()] = tileEntity;
}
@ -153,7 +153,7 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
if (!fluid.getFluid().isGaseous())
{
GL11.glScaled(0.99, 0.99, 0.99);
FluidTank tank = ((TileTank) tileEntity).getInternalTank();
FluidTank tank = ((TileTank) tileEntity).getTank();
double percentageFilled = (double) tank.getFluidAmount() / (double) tank.getCapacity();
double ySouthEast = FluidUtility.getAveragePercentageFilledForSides(TileTank.class, percentageFilled, tileEntity.worldObj, new Vector3(tileEntity), ForgeDirection.SOUTH, ForgeDirection.EAST);
@ -166,7 +166,7 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
{
GL11.glTranslated(-0.5, -0.5, -0.5);
GL11.glScaled(0.99, 0.99, 0.99);
int capacity = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getInternalTank().getCapacity() : fluid.amount;
int capacity = tileEntity instanceof TileTank ? ((TileTank) tileEntity).getTank().getCapacity() : fluid.amount;
double filledPercentage = (double) fluid.amount / (double) capacity;
double renderPercentage = fluid.getFluid().isGaseous() ? 1 : filledPercentage;
@ -198,7 +198,7 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
@Override
public boolean renderDynamic(Vector3 position, boolean isItem, float frame)
{
renderTank(TileTank.this, position.x, position.y, position.z, getInternalTank().getFluid());
renderTank(TileTank.this, position.x, position.y, position.z, getTank().getFluid());
return false;
}
};
@ -278,9 +278,9 @@ public class TileTank extends TileFluidDistribution implements IComparatorInputO
ItemStack itemStack = new ItemStack(Archaic.blockTank, 1, 0);
if (itemStack != null)
{
if (getInternalTank() != null && getInternalTank().getFluid() != null)
if (getTank() != null && getTank().getFluid() != null)
{
FluidStack stack = getInternalTank().getFluid();
FluidStack stack = getTank().getFluid();
if (stack != null)
{

View file

@ -10,8 +10,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fluids.FluidTank;
import resonant.lib.utility.LanguageUtility;
import resonantinduction.archaic.fluid.tank.TileTank;
import resonantinduction.archaic.fluid.tank.TileTank;
/** Waila support for tanks
*
@ -24,7 +22,7 @@ public class WailaFluidTank implements IWailaDataProvider
TileEntity tile = accessor.getTileEntity();
if (tile instanceof TileTank)
{
FluidTank tank = ((TileTank) tile).getInternalTank();
FluidTank tank = ((TileTank) tile).getTank();
if (tank != null && tank.getFluid() != null)
{
currenttip.add(LanguageUtility.getLocal("info.waila.tank.fluid") + " " + tank.getFluid().getFluid().getLocalizedName());

View file

@ -29,9 +29,14 @@ object ResonantInduction
var proxy: CommonProxy = _
/** Recipe Types */
object RecipeType extends Enumeration
final object RecipeType extends Enumeration
{
final val CRUSHER, GRINDER, MIXER, SMELTER, SAWMILL = Value
implicit class ExtendedValue(value: Value)
{
def name = value.toString
}
}
@EventHandler

View file

@ -2,12 +2,15 @@ package resonantinduction.core
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import net.minecraft.block.Block
import net.minecraft.item.ItemStack
import net.minecraftforge.common.config.Configuration
import resonant.api.recipe.QuantumAssemblerRecipes
import resonant.lib.config.Config
import resonant.lib.config.ConfigEvent.PostConfigEvent
import resonant.lib.prefab.poison.PotionRadiation
import scala.collection.convert.wrapAll._
/** @author Calclavia */
object Settings
{
@ -57,7 +60,7 @@ object Settings
@SubscribeEvent
def configEvent(evt: PostConfigEvent)
{
QuantumAssemblerRecipes.RECIPES.addAll(quantumAssemblerRecipes.map(Block.blockRegistry.getObject(_).asInstanceOf[Block]).toSet)
QuantumAssemblerRecipes.RECIPES.addAll(quantumAssemblerRecipes.map(x => new ItemStack(Block.blockRegistry.getObject(x).asInstanceOf[Block])).toList)
PotionRadiation.INSTANCE.getId
}
}

View file

@ -5,7 +5,7 @@ import net.minecraft.tileentity.TileEntity
import net.minecraft.world.World
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.core.grid.Node
import universalelectricity.core.transform.vector.Vector3
import universalelectricity.core.transform.vector.VectorWorld
/**
* A node that works with Forge Multipart
@ -18,8 +18,8 @@ abstract class MultipartNode[N <: Node[N]](parent: INodeProvider) extends Node[N
return if (parent.isInstanceOf[TMultiPart]) (parent.asInstanceOf[TMultiPart]).world else if (parent.isInstanceOf[TileEntity]) (parent.asInstanceOf[TileEntity]).getWorldObj else null
}
override def position: Vector3 =
override def position: VectorWorld =
{
return if (parent.isInstanceOf[TMultiPart]) new Vector3((parent.asInstanceOf[TMultiPart]).x, (parent.asInstanceOf[TMultiPart]).y, (parent.asInstanceOf[TMultiPart]).z) else if (parent.isInstanceOf[TileEntity]) new Vector3(parent.asInstanceOf[TileEntity]) else null
return if (parent.isInstanceOf[TMultiPart]) new VectorWorld(parent.asInstanceOf[TMultiPart].world, parent.asInstanceOf[TMultiPart].x, parent.asInstanceOf[TMultiPart].y, parent.asInstanceOf[TMultiPart].z) else if (parent.isInstanceOf[TileEntity]) new VectorWorld(parent.asInstanceOf[TileEntity]) else null
}
}

View file

@ -21,12 +21,12 @@ import universalelectricity.core.transform.vector.Vector3
*
* @author DarkGuardsman
*/
object TileFluidNode extends Enumeration
object TileFluidNodeProvider extends Enumeration
{
final val PACKET_DESCRIPTION, PACKET_RENDER, PACKET_TANK = Value
}
abstract class TileFluidNode(material: Material) extends SpatialTile(material) with INodeProvider with IFluidHandler with TPacketIDReceiver with TPacketIDSender
abstract class TileFluidNodeProvider(material: Material) extends SpatialTile(material) with INodeProvider with IFluidHandler with TPacketIDReceiver with TPacketIDSender
{
protected var tank: FluidTank
protected var pressure = 0
@ -73,19 +73,19 @@ abstract class TileFluidNode(material: Material) extends SpatialTile(material) w
{
super.write(buf, id)
if (id == TileFluidNode.PACKET_DESCRIPTION)
if (id == TileFluidNodeProvider.PACKET_DESCRIPTION.id)
{
buf <<< colorID
buf <<< renderSides
buf <<< tank
}
else if (id == TileFluidNode.PACKET_RENDER)
else if (id == TileFluidNodeProvider.PACKET_RENDER.id)
{
buf <<< colorID
buf <<< renderSides
}
else if (id == TileFluidNode.PACKET_TANK)
else if (id == TileFluidNodeProvider.PACKET_TANK.id)
{
buf <<< tank
buf <<< pressure
@ -96,19 +96,19 @@ abstract class TileFluidNode(material: Material) extends SpatialTile(material) w
{
if (world.isRemote)
{
if (id == TileFluidNode.PACKET_DESCRIPTION)
if (id == TileFluidNodeProvider.PACKET_DESCRIPTION.id)
{
colorID = buf.readInt
renderSides = buf.readByte
tank = buf.readTank()
}
else if (id == TileFluidNode.PACKET_RENDER)
else if (id == TileFluidNodeProvider.PACKET_RENDER.id)
{
colorID = buf.readInt
renderSides = buf.readByte
markRender
}
else if (id == TileFluidNode.PACKET_TANK)
else if (id == TileFluidNodeProvider.PACKET_TANK.id)
{
tank = buf.readTank()
pressure = buf.readInt
@ -117,21 +117,21 @@ abstract class TileFluidNode(material: Material) extends SpatialTile(material) w
}
}
override def getDescriptionPacket: Packet = ResonantInduction.packetHandler.toMCPacket(PacketManager.request(this, TileFluidNode.PACKET_DESCRIPTION))
override def getDescriptionPacket: Packet = ResonantInduction.packetHandler.toMCPacket(PacketManager.request(this, TileFluidNodeProvider.PACKET_DESCRIPTION.id))
def sendRenderUpdate
{
if (!world.isRemote)
ResonantInduction.packetHandler.sendToAll(PacketManager.request(this, TileFluidNode.PACKET_RENDER))
ResonantInduction.packetHandler.sendToAll(PacketManager.request(this, TileFluidNodeProvider.PACKET_RENDER.id))
}
def sendTankUpdate
{
if (!world.isRemote)
ResonantInduction.packetHandler.sendToAllAround(PacketManager.request(this, TileFluidNode.PACKET_TANK), world, new Vector3(this), 60)
ResonantInduction.packetHandler.sendToAllAround(PacketManager.request(this, TileFluidNodeProvider.PACKET_TANK.id), world, new Vector3(this), 60)
}
def onFluidChanged
def onFluidChanged()
{
if (!worldObj.isRemote)
{

View file

@ -9,7 +9,7 @@ import universalelectricity.core.grid.{TickingGrid, UpdateTicker}
*
* @author DarkCow, Calclavia
*/
abstract class FluidDistributionGrid extends TickingGrid[IFluidDistributor]
abstract class FluidDistributionGrid extends TickingGrid[TFluidDistributor]
{
val tank = new FluidTank(0)
var needsUpdate = false
@ -33,9 +33,9 @@ abstract class FluidDistributionGrid extends TickingGrid[IFluidDistributor]
UpdateTicker.addUpdater(this)
}
override def reconstructNode(node: IFluidDistributor)
override def reconstructNode(node: TFluidDistributor)
{
val connectorTank: FluidTank = node.getInternalTank
val connectorTank: FluidTank = node.getTank
if (connectorTank != null)
{
@ -58,9 +58,9 @@ abstract class FluidDistributionGrid extends TickingGrid[IFluidDistributor]
}
}
def fill(source: IFluidDistributor, from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
def fill(source: TFluidDistributor, from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
val fill: Int = this.getTank.fill(resource.copy, doFill)
val fill: Int = tank.fill(resource.copy, doFill)
if (fill > 0)
{
needsUpdate = true
@ -69,11 +69,11 @@ abstract class FluidDistributionGrid extends TickingGrid[IFluidDistributor]
return fill
}
def drain(source: IFluidDistributor, from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
def drain(source: TFluidDistributor, from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
{
if (resource != null && resource.isFluidEqual(getTank.getFluid))
if (resource != null && resource.isFluidEqual(tank.getFluid))
{
val drain: FluidStack = getTank.drain(resource.amount, doDrain)
val drain: FluidStack = tank.drain(resource.amount, doDrain)
needsUpdate = true
UpdateTicker.addUpdater(this)
return drain
@ -81,17 +81,17 @@ abstract class FluidDistributionGrid extends TickingGrid[IFluidDistributor]
return null
}
def drain(source: IFluidDistributor, from: ForgeDirection, resource: Int, doDrain: Boolean): FluidStack =
def drain(source: TFluidDistributor, from: ForgeDirection, resource: Int, doDrain: Boolean): FluidStack =
{
val drain: FluidStack = getTank.drain(resource, doDrain)
val drain: FluidStack = tank.drain(resource, doDrain)
needsUpdate = true
UpdateTicker.addUpdater(this)
return drain
}
def getTankInfo: Array[FluidTankInfo] =
def tankInfo: Array[FluidTankInfo] =
{
return Array[FluidTankInfo](getTank.getInfo)
return Array[FluidTankInfo](tank.getInfo)
}
override def toString: String =

View file

@ -1,21 +0,0 @@
package resonantinduction.core.grid.fluid.distribution;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.IFluidHandler;
import universalelectricity.api.core.grid.INodeProvider;
/**
* Generic interface for any tile that acts as part of a fluid network. Generally network assume
* that each part can only support one fluid tank internally
*
* @author DarkGuardsman
*/
public interface IFluidDistributor extends INodeProvider, IFluidHandler
{
/**
* FluidTank that the network will have access to fill or drain
*/
public FluidTank getInternalTank();
public void onFluidChanged();
}

View file

@ -0,0 +1,21 @@
package resonantinduction.core.grid.fluid.distribution
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.fluids.{FluidTank, IFluidHandler}
import universalelectricity.api.core.grid.INodeProvider
/**
* Generic interface for any tile that acts as part of a fluid network. Generally network assume
* that each part can only support one fluid tank internally
*
* @author DarkGuardsman
*/
abstract trait TFluidDistributor extends TileEntity with INodeProvider with IFluidHandler
{
/**
* FluidTank that the network will have access to fill or drain
*/
def getTank: FluidTank
def onFluidChanged
}

View file

@ -1,11 +1,10 @@
package resonantinduction.core.grid.fluid.distribution
import java.util.HashMap
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.fluids.FluidStack
import resonant.lib.utility.FluidUtility
import scala.collection.JavaConversions._
import scala.collection.mutable
/** Network that handles connected tanks
@ -17,78 +16,63 @@ class TankNetwork extends FluidDistributionGrid
override def update()
{
val networkTankFluid: FluidStack = tank.getFluid
var lowestY: Int = 255
var highestY: Int = 0
val networkTankFluid = tank.getFluid
if (getNodes.size > 0)
{
var totalFluid: Int = if (networkTankFluid != null) networkTankFluid.amount else 0
val heightCount: HashMap[Integer, Integer] = new HashMap[_, _]
val heightPriorityQueue = new mutable.PriorityQueue[IFluidDistributor]()(Ordering.by(
(a: IFluidDistributor, b: IFluidDistributor) =>
var totalFluid = if (networkTankFluid != null) networkTankFluid.amount else 0
/**
* Creates a priority queue with tanks in the bottom as highest priority.
*/
val heightPriorityQueue = new mutable.PriorityQueue[TFluidDistributor]()(new Ordering[TFluidDistributor]
{
def compare(a: TFluidDistributor, b: TFluidDistributor): Int =
{
if (networkTankFluid != null && networkTankFluid.getFluid.isGaseous) return 0
val wa: TileEntity = a.asInstanceOf[TileEntity]
val wb: TileEntity = b.asInstanceOf[TileEntity]
if (wa.yCoord > wb.yCoord)
a
else
b
return b.asInstanceOf[TileEntity].yCoord - a.asInstanceOf[TileEntity].yCoord
}
))
})
heightPriorityQueue ++= getNodes()
var didChange = false
import scala.collection.JavaConversions._
for (connector <- this.getNodes)
{
if (connector.isInstanceOf[TileEntity])
{
val yCoord: Int = (connector.asInstanceOf[TileEntity]).yCoord
if (yCoord < lowestY)
{
lowestY = yCoord
}
if (yCoord > highestY)
{
highestY = yCoord
}
heightPriorityQueue.add(connector)
heightCount.put(yCoord, if (heightCount.containsKey(yCoord)) heightCount.get(yCoord) + 1 else 1)
}
}
var didChange: Boolean = false
while (!heightPriorityQueue.isEmpty)
{
val distributeNode: IFluidDistributor = heightPriorityQueue.poll
val yCoord: Int = (distributeNode.asInstanceOf[TileEntity]).yCoord
var connectorCount: Int = heightCount.get(yCoord)
val distributeNode = heightPriorityQueue.dequeue()
val yCoord = distributeNode.yCoord
val connectorCount = heightPriorityQueue count (_.yCoord == yCoord)
if (totalFluid <= 0)
{
distributeNode.getInternalTank.setFluid(null)
distributeNode.getTank.setFluid(null)
distributeNode.onFluidChanged
continue //todo: continue is not supported
}
val fluidPer: Int = totalFluid / connectorCount
val deltaFluidAmount: Int = fluidPer - distributeNode.getInternalTank.getFluidAmount
val current: Int = distributeNode.getInternalTank.getFluidAmount
if (deltaFluidAmount > 0)
{
val filled: Int = distributeNode.getInternalTank.fill(FluidUtility.getStack(networkTankFluid, deltaFluidAmount), false)
distributeNode.getInternalTank.fill(FluidUtility.getStack(networkTankFluid, deltaFluidAmount / 10), true)
totalFluid -= current + filled
}
else
{
val drain: FluidStack = distributeNode.getInternalTank.drain(Math.abs(deltaFluidAmount), false)
distributeNode.getInternalTank.drain(Math.abs(deltaFluidAmount / 10), true)
if (drain != null) totalFluid -= current - drain.amount
val fluidPer: Int = totalFluid / connectorCount
val deltaFluidAmount: Int = fluidPer - distributeNode.getTank.getFluidAmount
val current: Int = distributeNode.getTank.getFluidAmount
if (deltaFluidAmount > 0)
{
val filled: Int = distributeNode.getTank.fill(FluidUtility.getStack(networkTankFluid, deltaFluidAmount), false)
distributeNode.getTank.fill(FluidUtility.getStack(networkTankFluid, deltaFluidAmount / 10), true)
totalFluid -= current + filled
}
else
{
val drain: FluidStack = distributeNode.getTank.drain(Math.abs(deltaFluidAmount), false)
distributeNode.getTank.drain(Math.abs(deltaFluidAmount / 10), true)
if (drain != null) totalFluid -= current - drain.amount
}
if (deltaFluidAmount != 0) didChange = true
distributeNode.onFluidChanged
}
if (deltaFluidAmount != 0) didChange = true
if (connectorCount > 1) ({connectorCount -= 1; connectorCount + 1 })
heightCount.put(yCoord, connectorCount)
distributeNode.onFluidChanged
}
if (!didChange) needsUpdate = false
}
}

View file

@ -1,19 +1,18 @@
package resonantinduction.core.grid.fluid.distribution
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.IFluidHandler
import resonant.lib.utility.WorldUtility
import resonantinduction.core.grid.MultipartNode
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.core.transform.vector.Vector3
class TankNode(parent: INodeProvider) extends MultipartNode[TankNode](parent) with IFluidHandler
{
var maxFlowRate: Int = 20
var maxPressure: Int = 100
private var pressure: Int = 0
var connectedSides: Byte = 0
var onChange: () => Unit = null
@ -46,47 +45,35 @@ class TankNode(parent: INodeProvider) extends MultipartNode[TankNode](parent) wi
{
connections.clear
if (this.worldObj != null && !this.worldObj.isRemote)
if (world != null && !world.isRemote)
{
val previousConnections: Byte = renderSides
connectedBlocks = new Array[AnyRef](6)
renderSides = 0
val previousSides = connectedSides
connectedSides = 0
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
this.validateConnectionSide(new Vector3(this).add(dir).getTileEntity(worldObj), dir)
}
if (previousConnections != renderSides)
{
getNetwork.update
getNetwork.reconstruct
onChange.apply()
sendRenderUpdate
}
}
}
val tile = (position + dir).getTileEntity
/**
* Checks to make sure the connection is valid to the tileEntity
*
* @param tileEntity - the tileEntity being checked
* @param side - side the connection is too
*/
def validateConnectionSide(tileEntity: TileEntity, side: ForgeDirection)
{
if (!this.worldObj.isRemote)
{
if (tileEntity.isInstanceOf[IFluidDistributor])
if (tile.isInstanceOf[TFluidDistributor])
{
connections.put(tile.asInstanceOf[TFluidDistributor].getNode(classOf[TankNode], dir.getOpposite), dir)
connectedSides = WorldUtility.setEnableSide(connectedSides, dir, true)
}
}
if (previousSides != connectedSides)
{
this.getNetwork.merge((tileEntity.asInstanceOf[IFluidDistributor]).getNetwork)
renderSides = WorldUtility.setEnableSide(renderSides, side, true)
connectedBlocks(side.ordinal) = tileEntity
//TODO: Check and fix
getGrid.reconstruct()
onChange.apply()
}
}
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
{
return (source.isInstanceOf[TankNode]) && (connectionMap & (1 << from.ordinal)) != 0
//TODO: Check this
return source.isInstanceOf[TankNode]
}
override def load(nbt: NBTTagCompound)

View file

@ -3,25 +3,27 @@ package resonantinduction.core.grid.fluid.distribution
import net.minecraft.block.material.Material
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{Fluid, FluidStack, FluidTankInfo}
import resonantinduction.core.grid.fluid.TileFluidNode
import resonantinduction.core.grid.fluid.TileFluidNodeProvider
/**
* A prefab class for tiles that use the fluid network.
*
* @author DarkGuardsman
*/
abstract class TileFluidDistribution(material: Material) extends TileFluidNode(material) with IFluidDistributor
abstract class TileFluidDistribution(material: Material) extends TileFluidNodeProvider(material) with TFluidDistributor
{
override def start
tankNode.onChange = () => sendRenderUpdate
override def start()
{
super.start
tankNode.reconstruct
super.start()
tankNode.reconstruct()
}
override def invalidate
override def invalidate()
{
tankNode.deconstruct
super.invalidate
tankNode.deconstruct()
super.invalidate()
}
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
@ -51,7 +53,7 @@ abstract class TileFluidDistribution(material: Material) extends TileFluidNode(m
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
{
return Array[FluidTankInfo](getInternalTank.getInfo)
return Array[FluidTankInfo](getTank.getInfo)
}
/**

View file

@ -1,24 +1,22 @@
package resonantinduction.core.grid.fluid.pressure
import java.util.{HashMap, Iterator}
import codechicken.multipart.TMultiPart
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.tileentity.TileEntity
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{FluidStack, FluidTank, IFluidHandler}
import resonantinduction.core.grid.MultipartNode
import resonantinduction.core.grid.fluid.distribution.TFluidDistributor
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.core.grid.Node
import universalelectricity.core.transform.vector.Vector3
class FluidPressureNode(parent: INodeProvider) extends MultipartNode[FluidPressureNode](parent)
import scala.collection.convert.wrapAll._
class FluidPressureNode(parent: INodeProvider) extends MultipartNode[AnyRef](parent)
{
var maxFlowRate: Int = 20
var maxPressure: Int = 100
protected var connectionMap: Byte = Byte.parseByte("111111", 2)
private var pressure: Int = 0
protected var connectionMap: Byte = java.lang.Byte.parseByte("111111", 2)
private var pressure = 0
def genericParent = parent.asInstanceOf[TFluidDistributor]
def setConnection(connectionMap: Byte): FluidPressureNode =
{
@ -35,27 +33,28 @@ class FluidPressureNode(parent: INodeProvider) extends MultipartNode[FluidPressu
}
}
protected def updatePressure
protected def updatePressure()
{
var totalPressure: Int = 0
var findCount: Int = 0
var minPressure: Int = 0
var maxPressure: Int = 0
val it: Iterator[Map.Entry[AnyRef, ForgeDirection]] = new HashMap[_, _](connections).entrySet.iterator
while (it.hasNext)
var totalPressure = 0
val connectionSize = connections.size
var minPressure = 0
var maxPressure = 0
connections
.filterKeys(_.isInstanceOf[FluidPressureNode])
.map({ case (k: AnyRef, v: ForgeDirection) => (k.asInstanceOf[FluidPressureNode], v) })
.foreach
{
val entry: Map.Entry[AnyRef, ForgeDirection] = it.next
val obj: AnyRef = entry.getKey
if (obj.isInstanceOf[FluidPressureNode])
case (node: FluidPressureNode, dir: ForgeDirection) =>
{
val pressure: Int = (obj.asInstanceOf[FluidPressureNode]).getPressure(entry.getValue.getOpposite)
val pressure = node.getPressure(dir.getOpposite)
minPressure = Math.min(pressure, minPressure)
maxPressure = Math.max(pressure, maxPressure)
totalPressure += pressure
findCount += 1
}
}
if (findCount == 0)
if (connectionSize == 0)
{
setPressure(0)
}
@ -69,47 +68,50 @@ class FluidPressureNode(parent: INodeProvider) extends MultipartNode[FluidPressu
{
maxPressure -= 1
}
setPressure(Math.max(minPressure, Math.min(maxPressure, totalPressure / findCount + Integer.signum(totalPressure))))
setPressure(Math.max(minPressure, Math.min(maxPressure, totalPressure / connectionSize + Integer.signum(totalPressure))))
}
}
def distribute
{
val it: Iterator[Map.Entry[AnyRef, ForgeDirection]] = new HashMap[_, _](connections).entrySet.iterator
while (it.hasNext)
connections.foreach
{
val entry: Map.Entry[_, ForgeDirection] = it.next
val obj: AnyRef = entry.getKey
val dir: ForgeDirection = entry.getValue
if (obj.isInstanceOf[FluidPressureNode])
case (obj: AnyRef, dir: ForgeDirection) =>
{
val otherNode: FluidPressureNode = obj.asInstanceOf[FluidPressureNode]
val pressureA: Int = getPressure(dir)
val pressureB: Int = otherNode.getPressure(dir.getOpposite)
if (pressureA >= pressureB)
if (obj.isInstanceOf[FluidPressureNode])
{
val tankA: FluidTank = parent.getPressureTank
if (tankA != null)
val otherNode: FluidPressureNode = obj.asInstanceOf[FluidPressureNode]
val pressureA = getPressure(dir)
val pressureB = otherNode.getPressure(dir.getOpposite)
/**
* High pressure from this node flows to low pressure nodes.
*/
if (pressureA >= pressureB)
{
val fluidA: FluidStack = tankA.getFluid
if (fluidA != null)
val tankA = genericParent.getTank
if (tankA != null)
{
val amountA: Int = fluidA.amount
if (amountA > 0)
val fluidA: FluidStack = tankA.getFluid
if (fluidA != null)
{
val tankB: FluidTank = otherNode.parent.getPressureTank
if (tankB != null)
val amountA: Int = fluidA.amount
if (amountA > 0)
{
val amountB: Int = tankB.getFluidAmount
var quantity: Int = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * getMaxFlowRate else 0, Math.min((amountA - amountB) / 2, getMaxFlowRate))
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
if (quantity > 0)
val tankB: FluidTank = otherNode.genericParent.getTank
if (tankB != null)
{
val drainStack: FluidStack = parent.drain(dir.getOpposite, quantity, false)
if (drainStack != null && drainStack.amount > 0)
val amountB: Int = tankB.getFluidAmount
var quantity: Int = Math.max(if (pressureA > pressureB) (pressureA - pressureB) * getMaxFlowRate else 0, Math.min((amountA - amountB) / 2, getMaxFlowRate))
quantity = Math.min(Math.min(quantity, tankB.getCapacity - amountB), amountA)
if (quantity > 0)
{
parent.drain(dir.getOpposite, otherNode.parent.fill(dir, drainStack, true), true)
val drainStack: FluidStack = genericParent.drain(dir.getOpposite, quantity, false)
if (drainStack != null && drainStack.amount > 0)
{
genericParent.drain(dir.getOpposite, otherNode.genericParent.fill(dir, drainStack, true), true)
}
}
}
}
@ -117,30 +119,30 @@ class FluidPressureNode(parent: INodeProvider) extends MultipartNode[FluidPressu
}
}
}
}
else if (obj.isInstanceOf[IFluidHandler])
{
val fluidHandler: IFluidHandler = obj.asInstanceOf[IFluidHandler]
val pressure: Int = getPressure(dir)
val tankPressure: Int = if (fluidHandler.isInstanceOf[INodeProvider]) (fluidHandler.asInstanceOf[INodeProvider]).getNode(classOf[FluidPressureNode], dir.getOpposite).getPressure(dir.getOpposite) else 0
val sourceTank: FluidTank = parent.getPressureTank
val transferAmount: Int = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * getMaxFlowRate
if (pressure > tankPressure)
else if (obj.isInstanceOf[IFluidHandler])
{
if (sourceTank.getFluidAmount > 0 && transferAmount > 0)
val fluidHandler: IFluidHandler = obj.asInstanceOf[IFluidHandler]
val pressure: Int = getPressure(dir)
val tankPressure: Int = if (fluidHandler.isInstanceOf[INodeProvider]) (fluidHandler.asInstanceOf[INodeProvider]).getNode(classOf[FluidPressureNode], dir.getOpposite).getPressure(dir.getOpposite) else 0
val sourceTank = genericParent.getTank
val transferAmount: Int = (Math.max(pressure, tankPressure) - Math.min(pressure, tankPressure)) * getMaxFlowRate
if (pressure > tankPressure)
{
val drainStack: FluidStack = parent.drain(dir.getOpposite, transferAmount, false)
parent.drain(dir.getOpposite, fluidHandler.fill(dir.getOpposite, drainStack, true), true)
}
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
val drainStack: FluidStack = fluidHandler.drain(dir.getOpposite, transferAmount, false)
if (drainStack != null)
if (sourceTank.getFluidAmount > 0 && transferAmount > 0)
{
fluidHandler.drain(dir.getOpposite, parent.fill(dir.getOpposite, drainStack, true), true)
val drainStack: FluidStack = genericParent.drain(dir.getOpposite, transferAmount, false)
genericParent.drain(dir.getOpposite, fluidHandler.fill(dir.getOpposite, drainStack, true), true)
}
}
else if (pressure < tankPressure)
{
if (transferAmount > 0)
{
val drainStack: FluidStack = fluidHandler.drain(dir.getOpposite, transferAmount, false)
if (drainStack != null)
{
fluidHandler.drain(dir.getOpposite, genericParent.fill(dir.getOpposite, drainStack, true), true)
}
}
}
}
@ -175,11 +177,13 @@ class FluidPressureNode(parent: INodeProvider) extends MultipartNode[FluidPressu
*/
override def doRecache
{
connections.clear
connections.clear()
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
val tile: TileEntity = position.add(dir).getTileEntity(world)
if (tile.isInstanceOf[Nothing])
val tile = (position + dir).getTileEntity
if (tile.isInstanceOf[INodeProvider])
{
val check: FluidPressureNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[FluidPressureNode], dir.getOpposite)
if (check != null && canConnect(dir, check) && check.canConnect(dir.getOpposite, this))

View file

@ -3,33 +3,34 @@ package resonantinduction.core.grid.fluid.pressure
import net.minecraft.block.material.Material
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.{FluidContainerRegistry, FluidStack, FluidTank, FluidTankInfo}
import resonantinduction.core.grid.fluid.TileFluidNode
import resonantinduction.core.grid.fluid.TileFluidNodeProvider
import universalelectricity.api.core.grid.INode
/**
* A prefab class for tiles that use the fluid network.
*
* @author DarkGuardsman
*/
abstract class TilePressureNode(material: Material) extends TileFluidNode(material)
abstract class TilePressureNode(material: Material) extends TileFluidNodeProvider(material)
{
protected val node: FluidPressureNode
protected val pressureNode: FluidPressureNode
tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
override def start
{
super.start
node.reconstruct
pressureNode.reconstruct
}
override def invalidate
{
node.deconstruct
pressureNode.deconstruct
super.invalidate
}
override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
val fill: Int = getInternalTank.fill(resource, doFill)
val fill: Int = tank.fill(resource, doFill)
onFluidChanged
return fill
}
@ -63,12 +64,14 @@ abstract class TilePressureNode(material: Material) extends TileFluidNode(materi
def getPressureTank: FluidTank =
{
return getInternalTank
return tank
}
def getNode(nodeType: Class[_ <: Nothing], from: ForgeDirection): Nothing =
override def getNode[N <: INode](nodeType: Class[N], from: ForgeDirection): N =
{
if (nodeType.isAssignableFrom(node.getClass)) return node
return null
if (nodeType.isAssignableFrom(pressureNode.getClass))
return pressureNode.asInstanceOf[N]
return null.asInstanceOf[N]
}
}

View file

@ -50,23 +50,14 @@ object MultipartUtility
if (!w.blockExists(x, y, z)) return _default
val b: Block = w.getBlock(x, y, z)
if (b == null) return false
if (b eq Blocks.glowstone || b eq Blocks.piston || b eq Blocks.sticky_piston || b eq Blocks.piston_extension) return true
if (b == Blocks.glowstone || b == Blocks.piston || b == Blocks.sticky_piston || b == Blocks.piston_extension) return true
return b.isSideSolid(w, x, y, z, side)
}
val dyes: Array[String] = Array("dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray", "dyePink", "dyeLime", "dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite")
def isDye(is: ItemStack): Int =
{
val dyes: Array[String] = Array("dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray", "dyePink", "dyeLime", "dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite")
{
var i: Int = 0
while (i < dyes.length)
{
{
if (OreDictionary.getOreID(is) != -1 && (OreDictionary.getOreName(OreDictionary.getOreID(is)) == dyes(i))) return i
}
({i += 1; i - 1 })
}
}
return -1
return (0 until dyes.size) find (i => OreDictionary.getOreID(is) != -1 && (OreDictionary.getOreName(OreDictionary.getOreID(is)) == dyes(i))) getOrElse (-1)
}
}

View file

@ -29,10 +29,10 @@ class PacketMultiPart extends PacketType
this.z = part.z
this.partID = partID
this << x
this << y
this << z
this << partID
this <<< x
this <<< y
this <<< z
this <<< partID
}
def encodeInto(ctx: ChannelHandlerContext, buffer: ByteBuf)
@ -65,11 +65,11 @@ class PacketMultiPart extends PacketType
def handle(player: EntityPlayer)
{
val tile: TileEntity = player.getEntityWorld.getTileEntity(this.x, this.y, this.z)
val tile = player.getEntityWorld.getTileEntity(this.x, this.y, this.z)
if (tileEntity.isInstanceOf[TileMultipart])
if (tile.isInstanceOf[TileMultipart])
{
val part = (tileEntity.asInstanceOf[TileMultipart]).partMap(data.readInt)
val part = tile.asInstanceOf[TileMultipart].partMap(data.readInt)
if (part.isInstanceOf[TPacketReceiver])
{

View file

@ -1,18 +1,16 @@
package resonantinduction.core.prefab.part
import java.util.ArrayList
import java.util.Collections
import java.util.List
import codechicken.lib.data.{MCDataInput, MCDataOutput}
import codechicken.multipart.TMultiPart
import net.minecraft.block.BlockColored
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.Item
import net.minecraft.item.ItemShears
import net.minecraft.item.ItemStack
import net.minecraft.item.{Item, ItemShears, ItemStack}
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.MovingObjectPosition
import codechicken.lib.data.MCDataInput
import codechicken.lib.data.MCDataOutput
import scala.collection.mutable
/**
* @author Calclavia
@ -20,15 +18,15 @@ import codechicken.lib.data.MCDataOutput
*/
object PartColorableMaterial
{
final val DEFAULT_COLOR: Int = 15
final val defaultColor: Int = 15
}
abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart with TraitPart
{
var color: Int = DEFAULT_COLOR
var material: M = null
var isInsulated: Boolean = false
var requiresInsulation: Boolean = true
var color: Int = PartColorableMaterial.defaultColor
var material: M = _
var isInsulated = false
var requiresInsulation = true
/**
* Material Methods
@ -45,10 +43,7 @@ abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart
def setMaterial(i: Int)
def getMaterialID: Int =
{
return material.ordinal
}
def getMaterialID: Int
/**
* Insulation Methods
@ -56,7 +51,7 @@ abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart
def setInsulated(insulated: Boolean)
{
this.isInsulated = insulated
this.color = DEFAULT_COLOR
this.color = PartColorableMaterial.defaultColor
if (!this.world.isRemote)
{
tile.notifyPartChange(this)
@ -138,7 +133,7 @@ abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart
{
if (!world.isRemote && player.capabilities.isCreativeMode)
{
tile.dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color))))
tile.dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.func_150031_c(color))))
}
this.setInsulated(false)
return true
@ -149,7 +144,7 @@ abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart
{
player.inventory.decrStackSize(player.inventory.currentItem, 1)
}
this.setInsulated(BlockColored.getDyeFromBlock(itemStack.getItemDamage))
this.setInsulated(BlockColored.func_150031_c(itemStack.getItemDamage))
return true
}
}
@ -157,7 +152,7 @@ abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart
{
if (!world.isRemote && !player.capabilities.isCreativeMode)
{
tile.dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color))))
tile.dropItems(Collections.singletonList(new ItemStack(insulationType, 1, BlockColored.func_150031_c(color))))
}
this.setInsulated(false)
}
@ -169,11 +164,11 @@ abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart
override def getDrops: Iterable[ItemStack] =
{
val drops: List[ItemStack] = new ArrayList[ItemStack]
val drops = mutable.Set.empty[ItemStack]
drops.add(getItem)
if (requiresInsulation && isInsulated)
{
drops.add(new ItemStack(insulationType, 1, BlockColored.getBlockFromDye(color)))
drops.add(new ItemStack(insulationType, 1, BlockColored.func_150031_c(color)))
}
return drops
}
@ -199,11 +194,9 @@ abstract class PartColorableMaterial[M](insulationType: Item) extends TMultiPart
case 1 =>
this.isInsulated = packet.readBoolean
this.tile.markRender
break //todo: break is not supported
case 2 =>
this.color = packet.readInt
this.tile.markRender
break //todo: break is not supported
}
}

View file

@ -3,15 +3,15 @@ package resonantinduction.core.resource
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.InputStream
import java.util.{ArrayList, HashMap, Iterator, List}
import java.util.{ArrayList, HashMap, List}
import javax.imageio.ImageIO
import cpw.mods.fml.common.eventhandler.SubscribeEvent
import cpw.mods.fml.common.registry.{GameRegistry, LanguageRegistry}
import cpw.mods.fml.common.registry.GameRegistry
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.block.Block
import net.minecraft.client.Minecraft
import net.minecraft.item.crafting.FurnaceRecipes
import net.minecraft.init.{Blocks, Items}
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.util.{IIcon, ResourceLocation}
import net.minecraftforge.client.event.TextureStitchEvent
@ -19,13 +19,14 @@ import net.minecraftforge.fluids.{BlockFluidFinite, FluidContainerRegistry, Flui
import net.minecraftforge.oredict.OreDictionary
import resonant.api.recipe.MachineRecipes
import resonant.lib.config.Config
import resonant.lib.recipe.Recipes
import resonant.lib.utility.LanguageUtility
import resonantinduction.core.ResonantInduction.RecipeType
import resonantinduction.core.prefab.FluidColored
import resonantinduction.core.resource.fluid.{BlockFluidMaterial, BlockFluidMixture}
import resonantinduction.core.{CoreContent, Reference, ResonantInduction, Settings}
import scala.collection.JavaConversions._
import scala.collection.JavaConversions._
import scala.collection.mutable
/**
@ -53,6 +54,27 @@ object ResourceGenerator
@Config(category = "resource-generator", comment = "Allow the Resource Generator to make ore dictionary compatible recipes?")
private val allowOreDictCompatibility: Boolean = true
/**
* Automatically generate resources from available ingots
*/
def generateOreResources()
{
OreDictionary.registerOre("ingotGold", Items.gold_ingot)
OreDictionary.registerOre("ingotIron", Items.iron_ingot)
OreDictionary.registerOre("oreGold", Blocks.gold_ore)
OreDictionary.registerOre("oreIron", Blocks.iron_ore)
OreDictionary.registerOre("oreLapis", Blocks.lapis_ore)
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Blocks.stone))
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Blocks.cobblestone, Blocks.gravel)
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Blocks.stone, Blocks.cobblestone)
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Blocks.chest, new ItemStack(Blocks.planks, 7, 0))
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Blocks.cobblestone, Blocks.sand)
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Blocks.gravel, Blocks.sand)
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Blocks.glass, Blocks.sand)
materials filter (name => OreDictionary.getOres("ore" + LanguageUtility.capitalizeFirst(name)).size > 0) foreach (generate)
}
def generate(materialName: String)
{
val nameCaps = LanguageUtility.capitalizeFirst(materialName)
@ -73,37 +95,35 @@ object ResourceGenerator
if (enableAllFluids)
{
val fluidMolten: FluidColored = new FluidColored(materialNameToMolten(materialName))
fluidMolten.setDensity(7)
fluidMolten.setViscosity(5000)
fluidMolten.setTemperature(273 + 1538)
/**
* Generate molten fluid
*/
val fluidMolten = new FluidColored(materialNameToMolten(materialName)).setDensity(7).setViscosity(5000).setTemperature(273 + 1538)
FluidRegistry.registerFluid(fluidMolten)
LanguageRegistry.instance.addStringLocalization(fluidMolten.getUnlocalizedName, LanguageUtility.getLocal("tooltip.molten") + " " + localizedName)
val blockFluidMaterial: BlockFluidMaterial = new BlockFluidMaterial(fluidMolten)
GameRegistry.registerBlock(blockFluidMaterial, "molten" + nameCaps)
ResonantInduction.blockMoltenFluid.put(getID(materialName), blockFluidMaterial)
FluidContainerRegistry.registerFluidContainer(fluidMolten, CoreContent.BucketMolten.getStackFromMaterial(materialName))
val fluidMixture: FluidColored = new FluidColored(materialNameToMixture(materialName))
val blockFluidMaterial = new BlockFluidMaterial(fluidMolten)
CoreContent.manager.newBlock("molten" + nameCaps, blockFluidMaterial)
FluidContainerRegistry.registerFluidContainer(fluidMolten, CoreContent.bucketMolten.getStackFromMaterial(materialName))
/**
* Generate mixture fluid
*/
val fluidMixture = new FluidColored(materialNameToMixture(materialName))
FluidRegistry.registerFluid(fluidMixture)
val blockFluidMixture: BlockFluidMixture = new BlockFluidMixture(fluidMixture)
LanguageRegistry.instance.addStringLocalization(fluidMixture.getUnlocalizedName, localizedName + " " + LanguageUtility.getLocal("tooltip.mixture"))
val blockFluidMixture = new BlockFluidMixture(fluidMixture)
GameRegistry.registerBlock(blockFluidMixture, "mixture" + nameCaps)
ResonantInduction.blockMixtureFluids.put(getID(materialName), blockFluidMixture)
FluidContainerRegistry.registerFluidContainer(fluidMixture, CoreContent.BucketMixture.getStackFromMaterial(materialName))
FluidContainerRegistry.registerFluidContainer(fluidMixture, CoreContent.bucketMixture.getStackFromMaterial(materialName))
if (allowOreDictCompatibility)
{
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps)
}
else
{
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(fluidMolten, FluidContainerRegistry.BUCKET_VOLUME), "ingot" + nameCaps)
}
}
val dust: ItemStack = CoreContent.dust.getStackFromMaterial(materialName)
val rubble: ItemStack = CoreContent.rubble.getStackFromMaterial(materialName)
val refinedDust: ItemStack = CoreContent.refinedDust.getStackFromMaterial(materialName)
if (allowOreDictCompatibility)
{
OreDictionary.registerOre("rubble" + nameCaps, CoreContent.rubble.getStackFromMaterial(materialName))
@ -117,45 +137,17 @@ object ResourceGenerator
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, rubble, dust, dust)
MachineRecipes.INSTANCE.addRecipe(RecipeType.MIXER.name, dust, refinedDust)
}
FurnaceRecipes.smelting.addSmelting(dust.itemID, dust.getItemDamage, OreDictionary.getOres("ingot" + nameCaps).get(0).copy, 0.7f)
val smeltResult: ItemStack = OreDictionary.getOres("ingot" + nameCaps).get(0).copy
FurnaceRecipes.smelting.addSmelting(refinedDust.itemID, refinedDust.getItemDamage, smeltResult, 0.7f)
Recipes +=(dust.copy, OreDictionary.getOres("ingot" + nameCaps).get(0).copy, 0.7f)
val smeltResult = OreDictionary.getOres("ingot" + nameCaps).get(0).copy
Recipes +=(refinedDust.copy, smeltResult, 0.7f)
if (OreDictionary.getOres("ore" + nameCaps).size > 0)
{
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, "ore" + nameCaps, "rubble" + nameCaps)
}
}
def generateOreResources()
{
OreDictionary.registerOre("ingotGold", Item.ingotGold)
OreDictionary.registerOre("ingotIron", Item.ingotIron)
OreDictionary.registerOre("oreGold", Block.oreGold)
OreDictionary.registerOre("oreIron", Block.oreIron)
OreDictionary.registerOre("oreLapis", Block.oreLapis)
MachineRecipes.INSTANCE.addRecipe(RecipeType.SMELTER.name, new FluidStack(FluidRegistry.LAVA, FluidContainerRegistry.BUCKET_VOLUME), new ItemStack(Block.stone))
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Block.cobblestone, Block.gravel)
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Block.stone, Block.cobblestone)
MachineRecipes.INSTANCE.addRecipe(RecipeType.CRUSHER.name, Block.chest, new ItemStack(Block.planks, 7, 0))
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Block.cobblestone, Block.sand)
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Block.gravel, Block.sand)
MachineRecipes.INSTANCE.addRecipe(RecipeType.GRINDER.name, Block.glass, Block.sand)
val it: Iterator[String] = materials.keySet.iterator
while (it.hasNext)
{
val materialName: String = it.next
val nameCaps: String = LanguageUtility.capitalizeFirst(materialName)
if (OreDictionary.getOres("ore" + nameCaps).size > 0)
{
generate(materialName)
}
else
{
it.remove
}
}
}
@SideOnly(Side.CLIENT)
def computeColors
{
@ -184,7 +176,8 @@ object ResourceGenerator
* @param itemStack
* @return The RGB hexadecimal color code.
*/
@SideOnly(Side.CLIENT) def getAverageColor(itemStack: ItemStack): Int =
@SideOnly(Side.CLIENT)
def getAverageColor(itemStack: ItemStack): Int =
{
var totalR: Int = 0
var totalG: Int = 0
@ -201,37 +194,27 @@ object ResourceGenerator
var iconString: String = icon.getIconName
if (iconString != null && !iconString.contains("MISSING_ICON_ITEM"))
{
iconString = (if (iconString.contains(":")) iconString.replace(":", ":" + Reference.ITEM_TEXTURE_DIRECTORY) else Reference.ITEM_TEXTURE_DIRECTORY + iconString) + ".png"
iconString = (if (iconString.contains(":")) iconString.replace(":", ":" + Reference.itemTextureDirectory) else Reference.itemTextureDirectory + iconString) + ".png"
val textureLocation: ResourceLocation = new ResourceLocation(iconString)
val inputstream: InputStream = Minecraft.getMinecraft.getResourceManager.getResource(textureLocation).getInputStream
val bufferedimage: BufferedImage = ImageIO.read(inputstream)
val width: Int = bufferedimage.getWidth
val height: Int = bufferedimage.getWidth
/**
* Read every single pixel of the texture.
*/
for (x <- 0 until width; y <- 0 until height)
{
var x: Int = 0
while (x < width)
val rgb: Color = new Color(bufferedimage.getRGB(x, y))
val luma: Double = 0.2126 * rgb.getRed + 0.7152 * rgb.getGreen + 0.0722 * rgb.getBlue
if (luma > 40)
{
{
{
var y: Int = 0
while (y < height)
{
{
val rgb: Color = new Color(bufferedimage.getRGB(x, y))
val luma: Double = 0.2126 * rgb.getRed + 0.7152 * rgb.getGreen + 0.0722 * rgb.getBlue
if (luma > 40)
{
totalR += rgb.getRed
totalG += rgb.getGreen
totalB += rgb.getBlue
colorCount += 1
}
}
({y += 1; y - 1 })
}
}
}
({x += 1; x - 1 })
totalR += rgb.getRed
totalG += rgb.getGreen
totalB += rgb.getBlue
colorCount += 1
}
}
}
@ -249,7 +232,7 @@ object ResourceGenerator
{
case e: Exception =>
{
ResonantInduction.LOGGER.fine("Failed to compute colors for: " + item)
Reference.logger.fine("Failed to compute colors for: " + item)
}
}
return 0xFFFFFF
@ -287,17 +270,12 @@ object ResourceGenerator
def getMixture(name: String): BlockFluidFinite =
{
return ResonantInduction.blockMixtureFluids.get(getID(name))
return Block.blockRegistry.getObject("mixture" + name).asInstanceOf[BlockFluidFinite]
}
def getMolten(name: String): BlockFluidFinite =
{
return ResonantInduction.blockMoltenFluid.get(getID(name))
}
def getName(id: Int): String =
{
return materials.inverse.get(id)
return Block.blockRegistry.getObject("molten" + LanguageUtility.capitalizeFirst(name)).asInstanceOf[BlockFluidFinite]
}
def getName(itemStack: ItemStack): String =
@ -314,7 +292,8 @@ object ResourceGenerator
return 0xFFFFFF
}
@Deprecated def getMaterials: List[String] =
@Deprecated
def getMaterials: List[String] =
{
val returnMaterials: List[String] = new ArrayList[String]
{
@ -324,7 +303,7 @@ object ResourceGenerator
{
returnMaterials.add(getName(i))
}
({i += 1; i - 1 })
i += 1
}
}
return returnMaterials

View file

@ -17,15 +17,12 @@ import cpw.mods.fml.relauncher.SideOnly;
* Fluid class uses for molten materials.
*
* @author Calclavia
*
*/
public class BlockFluidMaterial extends BlockFluidFinite
{
public BlockFluidMaterial(Fluid fluid)
{
super(Settings.getNextBlockID(fluid.getName()), fluid, Material.lava);
setTextureName(Reference.PREFIX + "molten_flow");
setUnlocalizedName(Reference.PREFIX + "fluidMaterial");
super(fluid, Material.lava);
}
public void setQuanta(World world, int x, int y, int z, int quanta)