Steam Piston & rod now translate energy correctly

Took some time but i got it too work, the steam piston will generate
mechanical energy and then traslate that energy to a rod which will
translate it to the next and so on. Now too just create the generator
and i'm done.
This commit is contained in:
Rseifert 2012-10-03 13:16:44 -04:00
parent 3d238fdd38
commit d2cafa890e
13 changed files with 186 additions and 148 deletions

View file

@ -12,8 +12,11 @@ import basicpipes.conductors.BlockRod;
import basicpipes.conductors.ItemGuage;
import basicpipes.conductors.ItemParts;
import basicpipes.conductors.ItemPipe;
import basicpipes.conductors.TileEntityPipe;
import basicpipes.conductors.TileEntityRod;
import basicpipes.machines.BlockMachine;
import basicpipes.machines.BlockValve;
import basicpipes.machines.TileEntityPump;
import basicpipes.pipes.api.Liquid;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
@ -82,6 +85,9 @@ public class BasicPipesMain{
{
//register
proxy.init();
GameRegistry.registerTileEntity(TileEntityPipe.class, "pipe");
GameRegistry.registerTileEntity(TileEntityPump.class, "pump");
GameRegistry.registerTileEntity(TileEntityRod.class, "rod");
//Names and lang stuff
//Pipe Names
for(int i =0; i < Liquid.values().length;i++)

View file

@ -18,9 +18,7 @@ public class PipeProxy implements IGuiHandler
}
public void init()
{
GameRegistry.registerTileEntity(TileEntityPipe.class, "pipe");
GameRegistry.registerTileEntity(TileEntityPump.class, "pump");
GameRegistry.registerTileEntity(TileEntityRod.class, "rod");
}
public void postInit()
{

View file

@ -28,14 +28,18 @@ public class BlockRod extends universalelectricity.prefab.BlockMachine {
int angle= MathHelper.floor_double((player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int meta = 0;
ForgeDirection idr;
int dZ = 0;
int dX = 0;
switch(angle)
{
case 0: meta = 2;break;
case 1: meta = 5;break;
case 2: meta = 3;break;
case 3: meta = 4;break;
case 0: meta = 2;dZ--;break;
case 1: meta = 5;dX--;break;
case 2: meta = 3;dZ++;break;
case 3: meta = 4;dX++;break;
}
world.setBlockAndMetadataWithUpdate(i, j, k,blockID, meta, true);
//ForgeDirection dir = ForgeDirection.getOrientation(meta);
world.setBlockAndMetadataWithUpdate(i, j, k,blockID, meta, true);
// world.setBlockAndMetadataWithUpdate(i+dir.offsetX, j, k+dir.offsetZ,blockID, meta, true);
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer)

View file

@ -3,7 +3,10 @@ package basicpipes.conductors;
import java.util.ArrayList;
import java.util.List;
import steampower.turbine.TileEntitySteamPiston;
import basicpipes.BasicPipesMain;
import basicpipes.pipes.api.IMechanical;
import basicpipes.pipes.api.Liquid;
import net.minecraft.src.*;
@ -65,19 +68,19 @@ public class ItemGuage extends Item
player.addChatMessage(print);
return true;
}/**
if(blockEntity instanceof TileEntityRod)
}
if(blockEntity instanceof IMechanical)
{
TileEntityRod rod = (TileEntityRod) blockEntity;
double steam = rod.loadRPM;
double pressure = rod.getForce(ForgeDirection.getOrientation(par7));
IMechanical rod = (IMechanical) blockEntity;
int steam = rod.getForce();
int pressure = rod.getAnimationPos();
String print = "Error";
print = " " + steam +"Load "+pressure+"RPM";
print = " " + steam +"N "+pressure*45+"degrees";
player.addChatMessage(print);
return true;
}*/
}
}
}

View file

@ -1,54 +1,123 @@
package basicpipes.conductors;
import com.google.common.io.ByteArrayDataInput;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.NetworkManager;
import net.minecraft.src.Packet;
import net.minecraft.src.Packet250CustomPayload;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import net.minecraftforge.common.ForgeDirection;
import steampower.SteamPowerMain;
import universalelectricity.network.IPacketReceiver;
import universalelectricity.network.PacketManager;
import universalelectricity.prefab.Vector3;
import basicpipes.BasicPipesMain;
import basicpipes.pipes.api.ILiquidConsumer;
import basicpipes.pipes.api.IMechenical;
import basicpipes.pipes.api.Liquid;
import basicpipes.pipes.api.IMechanical;
public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechenical {
import com.google.common.io.ByteArrayDataInput;
public class TileEntityRod extends TileEntity implements IPacketReceiver,IMechanical {
public int pos = 0;
private int force = 0;
public int aForce = 0;
public int forceMax = 1000;
private int tickCount = 0;
private int posCount = 0;
private ForgeDirection frontDir;
private ForgeDirection backDir;
private TileEntity bb;
private TileEntity ff;
@Override
public double getForce(ForgeDirection side) {
return 0;
public void updateEntity()
{
super.updateEntity();
if(tickCount++ >=10)
{ tickCount = 0;
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
frontDir = ForgeDirection.getOrientation(meta);
backDir = ForgeDirection.getOrientation(meta).getOpposite();
bb = worldObj.getBlockTileEntity(xCoord+backDir.offsetX, yCoord, zCoord+backDir.offsetZ);
ff = worldObj.getBlockTileEntity(xCoord+frontDir.offsetX, yCoord, zCoord+frontDir.offsetZ);
if(force > 0)
{
int posCountA = (forceMax/force) & 10;
if(posCount++ >= posCountA)
{
pos ++;if(pos > 7){pos = 0;};
}
}
if(bb instanceof TileEntityRod)
{
this.pos = ((IMechanical)bb).getAnimationPos();
}
if(!worldObj.isRemote)
{
aForce = Math.max(force - 10,0);
if(ff instanceof IMechanical)
{
if(((IMechanical) ff).canInputSide(backDir))
{
((IMechanical) ff).applyForce(aForce);
}
}
Packet packet = PacketManager.getPacket(SteamPowerMain.channel,this, new Object[]{force,aForce});
PacketManager.sendPacketToClients(packet, worldObj, Vector3.get(this), 40);
}
}
}
@Override
public int getForceSide(ForgeDirection side) {
return aForce;
}
@Override
public boolean canOutputSide(ForgeDirection side) {
// TODO Auto-generated method stub
if(side == frontDir)
{
return true;
}
return false;
}
@Override
public boolean canInputSide(ForgeDirection side) {
// TODO Auto-generated method stub
if(side == backDir)
{
return true;
}
return false;
}
@Override
public double applyForce(int force) {
// TODO Auto-generated method stub
return 0;
public int applyForce(int force) {
this.force = force;
return force;
}
@Override
public void handlePacketData(NetworkManager network,
Packet250CustomPayload packet, EntityPlayer player,
ByteArrayDataInput dataStream) {
// TODO Auto-generated method stub
try
{
this.force = dataStream.readInt();
this.aForce = dataStream.readInt();
}catch(Exception e)
{
e.printStackTrace();
System.out.print("MechRodDataFailure \n");
}
}
@Override
public int getAnimationPos() {
return this.pos;
}
@Override
public int getForce() {
// TODO Auto-generated method stub
return this.force;
}
}

View file

@ -2,13 +2,14 @@ package basicpipes.pipes.api;
import net.minecraftforge.common.ForgeDirection;
// mechanical
public interface IMechenical {
public interface IMechanical {
/**
*
* @param side the rpm is coming from
* @return rpm that the block is running at
*/
public double getForce(ForgeDirection side);
public int getForceSide(ForgeDirection side);
public int getForce();
/**
*
* @param side
@ -26,5 +27,10 @@ public interface IMechenical {
* @param RPM being applied to this machine
* @return the rpm after the load has been applied
*/
public double applyForce(int force);
public int applyForce(int force);
/**
* not required but is handy to get animation position of some mechanical block
* @return int between 0 -7
*/
public int getAnimationPos();
}

View file

@ -16,15 +16,15 @@ import universalelectricity.network.IPacketReceiver;
import basicpipes.conductors.TileEntityRod;
import basicpipes.pipes.api.ILiquidConsumer;
import basicpipes.pipes.api.ILiquidProducer;
import basicpipes.pipes.api.IMechenical;
import basicpipes.pipes.api.IMechanical;
import basicpipes.pipes.api.Liquid;
import basicpipes.conductors.*;
import com.google.common.io.ByteArrayDataInput;
public class TileEntitySteamPiston extends TileEntityMachine implements IPacketReceiver,ILiquidConsumer,ILiquidProducer,IMechenical
public class TileEntitySteamPiston extends TileEntityMachine implements IPacketReceiver,ILiquidConsumer,ILiquidProducer,IMechanical
{
private int force = 0;
public int force = 0;
public int aForce = 0;
private int frictionLoad = 10;
public int steam = 0;
@ -36,6 +36,7 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
private int runTime = 0;
private int genRate = 0;//max 100
private int posCount = 0;
public int tCount = 0;
private ForgeDirection frontDir;
private ForgeDirection backDir;
public TileEntity bb;
@ -48,11 +49,13 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
{
super.updateEntity();
if(tickCount++ >=10)
{
//++runTime;
//pos += 1;if(pos > 7){pos =0;} //for testing
{tickCount = 0;
++tCount;if(tCount > 120){tCount = 0;}
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
int nMeta = 0;
switch(meta)
{
case 0: nMeta = 2;break;
@ -82,34 +85,39 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
}
if(bb instanceof TileEntitySteamPiston)
{
this.pos = ((TileEntitySteamPiston) bb).pos + 1;
this.pos = ((TileEntitySteamPiston) bb).getAnimationPos() + 1;
if(this.pos > 7){pos = 0;}
}
if(!worldObj.isRemote)
{
if(this.runTime <= 0 && this.steam > 0)
if(this.runTime < 1 && this.steam > 0)
{
this.steam--;
this.runTime+=30;
}else
this.runTime=60;
}
if(this.runTime > 0)
{
genRate=Math.min(genRate + 1, 100);
this.runTime-=1;
this.force = genRate * 10;
this.force = Math.min(genRate * 10,1000);
this.aForce = Math.max(force - this.frictionLoad,0);
}
if(ff instanceof IMechenical)
if(runTime == 0 && this.steam == 0)
{
((IMechenical) ff).applyForce(this.aForce);
genRate = Math.max(genRate--, 0);
force= Math.max(force-=10, 0);;
}
if(genRate <=0 && runTime > 0)
if(ff instanceof IMechanical)
{
genRate++;
}else
{
genRate--;
if(((IMechanical) ff).canInputSide(backDir))
{
((IMechanical) ff).applyForce(this.aForce);
}
}
}
}
}
@ -119,7 +127,7 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
//Liquid and mechanical stuff
//----------------
@Override
public double getForce(ForgeDirection side) {
public int getForceSide(ForgeDirection side) {
return aForce;
}
@ -142,7 +150,7 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
}
@Override
public double applyForce(int force) {
public int applyForce(int force) {
this.aForce = this.force + force- frictionLoad;
return aForce;
}
@ -261,7 +269,8 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
{
super.readFromNBT(par1NBTTagCompound);
this.runTime = par1NBTTagCompound.getShort("time");
this.runTime = par1NBTTagCompound.getInteger("time");
this.genRate = par1NBTTagCompound.getInteger("gen");
this.steam = par1NBTTagCompound.getInteger("steam");
this.water = par1NBTTagCompound.getInteger("water");
}
@ -272,10 +281,25 @@ public class TileEntitySteamPiston extends TileEntityMachine implements IPacketR
public void writeToNBT(NBTTagCompound par1NBTTagCompound)
{
super.writeToNBT(par1NBTTagCompound);
par1NBTTagCompound.setShort("time", (short)this.runTime);
par1NBTTagCompound.setInteger("time", (int)this.runTime);
par1NBTTagCompound.setInteger("gen", (int)this.genRate);
par1NBTTagCompound.setInteger("steam", (int)this.steam);
par1NBTTagCompound.setInteger("water", (int)this.water);
}
@Override
public int getAnimationPos() {
// TODO Auto-generated method stub
return this.pos;
}
@Override
public int getForce() {
// TODO Auto-generated method stub
return this.force;
}
}

View file

@ -7,76 +7,6 @@ import basicpipes.pipes.api.ILiquidConsumer;
import basicpipes.pipes.api.ILiquidProducer;
import basicpipes.pipes.api.Liquid;
public class TileEntitytopGen extends TileEntityMachine implements ILiquidConsumer,ILiquidProducer {
public TileEntitySteamPiston genB = null;
public void updateEntity()
{
if(!this.worldObj.isRemote)
{
super.updateEntity();
TileEntity ent = worldObj.getBlockTileEntity(xCoord, yCoord-1, xCoord);
if(ent instanceof TileEntitySteamPiston)
{
genB = (TileEntitySteamPiston)ent;
}
}
}
@Override
public int onProduceLiquid(Liquid type, int maxVol, ForgeDirection side) {
// TODO Auto-generated method stub
return genB !=null ? genB.onProduceLiquid(type, maxVol, side) : 0;
}
public class TileEntitytopGen extends TileEntityMachine {
@Override
public boolean canProduceLiquid(Liquid type, ForgeDirection side) {
if(type == Liquid.WATER)
{
return true;
}
return genB !=null ? genB.canProduceLiquid(type, side) : false;
}
@Override
public int onReceiveLiquid(Liquid type, int vol, ForgeDirection side) {
// TODO Auto-generated method stub
return genB !=null ? genB.onReceiveLiquid(type, vol, side) : vol;
}
@Override
public boolean canRecieveLiquid(Liquid type, ForgeDirection side) {
if(type == Liquid.STEAM)
{
return true;
}
return genB !=null ? genB.canRecieveLiquid(type, side): false;
}
@Override
public int getStoredLiquid(Liquid type) {
// TODO Auto-generated method stub
return genB !=null ? genB.getStoredLiquid(type): 0;
}
@Override
public int getLiquidCapacity(Liquid type) {
// TODO Auto-generated method stub
return genB !=null ? genB.getLiquidCapacity(type): 0;
}
@Override
public int presureOutput(Liquid type, ForgeDirection side) {
if(type == Liquid.WATER)
{
return 32;
}
return 0;
}
@Override
public boolean canProducePresure(Liquid type, ForgeDirection side)
{
if(type == Liquid.WATER)
{
return true;
}
return false;
}
}

View file

@ -109,12 +109,13 @@ public class ModelGearRod extends ModelBase
Rod2.mirror = true;
setRotation(Rod2, 0F, 0F, 0.7853982F);
}
public void render(float f5,float r)
public void render(float f5,int r)
{
Rod.rotateAngleZ= 45 * r;
Rod2.rotateAngleZ= Rod.rotateAngleZ + 45;
Rod.render(f5);
Rod2.render(f5);
Rod.rotateAngleZ+= (r)*45;
Rod2.rotateAngleZ+= (r)*45;
//TODO add rotation to rods
front.render(f5);
back.render(f5);

View file

@ -22,8 +22,8 @@ public class PipeClientProxy extends PipeProxy
@Override
public void init()
{
ClientRegistry.registerTileEntity(TileEntityPipe.class, "pipe", new RenderPipe());
ClientRegistry.registerTileEntity(TileEntityPump.class, "pump", new RenderPump());
ClientRegistry.registerTileEntity(TileEntityRod.class, "rod", new RenderGearRod());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPipe.class, new RenderPipe());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityPump.class, new RenderPump());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRod.class, new RenderGearRod());
}
}

View file

@ -5,6 +5,8 @@ import net.minecraft.src.TileEntitySpecialRenderer;
import org.lwjgl.opengl.GL11;
import steampower.geared.ModelGearPiston;
import basicpipes.conductors.TileEntityPipe;
import basicpipes.conductors.TileEntityRod;
import basicpipes.machines.TileEntityPump;
@ -13,23 +15,18 @@ import basicpipes.pipes.api.Liquid;
public class RenderGearRod extends TileEntitySpecialRenderer
{
int type = 0;
private ModelGearRod model;
public RenderGearRod()
{
model = new ModelGearRod();
}
public void renderAModelAt(TileEntityRod tileEntity, double d, double d1, double d2, float f)
{
int meta = tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
bindTextureByName("/textures/GearRod.png");
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
int meta = tileEntity.worldObj.getBlockMetadata(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
switch(meta)
{
case 0: GL11.glRotatef(90f, 1f, 0f, 0f);break;

View file

@ -46,7 +46,7 @@ import universalelectricity.electricity.ElectricInfo.ElectricUnit;
{
if(tileEntity.steam> 0)
{
displayText = "OutPut Full";
displayText = "No Load";
}
if(tileEntity.steam<= 0)
{
@ -56,17 +56,18 @@ import universalelectricity.electricity.ElectricInfo.ElectricUnit;
else
{
//displayText = ElectricUnit.getWattDisplay((int)(tileEntity.generateRate*20));
displayText = "ForceOut: "+tileEntity.aForce+"N";
displayText = "ForceOut: "+tileEntity.force+"N";
}
displayText2 = "water" + "-" + tileEntity.water;
displayText3 = "steam" + "-" + tileEntity.steam;
if(tileEntity.bb != null){displayText4 = "Debug:bb" + "=" + tileEntity.bb.toString();}
if(tileEntity.ff != null){displayText5 = "Debugff" + "=" + tileEntity.ff.toString();}
displayText4 = "Debug:Time" + "=" + tileEntity.tCount;
this.fontRenderer.drawString(displayText, (int)(105-displayText.length()*1), 45, 4210752);
this.fontRenderer.drawString(displayText2, (int)(105-displayText.length()*1), 55, 4210752);
this.fontRenderer.drawString(displayText3, (int)(105-displayText.length()*1), 65, 4210752);
// this.fontRenderer.drawString(displayText4, (int)(105-displayText.length()*1), 75, 4210752);
// this.fontRenderer.drawString(displayText5, (int)(105-displayText.length()*1), 85, 4210752);
this.fontRenderer.drawString(displayText4, (int)(105-displayText.length()*1), 75, 4210752);
this.fontRenderer.drawString(displayText5, (int)(105-displayText.length()*1), 85, 4210752);
this.fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
}

View file

@ -10,7 +10,6 @@ import steampower.turbine.TileEntitySteamPiston;
public class RenderGearPiston extends TileEntitySpecialRenderer
{
int type = 0;
private ModelGearPiston model;
public RenderGearPiston()