Fixed #285 - Some water turbine/mill packet and logic
This commit is contained in:
parent
3f29f38449
commit
9f5b00669c
4 changed files with 102 additions and 54 deletions
|
@ -23,7 +23,7 @@ public class RenderWaterTurbine extends TileEntitySpecialRenderer implements ISi
|
|||
@Override
|
||||
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
|
||||
{
|
||||
TileTurbine tile = (TileTurbine) t;
|
||||
TileMechanicalTurbine tile = (TileMechanicalTurbine) t;
|
||||
|
||||
if (tile.getMultiBlock().isPrimary())
|
||||
{
|
||||
|
@ -32,7 +32,7 @@ public class RenderWaterTurbine extends TileEntitySpecialRenderer implements ISi
|
|||
GL11.glPushMatrix();
|
||||
|
||||
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection());
|
||||
GL11.glRotatef((float) Math.toDegrees(tile.rotation), 0, 1, 0);
|
||||
GL11.glRotatef((float) Math.toDegrees(tile.renderAngle), 0, 1, 0);
|
||||
|
||||
if (tile.getDirection().offsetY != 0)
|
||||
renderWaterTurbine(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
|
||||
|
|
|
@ -21,44 +21,53 @@ public class TileMechanicalTurbine extends TileTurbine implements INodeProvider
|
|||
protected double renderAngularVelocity;
|
||||
protected double renderAngle;
|
||||
|
||||
protected double prevAngularVelocity;
|
||||
|
||||
protected class TurbineNode extends MechanicalNode
|
||||
{
|
||||
public TurbineNode(INodeProvider parent)
|
||||
{
|
||||
super(parent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
if (source instanceof MechanicalNode && !(source instanceof TileMechanicalTurbine))
|
||||
{
|
||||
/**
|
||||
* Face to face stick connection.
|
||||
*/
|
||||
TileEntity sourceTile = position().translate(from).getTileEntity(getWorld());
|
||||
|
||||
if (sourceTile instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode sourceInstance = ((INodeProvider) sourceTile).getNode(MechanicalNode.class, from.getOpposite());
|
||||
return sourceInstance == source && from == getDirection().getOpposite();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inverseRotation(ForgeDirection dir, IMechanicalNode with)
|
||||
{
|
||||
return dir == getDirection().getOpposite();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRatio(ForgeDirection dir, IMechanicalNode with)
|
||||
{
|
||||
return getMultiBlock().isConstructed() ? multiBlockRadius - 0.5f : 0.5f;
|
||||
}
|
||||
};
|
||||
|
||||
public TileMechanicalTurbine()
|
||||
{
|
||||
super();
|
||||
energy = new EnergyStorageHandler(0);
|
||||
mechanicalNode = new MechanicalNode(this)
|
||||
{
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
if (source instanceof MechanicalNode && !(source instanceof TileMechanicalTurbine))
|
||||
{
|
||||
/**
|
||||
* Face to face stick connection.
|
||||
*/
|
||||
TileEntity sourceTile = position().translate(from).getTileEntity(getWorld());
|
||||
|
||||
if (sourceTile instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode sourceInstance = ((INodeProvider) sourceTile).getNode(MechanicalNode.class, from.getOpposite());
|
||||
return sourceInstance == source && from == getDirection().getOpposite();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inverseRotation(ForgeDirection dir, IMechanicalNode with)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRatio(ForgeDirection dir, IMechanicalNode with)
|
||||
{
|
||||
return getMultiBlock().isConstructed() ? multiBlockRadius - 0.5f : 0.5f;
|
||||
}
|
||||
};
|
||||
mechanicalNode = new TurbineNode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,6 +90,12 @@ public class TileMechanicalTurbine extends TileTurbine implements INodeProvider
|
|||
if (!worldObj.isRemote)
|
||||
{
|
||||
renderAngularVelocity = (double) mechanicalNode.angularVelocity;
|
||||
|
||||
if (renderAngularVelocity != prevAngularVelocity)
|
||||
{
|
||||
prevAngularVelocity = renderAngularVelocity;
|
||||
sendPowerUpdate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -99,12 +114,12 @@ public class TileMechanicalTurbine extends TileTurbine implements INodeProvider
|
|||
if (!worldObj.isRemote)
|
||||
{
|
||||
if (mechanicalNode.torque < 0)
|
||||
torque = -torque;
|
||||
torque = -Math.abs(torque);
|
||||
|
||||
if (mechanicalNode.angularVelocity < 0)
|
||||
angularVelocity = -angularVelocity;
|
||||
angularVelocity = -Math.abs(angularVelocity);
|
||||
|
||||
mechanicalNode.apply((torque - mechanicalNode.torque) / 10, (angularVelocity - mechanicalNode.angularVelocity) / 10);
|
||||
mechanicalNode.apply((torque - mechanicalNode.getTorque()) / 10, (angularVelocity - mechanicalNode.getAngularVelocity()) / 10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,8 +2,12 @@ package resonantinduction.mechanical.energy.turbine;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import resonantinduction.core.grid.INodeProvider;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
import resonantinduction.mechanical.energy.turbine.TileMechanicalTurbine.TurbineNode;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFluid;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -23,41 +27,70 @@ public class TileWaterTurbine extends TileMechanicalTurbine
|
|||
|
||||
public TileWaterTurbine()
|
||||
{
|
||||
maxPower = 200;
|
||||
torque = defaultTorque;
|
||||
mechanicalNode = new TurbineNode(this)
|
||||
{
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
if (source instanceof MechanicalNode && !(source instanceof TileMechanicalTurbine))
|
||||
{
|
||||
/**
|
||||
* Face to face stick connection.
|
||||
*/
|
||||
TileEntity sourceTile = position().translate(from).getTileEntity(getWorld());
|
||||
|
||||
if (sourceTile instanceof INodeProvider)
|
||||
{
|
||||
MechanicalNode sourceInstance = ((INodeProvider) sourceTile).getNode(MechanicalNode.class, from.getOpposite());
|
||||
return sourceInstance == source && (from == getDirection().getOpposite() || from == getDirection());
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if (getMultiBlock().isConstructed())
|
||||
torque = (long) (defaultTorque / (9f / multiBlockRadius));
|
||||
torque = (long) (defaultTorque / (1d / multiBlockRadius));
|
||||
else
|
||||
torque = defaultTorque / 12;
|
||||
torque = defaultTorque / 20;
|
||||
|
||||
/**
|
||||
* If this is a horizontal turbine.
|
||||
*/
|
||||
if (getDirection().offsetY != 0)
|
||||
{
|
||||
maxPower = 10000;
|
||||
|
||||
if (powerTicks > 0)
|
||||
{
|
||||
getMultiBlock().get().power += getWaterPower();
|
||||
powerTicks--;
|
||||
}
|
||||
|
||||
int blockIDAbove = worldObj.getBlockId(xCoord, yCoord + 1, zCoord);
|
||||
int metadata = worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord);
|
||||
|
||||
if (blockIDAbove == Block.waterStill.blockID && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && metadata == 0)
|
||||
if (ticks % 20 == 0)
|
||||
{
|
||||
powerTicks = 20;
|
||||
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord);
|
||||
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Block.waterStill.blockID);
|
||||
int blockIDAbove = worldObj.getBlockId(xCoord, yCoord + 1, zCoord);
|
||||
int metadata = worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord);
|
||||
boolean isWater = (blockIDAbove == Block.waterStill.blockID || blockIDAbove == Block.waterMoving.blockID);
|
||||
|
||||
if (isWater && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && metadata == 0)
|
||||
{
|
||||
powerTicks = 20;
|
||||
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord);
|
||||
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Block.waterMoving.blockID);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
maxPower = 3000;
|
||||
|
||||
int checkX = xCoord;
|
||||
int checkY = yCoord - 1;
|
||||
int checkZ = zCoord;
|
||||
|
@ -72,7 +105,7 @@ public class TileWaterTurbine extends TileMechanicalTurbine
|
|||
Vector3 vector = new Vector3((Vec3) m.invoke(Block.waterMoving, worldObj, xCoord, checkY, checkZ));
|
||||
ForgeDirection dir = getDirection();
|
||||
|
||||
if ((dir.offsetZ > 0 && vector.x > 0) || (dir.offsetZ < 0 && vector.x < 0) || (dir.offsetX > 0 && vector.z > 0) || (dir.offsetX < 0 && vector.z < 0))
|
||||
if ((dir.offsetZ > 0 && vector.x < 0) || (dir.offsetZ < 0 && vector.x > 0) || (dir.offsetX > 0 && vector.z > 0) || (dir.offsetX < 0 && vector.z < 0))
|
||||
torque = -torque;
|
||||
|
||||
if (getDirection().offsetX != 0)
|
||||
|
|
|
@ -66,7 +66,7 @@ public class TileWindTurbine extends TileMechanicalTurbine
|
|||
}
|
||||
|
||||
if (getMultiBlock().isConstructed())
|
||||
torque = (long) (defaultTorque / (.52f / multiBlockRadius));
|
||||
torque = (long) (defaultTorque / (9d / multiBlockRadius));
|
||||
else
|
||||
torque = defaultTorque / 12;
|
||||
|
||||
|
@ -114,9 +114,9 @@ public class TileWindTurbine extends TileMechanicalTurbine
|
|||
|
||||
for (Entity entity : entities)
|
||||
{
|
||||
entity.motionX += dir.offsetX * velocity / 20;
|
||||
entity.motionY += dir.offsetY * velocity / 20;
|
||||
entity.motionZ += dir.offsetZ * velocity / 20;
|
||||
entity.motionX += dir.offsetX * velocity / 20 * 0.3;
|
||||
entity.motionY += dir.offsetY * velocity / 20 * 0.3;
|
||||
entity.motionZ += dir.offsetZ * velocity / 20 * 0.3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue