Converted turbines, and some render code to scala

This commit is contained in:
Robert S 2014-09-29 16:36:56 -04:00
parent 0e0a08629a
commit 909b8910e7
30 changed files with 1426 additions and 1636 deletions

View file

@ -1,76 +0,0 @@
package resonantinduction.electrical.transformer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.IItemRenderer;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.obj.WavefrontObject;
import org.lwjgl.opengl.GL11;
import resonant.content.prefab.scala.render.ISimpleItemRenderer;
import resonant.lib.render.RenderUtility;
import resonantinduction.core.Reference;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderTransformer implements ISimpleItemRenderer
{
public static final RenderTransformer INSTANCE = new RenderTransformer();
public static final WavefrontObject MODEL = (WavefrontObject) AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "transformer.obj"));
public static final ResourceLocation TEXTURE_COIL = new ResourceLocation(Reference.domain(), Reference.modelPath() + "transformer_winding.png");
public static final ResourceLocation TEXTURE_STONE = new ResourceLocation(Reference.blockTextureDirectory() + "stone.png");
public static final ResourceLocation TEXTURE_IRON = new ResourceLocation(Reference.blockTextureDirectory() + "iron_block.png");
@Override
public void renderInventoryItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data)
{
GL11.glTranslated(0, -0.2f, 0);
doRender();
}
public void doRender()
{
GL11.glScalef(0.5f, 0.5f, 0.5f);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_COIL);
MODEL.renderAllExcept("core", "base");
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_IRON);
MODEL.renderOnly("core");
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_STONE);
MODEL.renderOnly("base");
}
public void render(PartElectricTransformer part, double x, double y, double z)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 0.5F, (float) z + 0.5F);
RenderUtility.rotateFaceBlockToSide(part.placementSide);
RenderUtility.rotateBlockBasedOnDirection(part.getFacing());
GL11.glRotatef(90, 0, 1, 0);
GL11.glScalef(0.5f, 0.5f, 0.5f);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_COIL);
switch (part.multiplier())
{
case 0:
MODEL.renderOnly("InsulatorLayerLow", "OuterWindingLowBox", "InnerWindingLowBox");
break;
case 1:
MODEL.renderOnly("InsulatorLayerMed", "OuterWindingMedBox", "InnerWindingMedBox");
break;
case 2:
MODEL.renderOnly("InnerWindingHighBox", "InsulatorLayerHigh", "OuterWindingHighBox");
break;
}
MODEL.renderOnly("OuterWindingConnector", "InnerWindingConnector");
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_IRON);
MODEL.renderOnly("core");
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE_STONE);
MODEL.renderOnly("base");
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,72 @@
package resonantinduction.electrical.transformer
import cpw.mods.fml.client.FMLClientHandler
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
import net.minecraft.item.ItemStack
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.IItemRenderer
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.obj.WavefrontObject
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference
@SideOnly(Side.CLIENT) object RenderTransformer
{
final val INSTANCE: RenderTransformer = new RenderTransformer
final val MODEL: WavefrontObject = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "transformer.obj")).asInstanceOf[WavefrontObject]
final val TEXTURE_COIL: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "transformer_winding.png")
final val TEXTURE_STONE: ResourceLocation = new ResourceLocation(Reference.blockTextureDirectory + "stone.png")
final val TEXTURE_IRON: ResourceLocation = new ResourceLocation(Reference.blockTextureDirectory + "iron_block.png")
}
@SideOnly(Side.CLIENT) class RenderTransformer extends ISimpleItemRenderer
{
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
{
GL11.glTranslated(0, -0.2f, 0)
doRender
}
def doRender
{
GL11.glScalef(0.5f, 0.5f, 0.5f)
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_COIL)
RenderTransformer.MODEL.renderAllExcept("core", "base")
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_IRON)
RenderTransformer.MODEL.renderOnly("core")
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_STONE)
RenderTransformer.MODEL.renderOnly("base")
}
def render(part: PartElectricTransformer, x: Double, y: Double, z: Double)
{
GL11.glPushMatrix
GL11.glTranslatef(x.asInstanceOf[Float] + 0.5F, y.asInstanceOf[Float] + 0.5F, z.asInstanceOf[Float] + 0.5F)
RenderUtility.rotateFaceBlockToSide(part.placementSide)
RenderUtility.rotateBlockBasedOnDirection(part.getFacing)
GL11.glRotatef(90, 0, 1, 0)
GL11.glScalef(0.5f, 0.5f, 0.5f)
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_COIL)
if (part.multiplier == 0)
{
RenderTransformer.MODEL.renderOnly("InsulatorLayerLow", "OuterWindingLowBox", "InnerWindingLowBox")
}
else if (part.multiplier == 1)
{
RenderTransformer.MODEL.renderOnly("InsulatorLayerMed", "OuterWindingMedBox", "InnerWindingMedBox")
}
else if (part.multiplier == 2)
{
RenderTransformer.MODEL.renderOnly("InnerWindingHighBox", "InsulatorLayerHigh", "OuterWindingHighBox")
}
RenderTransformer.MODEL.renderOnly("OuterWindingConnector", "InnerWindingConnector")
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_IRON)
RenderTransformer.MODEL.renderOnly("core")
FMLClientHandler.instance.getClient.renderEngine.bindTexture(RenderTransformer.TEXTURE_STONE)
RenderTransformer.MODEL.renderOnly("base")
GL11.glPopMatrix
}
}

View file

@ -1,56 +0,0 @@
package resonantinduction.mechanical.fluid.transport;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import org.lwjgl.opengl.GL11;
import resonant.lib.render.RenderUtility;
import resonantinduction.core.Reference;
public class RenderPump extends TileEntitySpecialRenderer
{
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "pump.tcn"));
public static final ResourceLocation TEXTURE = new ResourceLocation(Reference.domain(), Reference.modelPath() + "pump.png");
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
{
TilePump tile = (TilePump) tileEntity;
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
GL11.glRotatef(-90, 0, 1, 0);
if (tile.getWorldObj() != null)
RenderUtility.rotateBlockBasedOnDirection(tile.getDirection());
bindTexture(TEXTURE);
List<String> notRendered = new ArrayList<String>();
GL11.glPushMatrix();
GL11.glRotated(Math.toDegrees((float) tile.mechanicalNode.renderAngle), 0, 0, 1);
for (int i = 1; i <= 12; i++)
{
String fin = "fin" + i;
String innerFin = "innerFin" + i;
notRendered.add(fin);
notRendered.add(innerFin);
MODEL.renderOnly(fin, innerFin);
}
GL11.glPopMatrix();
MODEL.renderAllExcept(notRendered.toArray(new String[0]));
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,46 @@
package resonantinduction.mechanical.fluid.transport
import java.util.{ArrayList, List}
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import org.lwjgl.opengl.GL11
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference
object RenderPump
{
final val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "pump.tcn"))
final val TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "pump.png")
}
class RenderPump extends TileEntitySpecialRenderer
{
def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float)
{
val tile: TilePump = tileEntity.asInstanceOf[TilePump]
GL11.glPushMatrix
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
GL11.glRotatef(-90, 0, 1, 0)
if (tile.getWorldObj != null) RenderUtility.rotateBlockBasedOnDirection(tile.getDirection)
bindTexture(RenderPump.TEXTURE)
val notRendered: List[String] = new ArrayList[String]
GL11.glPushMatrix
GL11.glRotated(Math.toDegrees(tile.mechanicalNode.renderAngle.asInstanceOf[Float]), 0, 0, 1)
for (i <- 1 to 12)
{
val fin: String = "fin" + i
val innerFin: String = "innerFin" + i
notRendered.add(fin)
notRendered.add(innerFin)
RenderPump.MODEL.renderOnly(fin, innerFin)
}
GL11.glPopMatrix
RenderPump.MODEL.renderAllExcept(notRendered.toArray(new Array[String](0)): _*)
GL11.glPopMatrix
}
}

View file

@ -22,6 +22,7 @@ import universalelectricity.api.core.grid.INodeProvider;
*
* @author Darkguardsman */
@SuppressWarnings("serial")
//Don't convert to scala as this will find its way into RE later - From Darkguardsman
public class DebugFrameMechanical extends FrameNodeDebug
{
JList<String> connectionList_component = null;

View file

@ -19,6 +19,7 @@ import universalelectricity.core.transform.vector.IVectorWorld;
*
* @author Calclavia, Darkguardsman
*/
//Don't convert to scala as this will find its way into RE later - From Darkguardsman
public class MechanicalNode extends NodeConnector implements TMultipartNode, IMechanicalNode, ISaveObj, IVectorWorld, IUpdate
{
/** Marks that the rotation has changed and should be updated client side */

View file

@ -1,248 +0,0 @@
package resonantinduction.mechanical.mech;
import java.util.ArrayList;
import java.util.List;
import codechicken.multipart.*;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.MovingObjectPosition;
import net.minecraftforge.common.util.ForgeDirection;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.data.MCDataOutput;
import resonant.engine.ResonantEngine;
import universalelectricity.api.core.grid.INode;
import universalelectricity.api.core.grid.INodeProvider;
import universalelectricity.core.transform.vector.VectorWorld;
/** We assume all the force acting on the gear is 90 degrees.
*
* @author Calclavia */
public abstract class PartMechanical extends JCuboidPart implements JNormalOcclusion, TFacePart, INodeProvider
{
/** Node that handles resonantinduction.mechanical action of the machine */
public MechanicalNode node;
protected double prevAngularVelocity;
int ticks = 0;
/** Packets */
boolean markPacketUpdate = false;
/** Simple debug external GUI */
DebugFrameMechanical frame = null;
/** Side of the block this is placed on */
public ForgeDirection placementSide = ForgeDirection.UNKNOWN;
public int tier;
public void preparePlacement(int side, int itemDamage)
{
this.placementSide = ForgeDirection.getOrientation((byte) (side));
this.tier = itemDamage;
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
node.reconstruct();
}
@Override
public void onPartChanged(TMultiPart part)
{
super.onPartChanged(part);
if(part instanceof INodeProvider)
{
node.reconstruct();
}
}
@Override
public void update()
{
ticks++;
if (ticks >= Long.MAX_VALUE)
{
ticks = 0;
}
//Make sure to update on both sides
this.node.update();
if (!world().isRemote)
{
checkClientUpdate();
}
if (frame != null)
{
frame.update();
}
super.update();
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack itemStack)
{
if (ResonantEngine.runningAsDev)
{
if (itemStack != null && !world().isRemote)
{
if (itemStack.getItem() == Items.stick)
{
//Set the nodes debug mode
if (ControlKeyModifer.isControlDown(player))
{
//Opens a debug GUI
if (frame == null)
{
frame = new DebugFrameMechanical(this);
frame.showDebugFrame();
} //Closes the debug GUI
else
{
frame.closeDebugFrame();
frame = null;
}
}
}
}
}
return super.activate(player, hit, itemStack);
}
public void checkClientUpdate()
{
if (Math.abs(prevAngularVelocity - node.angularVelocity) >= 0.1)
{
prevAngularVelocity = node.angularVelocity;
sendRotationPacket();
}
}
@Override
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
{
if (nodeType.isAssignableFrom(node.getClass()))
{
return node;
}
return null;
}
@Override
public void onWorldJoin()
{
node.reconstruct();
}
@Override
public void onWorldSeparate()
{
node.deconstruct();
if (frame != null)
{
frame.closeDebugFrame();
}
}
/** Packet Code. */
public void sendRotationPacket()
{
if (world() != null && !world().isRemote)
{
getWriteStream().writeByte(1).writeDouble(node.angularVelocity);
}
}
/** Packet Code. */
@Override
public void read(MCDataInput packet)
{
read(packet, packet.readUByte());
}
public void read(MCDataInput packet, int packetID)
{
switch (packetID)
{
case 0:
load(packet.readNBTTagCompound());
break;
case 1:
node.angularVelocity = packet.readDouble();
break;
}
}
@Override
public void readDesc(MCDataInput packet)
{
packet.readByte();
load(packet.readNBTTagCompound());
}
@Override
public void writeDesc(MCDataOutput packet)
{
packet.writeByte(0);
NBTTagCompound nbt = new NBTTagCompound();
save(nbt);
packet.writeNBTTagCompound(nbt);
}
@Override
public int redstoneConductionMap()
{
return 0;
}
@Override
public boolean solid(int arg0)
{
return true;
}
@Override
public void load(NBTTagCompound nbt)
{
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"));
tier = nbt.getByte("tier");
node.load(nbt);
}
@Override
public void save(NBTTagCompound nbt)
{
nbt.setByte("side", (byte) placementSide.ordinal());
nbt.setByte("tier", (byte) tier);
node.save(nbt);
}
protected abstract ItemStack getItem();
@Override
public Iterable<ItemStack> getDrops()
{
List<ItemStack> drops = new ArrayList<ItemStack>();
drops.add(getItem());
return drops;
}
@Override
public ItemStack pickItem(MovingObjectPosition hit)
{
return getItem();
}
public VectorWorld getPosition()
{
return new VectorWorld(world(), x(), y(), z());
}
@Override
public String toString()
{
return "[" + getClass().getSimpleName() +"]" + x() + "x " + y() + "y " + z() + "z " + getSlotMask() + "s ";
}
}

View file

@ -0,0 +1,221 @@
package resonantinduction.mechanical.mech
import java.util.{ArrayList, List}
import codechicken.lib.data.{MCDataInput, MCDataOutput}
import codechicken.multipart._
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.MovingObjectPosition
import net.minecraftforge.common.util.ForgeDirection
import resonant.engine.ResonantEngine
import universalelectricity.api.core.grid.{INode, INodeProvider}
import universalelectricity.core.transform.vector.VectorWorld
/** We assume all the force acting on the gear is 90 degrees.
*
* @author Calclavia */
abstract class PartMechanical extends JCuboidPart with JNormalOcclusion with TFacePart with INodeProvider
{
/** Node that handles resonantinduction.mechanical action of the machine */
var node: MechanicalNode = null
protected var prevAngularVelocity: Double = .0
private[mech] var ticks: Int = 0
/** Packets */
private[mech] var markPacketUpdate: Boolean = false
/** Simple debug external GUI */
private[mech] var frame: DebugFrameMechanical = null
/** Side of the block this is placed on */
var placementSide: ForgeDirection = ForgeDirection.UNKNOWN
var tier: Int = 0
def preparePlacement(side: Int, itemDamage: Int)
{
this.placementSide = ForgeDirection.getOrientation((side).asInstanceOf[Byte])
this.tier = itemDamage
}
override def onNeighborChanged
{
super.onNeighborChanged
node.reconstruct
}
override def onPartChanged(part: TMultiPart)
{
super.onPartChanged(part)
if (part.isInstanceOf[INodeProvider])
{
node.reconstruct
}
}
override def update
{
ticks += 1
if (ticks >= java.lang.Long.MAX_VALUE)
{
ticks = 0
}
this.node.update
if (!world.isRemote)
{
checkClientUpdate
}
if (frame != null)
{
frame.update
}
super.update
}
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
{
if (ResonantEngine.runningAsDev)
{
if (itemStack != null && !world.isRemote)
{
if (itemStack.getItem eq Items.stick)
{
if (ControlKeyModifer.isControlDown(player))
{
if (frame == null)
{
frame = new DebugFrameMechanical(this)
frame.showDebugFrame
}
else
{
frame.closeDebugFrame
frame = null
}
}
}
}
}
return super.activate(player, hit, itemStack)
}
def checkClientUpdate
{
if (Math.abs(prevAngularVelocity - node.angularVelocity) >= 0.1)
{
prevAngularVelocity = node.angularVelocity
sendRotationPacket
}
}
def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
if (nodeType.isAssignableFrom(node.getClass))
{
return node
}
return null
}
override def onWorldJoin
{
node.reconstruct
}
override def onWorldSeparate
{
node.deconstruct
if (frame != null)
{
frame.closeDebugFrame
}
}
/** Packet Code. */
def sendRotationPacket
{
if (world != null && !world.isRemote)
{
getWriteStream.writeByte(1).writeDouble(node.angularVelocity)
}
}
/** Packet Code. */
override def read(packet: MCDataInput)
{
read(packet, packet.readUByte)
}
def read(packet: MCDataInput, packetID: Int)
{
if (packetID == 0)
{
load(packet.readNBTTagCompound)
}
else if (packetID == 1)
{
node.angularVelocity = packet.readDouble
}
}
override def readDesc(packet: MCDataInput)
{
packet.readByte
load(packet.readNBTTagCompound)
}
override def writeDesc(packet: MCDataOutput)
{
packet.writeByte(0)
val nbt: NBTTagCompound = new NBTTagCompound
save(nbt)
packet.writeNBTTagCompound(nbt)
}
override def redstoneConductionMap: Int =
{
return 0
}
override def solid(arg0: Int): Boolean =
{
return true
}
override def load(nbt: NBTTagCompound)
{
placementSide = ForgeDirection.getOrientation(nbt.getByte("side"))
tier = nbt.getByte("tier")
node.load(nbt)
}
override def save(nbt: NBTTagCompound)
{
nbt.setByte("side", placementSide.ordinal.asInstanceOf[Byte])
nbt.setByte("tier", tier.asInstanceOf[Byte])
node.save(nbt)
}
protected def getItem: ItemStack
override def getDrops: java.lang.Iterable[ItemStack] =
{
val drops: List[ItemStack] = new ArrayList[ItemStack]
drops.add(getItem)
return drops
}
override def pickItem(hit: MovingObjectPosition): ItemStack =
{
return getItem
}
def getPosition: VectorWorld =
{
return new VectorWorld(world, x, y, z)
}
override def toString: String =
{
return "[" + getClass.getSimpleName + "]" + x + "x " + y + "y " + z + "z " + getSlotMask + "s "
}
}

View file

@ -1,153 +0,0 @@
package resonantinduction.mechanical.mech;
import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.Packet;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.content.prefab.java.TileNode;
import resonant.engine.ResonantEngine;
import resonant.lib.network.discriminator.PacketTile;
import resonant.lib.network.discriminator.PacketType;
import resonant.lib.network.handle.IPacketIDReceiver;
import universalelectricity.api.core.grid.INode;
import universalelectricity.api.core.grid.INodeProvider;
import universalelectricity.core.transform.vector.Vector3;
import codechicken.multipart.ControlKeyModifer;
/** Prefab for resonantinduction.mechanical tiles
*
* @author Calclavia */
public abstract class TileMechanical extends TileNode implements INodeProvider, IPacketIDReceiver
{
protected static final int PACKET_NBT = 0;
protected static final int PACKET_VELOCITY = 1;
/** Node that handles most mechanical actions */
public MechanicalNode mechanicalNode;
/** External debug GUI */
DebugFrameMechanical frame = null;
public TileMechanical(Material material)
{
super(material);
this.mechanicalNode = new MechanicalNode(this);
}
@Override
public void update()
{
super.update();
if(frame != null)
{
frame.update();
if(!frame.isVisible())
{
frame.dispose();
frame = null;
}
}
if (!this.getWorldObj().isRemote)
{
if (ticks() % 3 == 0 && (mechanicalNode.markTorqueUpdate || mechanicalNode.markRotationUpdate))
{
//ResonantInduction.LOGGER.info("[mechanicalNode] Sending Update");
sendRotationPacket();
mechanicalNode.markRotationUpdate = false;
mechanicalNode.markTorqueUpdate = false;
}
}
}
@Override
public boolean use(EntityPlayer player, int side, Vector3 hit)
{
ItemStack itemStack = player.getHeldItem();
if (ResonantEngine.runningAsDev)
{
if (itemStack != null && !world().isRemote)
{
if (itemStack.getItem() == Items.stick)
{
//Set the nodes debug mode
if (ControlKeyModifer.isControlDown(player))
{
//Opens a debug GUI
if (frame == null)
{
frame = new DebugFrameMechanical(this);
frame.showDebugFrame();
} //Closes the debug GUI
else
{
frame.closeDebugFrame();
frame = null;
}
}
}
}
}
return false;
}
@Override
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
{
return mechanicalNode;
}
@Override
public Packet getDescriptionPacket()
{
NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag);
return ResonantEngine.instance.packetHandler.toMCPacket(new PacketTile(this, PACKET_NBT, tag));
}
/** Sends the torque and angular velocity to the client */
private void sendRotationPacket()
{
ResonantEngine.instance.packetHandler.sendToAllAround(new PacketTile(this, PACKET_VELOCITY, mechanicalNode.angularVelocity, mechanicalNode.torque), this);
}
@Override
public boolean read(ByteBuf data, int id, EntityPlayer player, PacketType type)
{
if (world().isRemote)
{
if (id == PACKET_NBT)
{
readFromNBT(ByteBufUtils.readTag(data));
return true;
}
else if (id == PACKET_VELOCITY)
{
mechanicalNode.angularVelocity = data.readDouble();
mechanicalNode.torque = data.readDouble();
return true;
}
}
return false;
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
mechanicalNode.load(nbt);
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
mechanicalNode.save(nbt);
}
}

View file

@ -0,0 +1,137 @@
package resonantinduction.mechanical.mech
import codechicken.multipart.ControlKeyModifer
import cpw.mods.fml.common.network.ByteBufUtils
import io.netty.buffer.ByteBuf
import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.Items
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.network.Packet
import net.minecraftforge.common.util.ForgeDirection
import resonant.content.prefab.java.TileNode
import resonant.engine.ResonantEngine
import resonant.lib.network.discriminator.{PacketTile, PacketType}
import resonant.lib.network.handle.IPacketIDReceiver
import universalelectricity.api.core.grid.{INode, INodeProvider}
import universalelectricity.core.transform.vector.Vector3
/** Prefab for resonantinduction.mechanical tiles
*
* @author Calclavia */
object TileMechanical
{
protected final val PACKET_NBT: Int = 0
protected final val PACKET_VELOCITY: Int = 1
}
abstract class TileMechanical(material: Material) extends TileNode(material) with INodeProvider with IPacketIDReceiver
{
/** Node that handles most mechanical actions */
var mechanicalNode: MechanicalNode = null
/** External debug GUI */
private[mech] var frame: DebugFrameMechanical = null
this.mechanicalNode = new MechanicalNode(this)
override def update
{
super.update
if (frame != null)
{
frame.update
if (!frame.isVisible)
{
frame.dispose
frame = null
}
}
if (!this.getWorldObj.isRemote)
{
if (ticks % 3 == 0 && (mechanicalNode.markTorqueUpdate || mechanicalNode.markRotationUpdate))
{
sendRotationPacket
mechanicalNode.markRotationUpdate = false
mechanicalNode.markTorqueUpdate = false
}
}
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
val itemStack: ItemStack = player.getHeldItem
if (ResonantEngine.runningAsDev)
{
if (itemStack != null && !world.isRemote)
{
if (itemStack.getItem eq Items.stick)
{
if (ControlKeyModifer.isControlDown(player))
{
if (frame == null)
{
frame = new DebugFrameMechanical(this)
frame.showDebugFrame
}
else
{
frame.closeDebugFrame
frame = null
}
}
}
}
}
return false
}
override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
return mechanicalNode
}
override def getDescriptionPacket: Packet =
{
val tag: NBTTagCompound = new NBTTagCompound
writeToNBT(tag)
return ResonantEngine.instance.packetHandler.toMCPacket(new PacketTile(x, y, z, Array(TileMechanical.PACKET_NBT, tag)))
}
/** Sends the torque and angular velocity to the client */
private def sendRotationPacket
{
ResonantEngine.instance.packetHandler.sendToAllAround(new PacketTile(x, y , z, Array(TileMechanical.PACKET_VELOCITY, mechanicalNode.angularVelocity, mechanicalNode.torque)), this)
}
override def read(data: ByteBuf, id: Int, player: EntityPlayer, `type`: PacketType): Boolean =
{
if (world.isRemote)
{
if (id == TileMechanical.PACKET_NBT)
{
readFromNBT(ByteBufUtils.readTag(data))
return true
}
else if (id == TileMechanical.PACKET_VELOCITY)
{
mechanicalNode.angularVelocity = data.readDouble
mechanicalNode.torque = data.readDouble
return true
}
}
return false
}
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
mechanicalNode.load(nbt)
}
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
mechanicalNode.save(nbt)
}
}

View file

@ -1,79 +0,0 @@
package resonantinduction.mechanical.mech.process.crusher;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.common.util.ForgeDirection;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.opengl.GL11;
import resonant.lib.render.RenderUtility;
import resonantinduction.core.Reference;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderMechanicalPiston extends TileEntitySpecialRenderer
{
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "piston/mechanicalPiston.tcn"));
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.domain(), Reference.modelPath() + "piston/mechanicalPiston_iron.png");
final String[] staticParts = { "baseRing", "leg1", "leg2", "leg3", "leg4", "connector", "basePlate", "basePlateTop", "connectorBar", "centerPiston" };
final String[] shaftParts = { "topPlate", "outerPiston" };
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
TileMechanicalPiston tile = (TileMechanicalPiston) tileEntity;
GL11.glRotated(-90, 0, 1, 0);
GL11.glRotated(180, 0, 0, 1);
if (tile.getWorldObj() != null)
{
if (tile.getDirection() == ForgeDirection.NORTH || tile.getDirection() == ForgeDirection.SOUTH)
RenderUtility.rotateBlockBasedOnDirection(tile.getDirection().getOpposite());
else
RenderUtility.rotateBlockBasedOnDirection(tile.getDirection());
}
RenderUtility.bind(TEXTURE);
// Angle in radians of the rotor.
double angle = tile.mechanicalNode.renderAngle;
/** Render Piston Rotor */
GL11.glPushMatrix();
GL11.glRotated(-Math.toDegrees(angle), 0, 0, 1);
MODEL.renderAllExcept(ArrayUtils.addAll(shaftParts, staticParts));
GL11.glPopMatrix();
/** Render Piston Shaft */
GL11.glPushMatrix();
if (tile.getWorldObj() != null)
{
ForgeDirection dir = tile.getDirection();
if (tile.world().isAirBlock(tile.x() + dir.offsetX, tile.y() + dir.offsetY, tile.z() + dir.offsetZ))
{
GL11.glTranslated(0, 0, (0.4 * Math.sin(angle)) - 0.5);
}
else
{
GL11.glTranslated(0, 0, (0.06 * Math.sin(angle)) - 0.03);
}
}
MODEL.renderOnly(shaftParts);
GL11.glPopMatrix();
MODEL.renderOnly(staticParts);
GL11.glPopMatrix();
}
}

View file

@ -0,0 +1,63 @@
package resonantinduction.mechanical.mech.process.crusher
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.model.AdvancedModelLoader
import net.minecraftforge.client.model.IModelCustom
import net.minecraftforge.common.util.ForgeDirection
import org.apache.commons.lang3.ArrayUtils
import org.lwjgl.opengl.GL11
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.SideOnly
@SideOnly(Side.CLIENT) object RenderMechanicalPiston
{
final val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "piston/mechanicalPiston.tcn"))
var TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "piston/mechanicalPiston_iron.png")
}
@SideOnly(Side.CLIENT) class RenderMechanicalPiston extends TileEntitySpecialRenderer
{
private[crusher] final val staticParts: Array[String] = Array("baseRing", "leg1", "leg2", "leg3", "leg4", "connector", "basePlate", "basePlateTop", "connectorBar", "centerPiston")
private[crusher] final val shaftParts: Array[String] = Array("topPlate", "outerPiston")
def renderTileEntityAt(tileEntity: TileEntity, x: Double, y: Double, z: Double, f: Float)
{
GL11.glPushMatrix
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
val tile: TileMechanicalPiston = tileEntity.asInstanceOf[TileMechanicalPiston]
GL11.glRotated(-90, 0, 1, 0)
GL11.glRotated(180, 0, 0, 1)
if (tile.getWorldObj != null)
{
if (tile.getDirection == ForgeDirection.NORTH || tile.getDirection == ForgeDirection.SOUTH) RenderUtility.rotateBlockBasedOnDirection(tile.getDirection.getOpposite)
else RenderUtility.rotateBlockBasedOnDirection(tile.getDirection)
}
RenderUtility.bind(RenderMechanicalPiston.TEXTURE)
val angle: Double = tile.mechanicalNode.renderAngle
GL11.glPushMatrix
GL11.glRotated(-Math.toDegrees(angle), 0, 0, 1)
RenderMechanicalPiston.MODEL.renderAllExcept(ArrayUtils.addAll(shaftParts, staticParts: _*): _*)
GL11.glPopMatrix
GL11.glPushMatrix
if (tile.getWorldObj != null)
{
val dir: ForgeDirection = tile.getDirection
if (tile.world.isAirBlock(tile.x + dir.offsetX, tile.y + dir.offsetY, tile.z + dir.offsetZ))
{
GL11.glTranslated(0, 0, (0.4 * Math.sin(angle)) - 0.5)
}
else
{
GL11.glTranslated(0, 0, (0.06 * Math.sin(angle)) - 0.03)
}
}
RenderMechanicalPiston.MODEL.renderOnly(shaftParts: _*)
GL11.glPopMatrix
RenderMechanicalPiston.MODEL.renderOnly(staticParts: _*)
GL11.glPopMatrix
}
}

View file

@ -1,61 +0,0 @@
package resonantinduction.mechanical.mech.process.mixer;
import static org.lwjgl.opengl.GL11.glPopMatrix;
import static org.lwjgl.opengl.GL11.glPushMatrix;
import static org.lwjgl.opengl.GL11.glRotatef;
import static org.lwjgl.opengl.GL11.glTranslatef;
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 org.lwjgl.opengl.GL11;
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)
public class RenderMixer extends TileEntitySpecialRenderer implements ISimpleItemRenderer
{
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(),Reference.modelPath() + "mixer.tcn"));
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.domain(), Reference.modelPath() + "mixer.png");
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
if (t instanceof TileMixer)
{
TileMixer tile = (TileMixer) t;
glPushMatrix();
glTranslatef((float) x + 0.5F, (float) y + 0.5f, (float) z + 0.5F);
RenderUtility.bind(TEXTURE);
MODEL.renderOnly("centerTop", "centerBase");
glPushMatrix();
glRotatef((float) Math.toDegrees((float) tile.mechanicalNode.renderAngle), 0, 1, 0);
MODEL.renderAllExcept("centerTop", "centerBase");
glPopMatrix();
glPopMatrix();
}
}
@Override
public void renderInventoryItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data)
{
glPushMatrix();
GL11.glScalef(0.5f, 0.5f, 0.5f);
glTranslatef(0.5F, 0.5f, 0.5f);
RenderUtility.bind(TEXTURE);
MODEL.renderAll();
glPopMatrix();
}
}

View file

@ -0,0 +1,59 @@
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 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 org.lwjgl.opengl.GL11
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
{
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")
}
@SideOnly(Side.CLIENT) class RenderMixer extends TileEntitySpecialRenderer with ISimpleItemRenderer
{
def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float)
{
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
}
}
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
}
}

View file

@ -1,107 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom;
import org.apache.commons.lang3.ArrayUtils;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderElectricTurbine extends TileEntitySpecialRenderer
{
public static final IModelCustom MODEL_SMALL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(),Reference.modelPath() + "turbineSmall.tcn"));
public static final IModelCustom MODEL_LARGE = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(),Reference.modelPath() + "turbineLarge.tcn"));
public static final ResourceLocation SMALL_TEXTURE = new ResourceLocation(Reference.domain(), Reference.modelPath() + "turbineSmall.png");
public static final ResourceLocation LARGE_TEXTURE = new ResourceLocation(Reference.domain(), Reference.modelPath() + "turbineLarge.png");
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
TileTurbine tile = (TileTurbine) t;
if (tile.getMultiBlock().isPrimary())
{
// Texture file
GL11.glPushMatrix();
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5);
if (tile.getMultiBlock().isConstructed())
{
bindTexture(LARGE_TEXTURE);
final String[] blades = new String[]
{ "Blade1", "Blade2", "Blade3", "Blade4", "Blade5", "Blade6" };
final String[] mediumBlades = new String[]
{ "MediumBlade1", "MediumBlade2", "MediumBlade3", "MediumBlade4", "MediumBlade5", "MediumBlade6" };
final String[] largeBlades = new String[]
{ "LargeBlade1", "LargeBlade2", "LargeBlade3", "LargeBlade4", "LargeBlade5", "LargeBlade6" };
GL11.glPushMatrix();
GL11.glRotated(Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0);
MODEL_LARGE.renderOnly(blades);
MODEL_LARGE.renderOnly(largeBlades);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glRotated(-Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0);
MODEL_LARGE.renderOnly(mediumBlades);
GL11.glPopMatrix();
MODEL_LARGE.renderAllExcept(ArrayUtils.addAll(ArrayUtils.addAll(blades, mediumBlades), largeBlades));
}
else
{
GL11.glScalef(1f, 1.1f, 1f);
bindTexture(SMALL_TEXTURE);
final String[] bladesA = new String[3];
for (int i = 0; i < bladesA.length; i++)
{
bladesA[i] = "BLADE A" + (i + 1) + " SPINS";
}
final String[] sheildsA = new String[6];
for (int i = 0; i < sheildsA.length; i++)
{
sheildsA[i] = "SHIELD A" + (i + 1) + " SPINS";
}
final String[] bladesB = new String[3];
for (int i = 0; i < bladesB.length; i++)
{
bladesB[i] = "BLADE B" + (i + 1) + " SPINS";
}
final String[] sheildsB = new String[6];
for (int i = 0; i < sheildsB.length; i++)
{
sheildsB[i] = "SHIELD B" + (i + 1) + " SPINS";
}
final String[] renderA = ArrayUtils.addAll(bladesA, sheildsA);
final String[] renderB = ArrayUtils.addAll(bladesB, sheildsB);
GL11.glPushMatrix();
GL11.glRotated(Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0);
MODEL_SMALL.renderOnly(renderA);
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glRotated(-Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0);
MODEL_SMALL.renderOnly(renderB);
GL11.glPopMatrix();
MODEL_SMALL.renderAllExcept(ArrayUtils.addAll(renderA, renderB));
}
GL11.glPopMatrix();
}
}
}

View file

@ -0,0 +1,93 @@
package resonantinduction.mechanical.mech.turbine
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.ResourceLocation
import net.minecraftforge.client.model.{AdvancedModelLoader, IModelCustom}
import org.apache.commons.lang3.ArrayUtils
import org.lwjgl.opengl.GL11
import resonantinduction.core.Reference
@SideOnly(Side.CLIENT) object RenderElectricTurbine
{
final val MODEL_SMALL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "turbineSmall.tcn"))
final val MODEL_LARGE: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "turbineLarge.tcn"))
final val SMALL_TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "turbineSmall.png")
final val LARGE_TEXTURE: ResourceLocation = new ResourceLocation(Reference.domain, Reference.modelPath + "turbineLarge.png")
}
@SideOnly(Side.CLIENT) class RenderElectricTurbine extends TileEntitySpecialRenderer
{
def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float)
{
val tile: TileTurbine = t.asInstanceOf[TileTurbine]
if (tile.getMultiBlock.isPrimary)
{
GL11.glPushMatrix
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
if (tile.getMultiBlock.isConstructed)
{
bindTexture(RenderElectricTurbine.LARGE_TEXTURE)
val blades: Array[String] = Array[String]("Blade1", "Blade2", "Blade3", "Blade4", "Blade5", "Blade6")
val mediumBlades: Array[String] = Array[String]("MediumBlade1", "MediumBlade2", "MediumBlade3", "MediumBlade4", "MediumBlade5", "MediumBlade6")
val largeBlades: Array[String] = Array[String]("LargeBlade1", "LargeBlade2", "LargeBlade3", "LargeBlade4", "LargeBlade5", "LargeBlade6")
GL11.glPushMatrix
GL11.glRotated(Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0)
RenderElectricTurbine.MODEL_LARGE.renderOnly(blades: _*)
RenderElectricTurbine.MODEL_LARGE.renderOnly(largeBlades: _*)
GL11.glPopMatrix
GL11.glPushMatrix
GL11.glRotated(-Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0)
RenderElectricTurbine.MODEL_LARGE.renderOnly(mediumBlades: _*)
GL11.glPopMatrix
RenderElectricTurbine.MODEL_LARGE.renderAllExcept(ArrayUtils.addAll(ArrayUtils.addAll(blades, mediumBlades: _*), largeBlades: _*): _*)
}
else
{
GL11.glScalef(1f, 1.1f, 1f)
bindTexture(RenderElectricTurbine.SMALL_TEXTURE)
val bladesA: Array[String] = new Array[String](3)
for (i <- 0 to bladesA.length)
{
bladesA(i) = "BLADE A" + (i + 1) + " SPINS"
}
val sheildsA: Array[String] = new Array[String](6)
for (i <- 0 to sheildsA.length)
{
sheildsA(i) = "SHIELD A" + (i + 1) + " SPINS"
}
val bladesB: Array[String] = new Array[String](3)
for (i <- 0 to bladesB.length)
{
bladesB(i) = "BLADE B" + (i + 1) + " SPINS"
}
val sheildsB: Array[String] = new Array[String](6)
for (i <- 0 to sheildsB.length)
{
sheildsB(i) = "SHIELD B" + (i + 1) + " SPINS"
}
val renderA: Array[String] = ArrayUtils.addAll(bladesA, sheildsA: _*)
val renderB: Array[String] = ArrayUtils.addAll(bladesB, sheildsB: _*)
GL11.glPushMatrix
GL11.glRotated(Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0)
RenderElectricTurbine.MODEL_SMALL.renderOnly(renderA: _*)
GL11.glPopMatrix
GL11.glPushMatrix
GL11.glRotated(-Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0)
RenderElectricTurbine.MODEL_SMALL.renderOnly(renderB: _*)
GL11.glPopMatrix
RenderElectricTurbine.MODEL_SMALL.renderAllExcept(ArrayUtils.addAll(renderA, renderB: _*): _*)
}
GL11.glPopMatrix
}
}
}

View file

@ -1,148 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
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 org.lwjgl.opengl.GL11;
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;
@SideOnly(Side.CLIENT)
public class RenderWaterTurbine extends TileEntitySpecialRenderer implements ISimpleItemRenderer
{
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "waterTurbines.obj"));
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
TileTurbine tile = (TileTurbine) t;
if (tile.getMultiBlock().isPrimary())
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
GL11.glPushMatrix();
// Determine if the turbine is facing horizontally or vertical.
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection());
// Get the rotation directly from the resonantinduction.mechanical node running client side.
double mechanicalNodeRenderAngle = tile.mechanicalNode.renderAngle;
// We need to convert this value into something the model renderer can understand.
// Note: Check for NaN and if so then just defaults to zero.
float renderAngleInDegrees = 0;
if (!Double.isNaN(mechanicalNodeRenderAngle))
{
renderAngleInDegrees = (float) Math.toDegrees(mechanicalNodeRenderAngle);
}
// Call to actually rotate the gear model to the specified degree.
GL11.glRotatef(renderAngleInDegrees, 0, 1, 0);
//ResonantInduction.LOGGER.info("[RenderWaterTurbine] Render Angle: " + renderAngleInDegrees);
// Determine what type of water turbine model we need to use based on orientation.
if (tile.getDirection().offsetY != 0)
{
renderWaterTurbine(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
}
else
{
renderWaterWheel(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
}
GL11.glPopMatrix();
GL11.glPopMatrix();
}
}
@Override
public void renderInventoryItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data)
{
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 0.5f, 0.5f);
renderWaterTurbine(itemStack.getItemDamage(), 1, false);
GL11.glPopMatrix();
}
public void renderWaterWheel(int tier, int size, boolean isLarge)
{
if (isLarge)
{
GL11.glScalef(0.3f, 1, 0.3f);
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1);
GL11.glPushMatrix();
GL11.glScalef(1, 1.6f, 1);
RenderUtility.bind(Reference.blockTextureDirectory() + "cobblestone.png");
MODEL.renderOnly("bigwheel_endknot", "horizontal_centre_shaft");
GL11.glPopMatrix();
GL11.glPushMatrix();
GL11.glScalef(1, 1.4f, 1);
RenderUtility.bind(Reference.blockTextureDirectory() + "planks_spruce.png");
MODEL.renderOnly("bigwheel_supporters");
bindTexture(tier);
MODEL.renderOnly("bigwheel_scoops", "bigwheel_supportercircle");
GL11.glPopMatrix();
}
else
{
GL11.glPushMatrix();
GL11.glScalef(0.7f, 1, 0.7f);
RenderUtility.bind(Reference.blockTextureDirectory() + "cobblestone.png");
MODEL.renderOnly("small_waterwheel_endknot");
bindTexture(tier);
MODEL.renderOnly("small_waterwheel", "small_waterwheel_supporters", "horizontal_centre_shaft");
GL11.glPopMatrix();
}
}
public void renderWaterTurbine(int tier, int size, boolean isLarge)
{
if (isLarge)
{
GL11.glScalef(0.3f, 1, 0.3f);
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1);
bindTexture(tier);
MODEL.renderOnly("turbine_centre");
MODEL.renderOnly("turbine_blades");
}
else
{
GL11.glPushMatrix();
GL11.glScalef(0.9f, 1f, 0.9f);
RenderUtility.bind(Reference.blockTextureDirectory() + "log_oak.png");
MODEL.renderOnly("small_waterwheel_endknot");
bindTexture(tier);
MODEL.renderOnly("small_turbine_blades");
GL11.glPopMatrix();
}
}
public void bindTexture(int tier)
{
switch (tier)
{
case 0:
RenderUtility.bind(Reference.blockTextureDirectory() + "planks_oak.png");
break;
case 1:
RenderUtility.bind(Reference.blockTextureDirectory() + "cobblestone.png");
break;
case 2:
RenderUtility.bind(Reference.blockTextureDirectory() + "iron_block.png");
break;
}
}
}

View file

@ -0,0 +1,129 @@
package resonantinduction.mechanical.mech.turbine
import cpw.mods.fml.relauncher.Side
import cpw.mods.fml.relauncher.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 org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference
@SideOnly(Side.CLIENT) object RenderWaterTurbine
{
final val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "waterTurbines.obj"))
}
@SideOnly(Side.CLIENT) class RenderWaterTurbine extends TileEntitySpecialRenderer with ISimpleItemRenderer
{
def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float)
{
val tile: TileTurbine = t.asInstanceOf[TileTurbine]
if (tile.getMultiBlock.isPrimary)
{
GL11.glPushMatrix
GL11.glTranslatef(x.asInstanceOf[Float] + 0.5f, y.asInstanceOf[Float] + 0.5f, z.asInstanceOf[Float] + 0.5f)
GL11.glPushMatrix
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection)
val mechanicalNodeRenderAngle: Double = tile.mechanicalNode.renderAngle
var renderAngleInDegrees: Float = 0
if (!java.lang.Double.isNaN(mechanicalNodeRenderAngle))
{
renderAngleInDegrees = Math.toDegrees(mechanicalNodeRenderAngle).asInstanceOf[Float]
}
GL11.glRotatef(renderAngleInDegrees, 0, 1, 0)
if (tile.getDirection.offsetY != 0)
{
renderWaterTurbine(tile.tier, tile.multiBlockRadius, tile.getMultiBlock.isConstructed)
}
else
{
renderWaterWheel(tile.tier, tile.multiBlockRadius, tile.getMultiBlock.isConstructed)
}
GL11.glPopMatrix
GL11.glPopMatrix
}
}
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
{
GL11.glPushMatrix
GL11.glTranslatef(0.5f, 0.5f, 0.5f)
renderWaterTurbine(itemStack.getItemDamage, 1, false)
GL11.glPopMatrix
}
def renderWaterWheel(tier: Int, size: Int, isLarge: Boolean)
{
if (isLarge)
{
GL11.glScalef(0.3f, 1, 0.3f)
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1)
GL11.glPushMatrix
GL11.glScalef(1, 1.6f, 1)
RenderUtility.bind(Reference.blockTextureDirectory + "cobblestone.png")
RenderWaterTurbine.MODEL.renderOnly("bigwheel_endknot", "horizontal_centre_shaft")
GL11.glPopMatrix
GL11.glPushMatrix
GL11.glScalef(1, 1.4f, 1)
RenderUtility.bind(Reference.blockTextureDirectory + "planks_spruce.png")
RenderWaterTurbine.MODEL.renderOnly("bigwheel_supporters")
bindTexture(tier)
RenderWaterTurbine.MODEL.renderOnly("bigwheel_scoops", "bigwheel_supportercircle")
GL11.glPopMatrix
}
else
{
GL11.glPushMatrix
GL11.glScalef(0.7f, 1, 0.7f)
RenderUtility.bind(Reference.blockTextureDirectory + "cobblestone.png")
RenderWaterTurbine.MODEL.renderOnly("small_waterwheel_endknot")
bindTexture(tier)
RenderWaterTurbine.MODEL.renderOnly("small_waterwheel", "small_waterwheel_supporters", "horizontal_centre_shaft")
GL11.glPopMatrix
}
}
def renderWaterTurbine(tier: Int, size: Int, isLarge: Boolean)
{
if (isLarge)
{
GL11.glScalef(0.3f, 1, 0.3f)
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1)
bindTexture(tier)
RenderWaterTurbine.MODEL.renderOnly("turbine_centre")
RenderWaterTurbine.MODEL.renderOnly("turbine_blades")
}
else
{
GL11.glPushMatrix
GL11.glScalef(0.9f, 1f, 0.9f)
RenderUtility.bind(Reference.blockTextureDirectory + "log_oak.png")
RenderWaterTurbine.MODEL.renderOnly("small_waterwheel_endknot")
bindTexture(tier)
RenderWaterTurbine.MODEL.renderOnly("small_turbine_blades")
GL11.glPopMatrix
}
}
def bindTexture(tier: Int)
{
if (tier == 0)
{
RenderUtility.bind(Reference.blockTextureDirectory + "planks_oak.png")
}
else if (tier == 1)
{
RenderUtility.bind(Reference.blockTextureDirectory + "cobblestone.png")
}
else if (tier == 2)
{
RenderUtility.bind(Reference.blockTextureDirectory + "iron_block.png")
}
}
}

View file

@ -1,101 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
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 org.lwjgl.opengl.GL11;
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;
@SideOnly(Side.CLIENT)
public class RenderWindTurbine extends TileEntitySpecialRenderer implements ISimpleItemRenderer
{
public static final IModelCustom MODEL = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain(), Reference.modelPath() + "windTurbines.obj"));
@Override
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
{
TileTurbine tile = (TileTurbine) t;
if (tile.getMultiBlock().isPrimary())
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
GL11.glPushMatrix();
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection());
GL11.glTranslatef(0, 0.35f, 0);
GL11.glRotatef(180, 1, 0, 0);
GL11.glRotatef((float) Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0);
render(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
GL11.glPopMatrix();
GL11.glPopMatrix();
}
}
@Override
public void renderInventoryItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data)
{
GL11.glPushMatrix();
GL11.glTranslatef(0.5f, 0.5f, 0.5f);
render(itemStack.getItemDamage(), 1, false);
GL11.glPopMatrix();
}
public void render(int tier, int size, boolean isConstructed)
{
switch (tier)
{
case 0:
RenderUtility.bind(Reference.blockTextureDirectory() + "planks_oak.png");
break;
case 1:
RenderUtility.bind(Reference.blockTextureDirectory() + "cobblestone.png");
break;
case 2:
RenderUtility.bind(Reference.blockTextureDirectory() + "iron_block.png");
break;
}
if (isConstructed)
{
GL11.glScalef(0.3f, 1, 0.3f);
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1);
if (tier == 2)
{
GL11.glTranslatef(0, -0.11f, 0);
MODEL.renderOnly("LargeMetalBlade");
MODEL.renderOnly("LargeMetalHub");
}
else
{
MODEL.renderOnly("LargeBladeArm");
GL11.glScalef(1f, 2f, 1f);
GL11.glTranslatef(0, -0.05f, 0);
MODEL.renderOnly("LargeHub");
RenderUtility.bind(Reference.blockTextureDirectory() + "wool_colored_white.png");
MODEL.renderOnly("LargeBlade");
}
}
else
{
MODEL.renderOnly("SmallBlade");
RenderUtility.bind(Reference.blockTextureDirectory() + "log_oak.png");
MODEL.renderOnly("SmallHub");
}
}
}

View file

@ -0,0 +1,88 @@
package resonantinduction.mechanical.mech.turbine
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, IModelCustom}
import org.lwjgl.opengl.GL11
import resonant.content.prefab.scala.render.ISimpleItemRenderer
import resonant.lib.render.RenderUtility
import resonantinduction.core.Reference
@SideOnly(Side.CLIENT) object RenderWindTurbine
{
final val MODEL: IModelCustom = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "windTurbines.obj"))
}
@SideOnly(Side.CLIENT) class RenderWindTurbine extends TileEntitySpecialRenderer with ISimpleItemRenderer
{
def renderTileEntityAt(t: TileEntity, x: Double, y: Double, z: Double, f: Float)
{
val tile: TileTurbine = t.asInstanceOf[TileTurbine]
if (tile.getMultiBlock.isPrimary)
{
GL11.glPushMatrix
GL11.glTranslatef(x.asInstanceOf[Float] + 0.5f, y.asInstanceOf[Float] + 0.5f, z.asInstanceOf[Float] + 0.5f)
GL11.glPushMatrix
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection)
GL11.glTranslatef(0, 0.35f, 0)
GL11.glRotatef(180, 1, 0, 0)
GL11.glRotatef(Math.toDegrees(tile.mechanicalNode.renderAngle).asInstanceOf[Float], 0, 1, 0)
render(tile.tier, tile.multiBlockRadius, tile.getMultiBlock.isConstructed)
GL11.glPopMatrix
GL11.glPopMatrix
}
}
def renderInventoryItem(`type`: IItemRenderer.ItemRenderType, itemStack: ItemStack, data: AnyRef*)
{
GL11.glPushMatrix
GL11.glTranslatef(0.5f, 0.5f, 0.5f)
render(itemStack.getItemDamage, 1, false)
GL11.glPopMatrix
}
def render(tier: Int, size: Int, isConstructed: Boolean)
{
if (tier == 0)
{
RenderUtility.bind(Reference.blockTextureDirectory + "planks_oak.png")
} else if (tier == 1)
{
RenderUtility.bind(Reference.blockTextureDirectory + "cobblestone.png")
} else if (tier == 2)
{
RenderUtility.bind(Reference.blockTextureDirectory + "iron_block.png")
}
if (isConstructed)
{
GL11.glScalef(0.3f, 1, 0.3f)
GL11.glScalef(size * 2 + 1, Math.min(size, 2), size * 2 + 1)
if (tier == 2)
{
GL11.glTranslatef(0, -0.11f, 0)
RenderWindTurbine.MODEL.renderOnly("LargeMetalBlade")
RenderWindTurbine.MODEL.renderOnly("LargeMetalHub")
}
else
{
RenderWindTurbine.MODEL.renderOnly("LargeBladeArm")
GL11.glScalef(1f, 2f, 1f)
GL11.glTranslatef(0, -0.05f, 0)
RenderWindTurbine.MODEL.renderOnly("LargeHub")
RenderUtility.bind(Reference.blockTextureDirectory + "wool_colored_white.png")
RenderWindTurbine.MODEL.renderOnly("LargeBlade")
}
}
else
{
RenderWindTurbine.MODEL.renderOnly("SmallBlade")
RenderUtility.bind(Reference.blockTextureDirectory + "log_oak.png")
RenderWindTurbine.MODEL.renderOnly("SmallHub")
}
}
}

View file

@ -1,247 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import resonant.lib.multiblock.reference.IMultiBlockStructure;
import resonant.lib.network.handle.IPacketIDReceiver;
import resonantinduction.mechanical.mech.TileMechanical;
import net.minecraft.block.material.Material;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import resonantinduction.mechanical.mech.gear.ItemHandCrank;
import universalelectricity.api.core.grid.INodeProvider;
import universalelectricity.core.transform.vector.Vector3;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** Reduced version of the main turbine class */
public class TileTurbine extends TileMechanical implements IMultiBlockStructure<TileTurbine>, INodeProvider, IPacketIDReceiver
{
/** Tier of the tile */
public int tier = 0;
/** Radius of large turbine? */
public int multiBlockRadius = 1;
/** Max power in watts. */
protected long maxPower;
/** The power of the turbine this tick. In joules/tick */
public long power = 0;
protected final long defaultTorque = 5000;
/** MutliBlock methods. */
private TurbineMBlockHandler multiBlock;
public TileTurbine()
{
super(Material.wood);
normalRender(false);
isOpaqueCube(false);
setTextureName("material_wood_surface");
mechanicalNode = new TurbineNode(this);
rotationMask_$eq(Byte.parseByte("111111", 2));
}
@Override
public void onRemove(Block block, int par1)
{
super.onRemove(block, par1);
getMultiBlock().deconstruct();
}
@Override
public void update()
{
super.update();
getMultiBlock().update();
if (getMultiBlock().isPrimary())
{
if (!worldObj.isRemote)
{
/** Set angular velocity based on power and torque. */
mechanicalNode.angularVelocity = (float) ((double) power / mechanicalNode.torque);
}
if (mechanicalNode.angularVelocity != 0)
{
playSound();
}
}
if (!worldObj.isRemote)
power = 0;
}
protected long getMaxPower()
{
if (this.getMultiBlock().isConstructed())
{
return (long) (maxPower * getArea());
}
return maxPower;
}
public int getArea()
{
return (int) (((multiBlockRadius + 0.5) * 2) * ((multiBlockRadius + 0.5) * 2));
}
/** Called to play sound effects */
public void playSound()
{
}
/** Reads a tile entity from NBT. */
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
multiBlockRadius = nbt.getInteger("multiBlockRadius");
tier = nbt.getInteger("tier");
getMultiBlock().load(nbt);
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("multiBlockRadius", multiBlockRadius);
nbt.setInteger("tier", tier);
getMultiBlock().save(nbt);
}
@Override
@SideOnly(Side.CLIENT)
public AxisAlignedBB getRenderBoundingBox()
{
return AxisAlignedBB.getBoundingBox(this.xCoord - multiBlockRadius, this.yCoord - multiBlockRadius, this.zCoord - multiBlockRadius, this.xCoord + 1 + multiBlockRadius, this.yCoord + 1 + multiBlockRadius, this.zCoord + 1 + multiBlockRadius);
}
@Override
public Iterable<Vector3> getMultiBlockVectors()
{
//TODO replace with helper class that takes a direction and size input
Set<Vector3> vectors = new HashSet<Vector3>();
ForgeDirection dir = getDirection();
int xMulti = dir.offsetX != 0 ? 0 : 1;
int yMulti = dir.offsetY != 0 ? 0 : 1;
int zMulti = dir.offsetZ != 0 ? 0 : 1;
for (int x = -multiBlockRadius; x <= multiBlockRadius; x++)
{
for (int y = -multiBlockRadius; y <= multiBlockRadius; y++)
{
for (int z = -multiBlockRadius; z <= multiBlockRadius; z++)
{
vectors.add(new Vector3(x * xMulti, y * yMulti, z * zMulti));
}
}
}
return vectors;
}
@Override
public Vector3 getPosition()
{
return new Vector3(this);
}
@Override
public TurbineMBlockHandler getMultiBlock()
{
if (multiBlock == null)
multiBlock = new TurbineMBlockHandler(this);
return multiBlock;
}
@Override
public void onMultiBlockChanged()
{
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType() != null ? getBlockType() : null);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
@Override
public World getWorld()
{
return worldObj;
}
@Override
public boolean use(EntityPlayer player, int side, Vector3 hit)
{
//Rotate spin direction if the users clicks with a crank
if (player.getCurrentEquippedItem() != null && player.getCurrentEquippedItem().getItem() instanceof ItemHandCrank)
{
if (!world().isRemote)
{
mechanicalNode.torque = -mechanicalNode.torque;
mechanicalNode.angularVelocity = -mechanicalNode.angularVelocity;
}
return true;
}
return super.use(player, side, hit);
}
@Override
public boolean configure(EntityPlayer player, int side, Vector3 hit)
{
//Build or destroy multi block if not sneaking
if(!player.isSneaking()) {
if (getMultiBlock().isConstructed()) {
getMultiBlock().deconstruct();
multiBlockRadius++;
if (!getMultiBlock().construct()) {
multiBlockRadius = 1;
}
return true;
} else {
if (!getMultiBlock().construct()) {
multiBlockRadius = 1;
getMultiBlock().construct();
}
}
}else // Flip turbine in the opposite direction its facing
{
Set<TileTurbine> toFlip = new HashSet<TileTurbine>();
if (!getMultiBlock().isConstructed())
{
toFlip.add(this);
}
else
{
Set<TileTurbine> str = getMultiBlock().getPrimary().getMultiBlock().getStructure();
if (str != null)
toFlip.addAll(str);
}
for (TileTurbine turbine : toFlip)
{
if (side == turbine.getDirection().ordinal())
world().setBlockMetadataWithNotify(turbine.xCoord, turbine.yCoord, turbine.zCoord, side ^ 1, 3);
else
world().setBlockMetadataWithNotify(turbine.xCoord, turbine.yCoord, turbine.zCoord, side, 3);
}
}
return true;
}
}

View file

@ -0,0 +1,212 @@
package resonantinduction.mechanical.mech.turbine
import java.util.{HashSet, Set}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.block.Block
import net.minecraft.block.material.Material
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.AxisAlignedBB
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.multiblock.reference.IMultiBlockStructure
import resonant.lib.network.handle.IPacketIDReceiver
import resonantinduction.mechanical.mech.TileMechanical
import resonantinduction.mechanical.mech.gear.ItemHandCrank
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.core.transform.vector.Vector3
/** Reduced version of the main turbine class */
class TileTurbine extends TileMechanical(Material.wood) with IMultiBlockStructure[TileTurbine] with INodeProvider with IPacketIDReceiver
{
/** Tier of the tile */
var tier: Int = 0
/** Radius of large turbine? */
var multiBlockRadius: Int = 1
/** Max power in watts. */
protected var maxPower: Long = 0L
/** The power of the turbine this tick. In joules/tick */
var power: Double = 0
protected final val defaultTorque: Long = 5000
/** MutliBlock methods. */
private var multiBlock: TurbineMBlockHandler = null
//Constructor
normalRender(false)
isOpaqueCube(false)
setTextureName("material_wood_surface")
mechanicalNode = new TurbineNode(this)
rotationMask = 63
override def onRemove(block: Block, par1: Int)
{
super.onRemove(block, par1)
getMultiBlock.deconstruct
}
override def update
{
super.update
getMultiBlock.update
if (getMultiBlock.isPrimary)
{
if (!worldObj.isRemote)
{
mechanicalNode.angularVelocity = (power.asInstanceOf[Double] / mechanicalNode.torque).asInstanceOf[Float]
}
if (mechanicalNode.angularVelocity != 0)
{
playSound
}
}
if (!worldObj.isRemote) power = 0
}
protected def getMaxPower: Long =
{
if (this.getMultiBlock.isConstructed)
{
return (maxPower * getArea).asInstanceOf[Long]
}
return maxPower
}
def getArea: Int =
{
return (((multiBlockRadius + 0.5) * 2) * ((multiBlockRadius + 0.5) * 2)).asInstanceOf[Int]
}
/** Called to play sound effects */
def playSound
{
}
/** Reads a tile entity from NBT. */
override def readFromNBT(nbt: NBTTagCompound)
{
super.readFromNBT(nbt)
multiBlockRadius = nbt.getInteger("multiBlockRadius")
tier = nbt.getInteger("tier")
getMultiBlock.load(nbt)
}
/** Writes a tile entity to NBT. */
override def writeToNBT(nbt: NBTTagCompound)
{
super.writeToNBT(nbt)
nbt.setInteger("multiBlockRadius", multiBlockRadius)
nbt.setInteger("tier", tier)
getMultiBlock.save(nbt)
}
@SideOnly(Side.CLIENT) override def getRenderBoundingBox: AxisAlignedBB =
{
return AxisAlignedBB.getBoundingBox(this.xCoord - multiBlockRadius, this.yCoord - multiBlockRadius, this.zCoord - multiBlockRadius, this.xCoord + 1 + multiBlockRadius, this.yCoord + 1 + multiBlockRadius, this.zCoord + 1 + multiBlockRadius)
}
def getMultiBlockVectors: java.lang.Iterable[Vector3] =
{
val vectors: Set[Vector3] = new HashSet[Vector3]
val dir: ForgeDirection = getDirection
val xMulti: Int = if (dir.offsetX != 0) 0 else 1
val yMulti: Int = if (dir.offsetY != 0) 0 else 1
val zMulti: Int = if (dir.offsetZ != 0) 0 else 1
for (x : Int <- -multiBlockRadius to multiBlockRadius)
{
for (y : Int <- -multiBlockRadius to multiBlockRadius)
{
for (z : Int <- -multiBlockRadius to multiBlockRadius)
{
vectors.add(new Vector3(x * xMulti, y * yMulti, z * zMulti))
}
}
}
return vectors
}
def getPosition: Vector3 =
{
return new Vector3(this)
}
def getMultiBlock: TurbineMBlockHandler =
{
if (multiBlock == null) multiBlock = new TurbineMBlockHandler(this)
return multiBlock
}
def onMultiBlockChanged
{
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, if (getBlockType != null) getBlockType else null)
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord)
}
def getWorld: World =
{
return worldObj
}
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
if (player.getCurrentEquippedItem != null && player.getCurrentEquippedItem.getItem.isInstanceOf[ItemHandCrank])
{
if (!world.isRemote)
{
mechanicalNode.torque = -mechanicalNode.torque
mechanicalNode.angularVelocity = -mechanicalNode.angularVelocity
}
return true
}
return super.use(player, side, hit)
}
override def configure(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
{
if (!player.isSneaking)
{
if (getMultiBlock.isConstructed)
{
getMultiBlock.deconstruct
multiBlockRadius += 1
if (!getMultiBlock.construct)
{
multiBlockRadius = 1
}
return true
}
else
{
if (!getMultiBlock.construct)
{
multiBlockRadius = 1
getMultiBlock.construct
}
}
}
else
{
val toFlip: Set[TileTurbine] = new HashSet[TileTurbine]
if (!getMultiBlock.isConstructed)
{
toFlip.add(this)
}
else
{
val str: Set[TileTurbine] = getMultiBlock.getPrimary.getMultiBlock.getStructure
if (str != null) toFlip.addAll(str)
}
import scala.collection.JavaConversions._
for (turbine <- toFlip)
{
if (side == turbine.getDirection.ordinal) world.setBlockMetadataWithNotify(turbine.xCoord, turbine.yCoord, turbine.zCoord, side ^ 1, 3)
else world.setBlockMetadataWithNotify(turbine.xCoord, turbine.yCoord, turbine.zCoord, side, 3)
}
}
return true
}
}

View file

@ -1,165 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
import java.lang.reflect.Method;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockDynamicLiquid;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.content.prefab.itemblock.ItemBlockMetadata;
import resonantinduction.core.Settings;
import resonantinduction.mechanical.mech.MechanicalNode;
import universalelectricity.api.core.grid.INodeProvider;
import universalelectricity.core.transform.vector.Vector3;
import cpw.mods.fml.relauncher.ReflectionHelper;
/**
* The vertical water turbine collects flowing water flowing on X axis.
* The horizontal water turbine collects flowing water on Z axis.
*
* @author Calclavia
*
*/
public class TileWaterTurbine extends TileTurbine
{
public int powerTicks = 0;
public TileWaterTurbine()
{
super();
this.itemBlock_$eq(ItemBlockMetadata.class);
mechanicalNode.torque = defaultTorque;
mechanicalNode = new TurbineNode(this)
{
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
if (source instanceof MechanicalNode && !(source instanceof TileTurbine))
{
/**
* Face to face stick connection.
*/
TileEntity sourceTile = position().add(from).getTileEntity(getWorld());
if (sourceTile instanceof INodeProvider)
{
MechanicalNode sourceInstance = (MechanicalNode) ((INodeProvider) sourceTile).getNode(MechanicalNode.class, from.getOpposite());
return sourceInstance == source && (from == getDirection().getOpposite() || from == getDirection());
}
}
return false;
}
};
}
@Override
public void update()
{
super.update();
if (getMultiBlock().isConstructed())
{
mechanicalNode.torque = (long) (defaultTorque / (1d / multiBlockRadius));
}
else
{
mechanicalNode.torque = defaultTorque / 12;
}
/**
* If this is a horizontal turbine.
*/
if (getDirection().offsetY != 0)
{
maxPower = 10000;
if (powerTicks > 0)
{
getMultiBlock().get().power += getWaterPower();
powerTicks--;
}
if (ticks() % 20 == 0)
{
Block blockIDAbove = worldObj.getBlock(xCoord, yCoord + 1, zCoord);
int metadata = worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord);
boolean isWater = (blockIDAbove == Blocks.water || blockIDAbove == Blocks.flowing_water);
if (isWater && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && metadata == 0)
{
powerTicks = 20;
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord);
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water);
}
}
}
else
{
maxPower = 2500;
ForgeDirection currentDir = getDirection();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
if (dir != currentDir && dir != currentDir.getOpposite())
{
Vector3 check = new Vector3(this).add(dir);
Block blockID = worldObj.getBlock(check.xi(), check.yi(), check.zi());
int metadata = worldObj.getBlockMetadata(check.xi(), check.yi(), check.zi());
if (blockID == Blocks.water || blockID == Blocks.flowing_water)
{
try
{
Method m = ReflectionHelper.findMethod(BlockDynamicLiquid.class, null, new String[] { "getFlowVector", "func_72202_i" }, IBlockAccess.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
Vector3 vector = new Vector3((Vec3) m.invoke(Blocks.water, worldObj, check.xi(), check.yi(), check.zi()));
if ((currentDir.offsetZ > 0 && vector.x() < 0) || (currentDir.offsetZ < 0 && vector.x() > 0) || (currentDir.offsetX > 0 && vector.z() > 0) || (currentDir.offsetX < 0 && vector.z() < 0))
{
mechanicalNode.torque = -mechanicalNode.torque;
}
if (getDirection().offsetX != 0)
{
getMultiBlock().get().power += Math.abs(getWaterPower() * vector.z() * (7 - metadata) / 7f);
powerTicks = 20;
}
if (getDirection().offsetZ != 0)
{
getMultiBlock().get().power += Math.abs(getWaterPower() * vector.x() * (7 - metadata) / 7f);
powerTicks = 20;
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}
}
/**
* Gravitation Potential Energy:
* PE = mgh
*/
private long getWaterPower()
{
return (maxPower / (2 - tier + 1)) * Settings.WATER_POWER_RATIO();
}
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < 3; i++)
par3List.add(new ItemStack(par1, 1, i));
}
}

View file

@ -0,0 +1,147 @@
package resonantinduction.mechanical.mech.turbine
import java.lang.reflect.Method
import java.util.List
import cpw.mods.fml.relauncher.ReflectionHelper
import net.minecraft.block.{Block, BlockDynamicLiquid}
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.init.Blocks
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.tileentity.TileEntity
import net.minecraft.util.Vec3
import net.minecraft.world.IBlockAccess
import net.minecraftforge.common.util.ForgeDirection
import resonant.content.prefab.itemblock.ItemBlockMetadata
import resonantinduction.core.Settings
import resonantinduction.mechanical.mech.MechanicalNode
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.core.transform.vector.Vector3
import resonant.lib.wrapper.WrapList._
/**
* The vertical water turbine collects flowing water flowing on X axis.
* The horizontal water turbine collects flowing water on Z axis.
*
* @author Calclavia
*
*/
class TileWaterTurbine extends TileTurbine
{
var powerTicks: Int = 0
//Constructor
this.itemBlock_$eq(classOf[ItemBlockMetadata])
mechanicalNode.torque = defaultTorque
mechanicalNode = new TurbineNode((this))
{
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
{
if (source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TileTurbine]))
{
val sourceTile: TileEntity = position.add(from).getTileEntity(getWorld)
if (sourceTile.isInstanceOf[INodeProvider])
{
val sourceInstance: MechanicalNode = (sourceTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], from.getOpposite).asInstanceOf[MechanicalNode]
return sourceInstance == source && (from == getDirection.getOpposite || from == getDirection)
}
}
return false
}
}
//End Constructor
override def update
{
super.update
if (getMultiBlock.isConstructed)
{
mechanicalNode.torque = (defaultTorque / (1d / multiBlockRadius)).asInstanceOf[Long]
}
else
{
mechanicalNode.torque = defaultTorque / 12
}
if (getDirection.offsetY != 0)
{
maxPower = 10000
if (powerTicks > 0)
{
getMultiBlock.get.power += getWaterPower
powerTicks -= 1
}
if (ticks % 20 == 0)
{
val blockIDAbove: Block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
val metadata: Int = worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord)
val isWater: Boolean = (blockIDAbove == Blocks.water || blockIDAbove == Blocks.flowing_water)
if (isWater && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && metadata == 0)
{
powerTicks = 20
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water)
}
}
}
else
{
maxPower = 2500
val currentDir: ForgeDirection = getDirection
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
if (dir != currentDir && dir != currentDir.getOpposite)
{
val check: Vector3 = new Vector3(this).add(dir)
val blockID: Block = worldObj.getBlock(check.xi, check.yi, check.zi)
val metadata: Int = worldObj.getBlockMetadata(check.xi, check.yi, check.zi)
if (blockID == Blocks.water || blockID == Blocks.flowing_water)
{
try
{
val m: Method = ReflectionHelper.findMethod(classOf[BlockDynamicLiquid], null, Array[String]("getFlowVector", "func_72202_i"), classOf[IBlockAccess], Integer.TYPE, Integer.TYPE, Integer.TYPE)
val vector: Vector3 = new Vector3(m.invoke(Blocks.water, Array(worldObj, check.xi, check.yi, check.zi)).asInstanceOf[Vec3])
if ((currentDir.offsetZ > 0 && vector.x < 0) || (currentDir.offsetZ < 0 && vector.x > 0) || (currentDir.offsetX > 0 && vector.z > 0) || (currentDir.offsetX < 0 && vector.z < 0))
{
mechanicalNode.torque = -mechanicalNode.torque
}
if (getDirection.offsetX != 0)
{
getMultiBlock.get.power += Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f)
powerTicks = 20
}
if (getDirection.offsetZ != 0)
{
getMultiBlock.get.power += Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f)
powerTicks = 20
}
}
catch
{
case e: Exception =>
{
e.printStackTrace
}
}
}
}
}
}
}
/**
* Gravitation Potential Energy:
* PE = mgh
*/
private def getWaterPower: Long =
{
return (maxPower / (2 - tier + 1)) * Settings.WATER_POWER_RATIO
}
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
{
for (i <- 0 to 3)
{
par3List.add(new ItemStack(par1, 1, i))
}
}
}

View file

@ -1,132 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.biome.BiomeGenOcean;
import net.minecraft.world.biome.BiomeGenPlains;
import net.minecraftforge.common.util.ForgeDirection;
import resonant.content.prefab.itemblock.ItemBlockMetadata;
import resonant.lib.utility.inventory.InventoryUtility;
import resonantinduction.core.Settings;
import universalelectricity.core.transform.vector.Vector3;
import java.util.List;
/** The vertical wind turbine collects airflow. The horizontal wind turbine collects steam from steam
* power plants.
*
* @author Calclavia */
public class TileWindTurbine extends TileTurbine
{
private final byte[] openBlockCache = new byte[224];
private int checkCount = 0;
private float efficiency = 0;
private long windPower = 0;
public TileWindTurbine()
{
super();
this.itemBlock_$eq(ItemBlockMetadata.class);
}
@Override
public void update()
{
/** Break under storm. */
if (tier == 0 && getDirection().offsetY == 0 && worldObj.isRaining() && worldObj.isThundering() && worldObj.rand.nextFloat() < 0.00000008)
{
InventoryUtility.dropItemStack(worldObj, new Vector3(this), new ItemStack(Blocks.wool, 1 + worldObj.rand.nextInt(2)));
InventoryUtility.dropItemStack(worldObj, new Vector3(this), new ItemStack(Items.stick, 3 + worldObj.rand.nextInt(8)));
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
return;
}
/** Only the primary turbine ticks. */
if (!getMultiBlock().isPrimary())
return;
/** If this is a vertical turbine. */
if (getDirection().offsetY == 0)
{
maxPower = 3000;
if (ticks() % 20 == 0 && !worldObj.isRemote)
computePower();
getMultiBlock().get().power += windPower;
}
else
{
maxPower = 10000;
}
if (getMultiBlock().isConstructed())
mechanicalNode.torque = (long) (defaultTorque / (9d / multiBlockRadius));
else
mechanicalNode.torque = defaultTorque / 12;
super.update();
}
private void computePower()
{
int checkSize = 10;
int height = yCoord + checkCount / 28;
int deviation = checkCount % 7;
ForgeDirection checkDir;
Vector3 check;
switch (checkCount / 7 % 4)
{
case 0:
checkDir = ForgeDirection.NORTH;
check = new Vector3(xCoord - 3 + deviation, height, zCoord - 4);
break;
case 1:
checkDir = ForgeDirection.WEST;
check = new Vector3(xCoord - 4, height, zCoord - 3 + deviation);
break;
case 2:
checkDir = ForgeDirection.SOUTH;
check = new Vector3(xCoord - 3 + deviation, height, zCoord + 4);
break;
default:
checkDir = ForgeDirection.EAST;
check = new Vector3(xCoord + 4, height, zCoord - 3 + deviation);
}
byte openAirBlocks = 0;
while (openAirBlocks < checkSize && worldObj.isAirBlock(check.xi(), check.yi(), check.zi()))
{
check.add(checkDir);
openAirBlocks++;
}
efficiency = efficiency - openBlockCache[checkCount] + openAirBlocks;
openBlockCache[checkCount] = openAirBlocks;
checkCount = (checkCount + 1) % (openBlockCache.length - 1);
float multiblockMultiplier = (multiBlockRadius + 0.5f) * 2;
float materialMultiplier = tier == 0 ? 1.1f : tier == 1 ? 0.9f : 1;
BiomeGenBase biome = worldObj.getBiomeGenForCoords(xCoord, zCoord);
boolean hasBonus = biome instanceof BiomeGenOcean || biome instanceof BiomeGenPlains || biome == BiomeGenBase.river;
float windSpeed = (worldObj.rand.nextFloat() / 8) + (yCoord / 256f) * (hasBonus ? 1.2f : 1) + worldObj.getRainStrength(1.5f);
windPower = (long) Math.min(materialMultiplier * multiblockMultiplier * windSpeed * efficiency * Settings.WIND_POWER_RATIO(), maxPower * Settings.WIND_POWER_RATIO());
}
@Override
public void getSubBlocks(Item par1, CreativeTabs par2CreativeTabs, List par3List)
{
for (int i = 0; i < 3; i++)
par3List.add(new ItemStack(par1, 1, i));
}
}

View file

@ -0,0 +1,107 @@
package resonantinduction.mechanical.mech.turbine
import java.util.List
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.init.{Blocks, Items}
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.world.biome.{BiomeGenBase, BiomeGenOcean, BiomeGenPlains}
import net.minecraftforge.common.util.ForgeDirection
import resonant.content.prefab.itemblock.ItemBlockMetadata
import resonant.lib.utility.inventory.InventoryUtility
import resonantinduction.core.Settings
import universalelectricity.core.transform.vector.Vector3
import resonant.lib.wrapper.WrapList._
/** The vertical wind turbine collects airflow. The horizontal wind turbine collects steam from steam
* power plants.
*
* @author Calclavia */
class TileWindTurbine extends TileTurbine
{
private final val openBlockCache: Array[Byte] = new Array[Byte](224)
private var checkCount: Int = 0
private var efficiency: Float = 0
private var windPower: Long = 0
//Constructor
this.itemBlock = classOf[ItemBlockMetadata]
override def update
{
if (tier == 0 && getDirection.offsetY == 0 && worldObj.isRaining && worldObj.isThundering && worldObj.rand.nextFloat < 0.00000008)
{
InventoryUtility.dropItemStack(worldObj, new Vector3(this), new ItemStack(Blocks.wool, 1 + worldObj.rand.nextInt(2)))
InventoryUtility.dropItemStack(worldObj, new Vector3(this), new ItemStack(Items.stick, 3 + worldObj.rand.nextInt(8)))
worldObj.setBlockToAir(xCoord, yCoord, zCoord)
return
}
if (!getMultiBlock.isPrimary) return
if (getDirection.offsetY == 0)
{
maxPower = 3000
if (ticks % 20 == 0 && !worldObj.isRemote) computePower
getMultiBlock.get.power += windPower
}
else
{
maxPower = 10000
}
if (getMultiBlock.isConstructed) mechanicalNode.torque = (defaultTorque / (9d / multiBlockRadius)).asInstanceOf[Long]
else mechanicalNode.torque = defaultTorque / 12
super.update
}
private def computePower
{
val checkSize: Int = 10
val height: Int = yCoord + checkCount / 28
val deviation: Int = checkCount % 7
var checkDir: ForgeDirection = null
var check: Vector3 = null
var cc = checkCount / 7 % 4
if (cc == 0)
{
checkDir = ForgeDirection.NORTH
check = new Vector3(xCoord - 3 + deviation, height, zCoord - 4)
} else if (cc == 1)
{
checkDir = ForgeDirection.WEST
check = new Vector3(xCoord - 4, height, zCoord - 3 + deviation)
} else if (cc == 2)
{
checkDir = ForgeDirection.SOUTH
check = new Vector3(xCoord - 3 + deviation, height, zCoord + 4)
} else
{
checkDir = ForgeDirection.EAST
check = new Vector3(xCoord + 4, height, zCoord - 3 + deviation)
}
var openAirBlocks: Int = 0
while (openAirBlocks < checkSize && worldObj.isAirBlock(check.xi, check.yi, check.zi))
{
check.add(checkDir)
openAirBlocks += 1
}
efficiency = efficiency - openBlockCache(checkCount) + openAirBlocks
openBlockCache(checkCount) = openAirBlocks.asInstanceOf
checkCount = (checkCount + 1) % (openBlockCache.length - 1)
val multiblockMultiplier: Float = (multiBlockRadius + 0.5f) * 2
val materialMultiplier: Float = if (tier == 0) 1.1f else if (tier == 1) 0.9f else 1
val biome: BiomeGenBase = worldObj.getBiomeGenForCoords(xCoord, zCoord)
val hasBonus: Boolean = biome.isInstanceOf[BiomeGenOcean] || biome.isInstanceOf[BiomeGenPlains] || biome == BiomeGenBase.river
val windSpeed: Float = (worldObj.rand.nextFloat / 8) + (yCoord / 256f) * (if (hasBonus) 1.2f else 1) + worldObj.getRainStrength(1.5f)
windPower = Math.min(materialMultiplier * multiblockMultiplier * windSpeed * efficiency * Settings.WIND_POWER_RATIO, maxPower * Settings.WIND_POWER_RATIO).asInstanceOf[Long]
}
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
{
for (i <- 0 to 3)
{
par3List.add(new ItemStack(par1, 1, i))
}
}
}

View file

@ -1,28 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
import net.minecraft.tileentity.TileEntity;
import resonant.lib.multiblock.reference.MultiBlockHandler;
import universalelectricity.core.transform.vector.Vector3;
public class TurbineMBlockHandler extends MultiBlockHandler<TileTurbine>
{
public TurbineMBlockHandler(TileTurbine wrapper)
{
super(wrapper);
}
public TileTurbine getWrapperAt(Vector3 position)
{
TileEntity tile = position.getTileEntity(this.tile.getWorld());
if (tile != null && wrapperClass.isAssignableFrom(tile.getClass()))
{
if (((TileTurbine) tile).getDirection() == this.tile.getDirection() && ((TileTurbine) tile).tier == this.tile.tier)
{
return (TileTurbine) tile;
}
}
return null;
}
}

View file

@ -0,0 +1,21 @@
package resonantinduction.mechanical.mech.turbine
import net.minecraft.tileentity.TileEntity
import resonant.lib.multiblock.reference.MultiBlockHandler
import universalelectricity.core.transform.vector.Vector3
class TurbineMBlockHandler(wrapper: TileTurbine) extends MultiBlockHandler[TileTurbine](wrapper)
{
override def getWrapperAt(position: Vector3): TileTurbine =
{
val tile: TileEntity = position.getTileEntity(this.tile.getWorld)
if (tile != null && wrapperClass.isAssignableFrom(tile.getClass))
{
if ((tile.asInstanceOf[TileTurbine]).getDirection == this.tile.getDirection && (tile.asInstanceOf[TileTurbine]).tier == this.tile.tier)
{
return tile.asInstanceOf[TileTurbine]
}
}
return null
}
}

View file

@ -1,35 +0,0 @@
package resonantinduction.mechanical.mech.turbine;
import resonantinduction.mechanical.mech.MechanicalNode;
import net.minecraftforge.common.util.ForgeDirection;
/**
* Turbine's Mechanical node
* Turbines always face forward and connect from behind.
*
* @author Calclavia, Darkguardsman
*/
public class TurbineNode extends MechanicalNode
{
public TurbineNode(TileTurbine tileTurbineBase)
{
super(tileTurbineBase);
}
public TileTurbine turbine()
{
return (TileTurbine) getParent();
}
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
return turbine().getMultiBlock().isPrimary() && source instanceof MechanicalNode && !(source instanceof TurbineNode) && from == turbine().getDirection();
}
@Override
public boolean inverseRotation(ForgeDirection dir)
{
return dir == turbine().getDirection().getOpposite();
}
}

View file

@ -0,0 +1,29 @@
package resonantinduction.mechanical.mech.turbine
import resonantinduction.mechanical.mech.MechanicalNode
import net.minecraftforge.common.util.ForgeDirection
/**
* Turbine's Mechanical node
* Turbines always face forward and connect from behind.
*
* @author Calclavia, Darkguardsman
*/
class TurbineNode(tileTurbineBase: TileTurbine) extends MechanicalNode(tileTurbineBase)
{
def turbine: TileTurbine =
{
return getParent.asInstanceOf[TileTurbine]
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
{
return turbine.getMultiBlock.isPrimary && source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TurbineNode]) && from == turbine.getDirection
}
override def inverseRotation(dir: ForgeDirection): Boolean =
{
return dir == turbine.getDirection.getOpposite
}
}