Fixed water turbine packets
This commit is contained in:
parent
7e1778098c
commit
c8ed5fcfdc
3 changed files with 124 additions and 263 deletions
|
@ -0,0 +1,121 @@
|
|||
package resonantinduction.mechanical.turbine;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.api.mechanical.IMechanical;
|
||||
import resonantinduction.api.mechanical.IMechanicalNetwork;
|
||||
import resonantinduction.mechanical.gear.PartGearShaft;
|
||||
import resonantinduction.mechanical.network.MechanicalNetwork;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.prefab.turbine.TileTurbine;
|
||||
|
||||
public class TileMechanicalTurbine extends TileTurbine implements IMechanical
|
||||
{
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mechanical Methods
|
||||
*
|
||||
* @return The connections.
|
||||
*/
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
Object[] connections = new Object[6];
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).translate(dir).getTileEntity(worldObj);
|
||||
|
||||
if (tile instanceof IMechanical)
|
||||
{
|
||||
IMechanical mech = ((IMechanical) tile).getInstance(dir.getOpposite());
|
||||
|
||||
// Don't connect with shafts
|
||||
if (mech != null && !(mech instanceof PartGearShaft) && canConnect(dir, this) && mech.canConnect(dir.getOpposite(), this))
|
||||
{
|
||||
connections[dir.ordinal()] = mech;
|
||||
getNetwork().merge(mech.getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
|
||||
private IMechanicalNetwork network;
|
||||
|
||||
@Override
|
||||
public IMechanicalNetwork getNetwork()
|
||||
{
|
||||
if (this.network == null)
|
||||
{
|
||||
this.network = new MechanicalNetwork();
|
||||
this.network.addConnector(this);
|
||||
}
|
||||
return this.network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(IMechanicalNetwork network)
|
||||
{
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRatio(ForgeDirection dir, Object source)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAngularVelocity()
|
||||
{
|
||||
return angularVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngularVelocity(float velocity)
|
||||
{
|
||||
this.angularVelocity = velocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTorque(long torque)
|
||||
{
|
||||
this.torque = torque;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inverseRotation(ForgeDirection dir, IMechanical with)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMechanical getInstance(ForgeDirection dir)
|
||||
{
|
||||
return (IMechanical) getMultiBlock().get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
/**
|
||||
* Face to face stick connection.
|
||||
*/
|
||||
TileEntity sourceTile = getPosition().translate(from).getTileEntity(getWorld());
|
||||
|
||||
if (sourceTile instanceof IMechanical)
|
||||
{
|
||||
IMechanical sourceInstance = ((IMechanical) sourceTile).getInstance(from.getOpposite());
|
||||
return sourceInstance == source && from == getDirection().getOpposite();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ import calclavia.lib.prefab.turbine.TileTurbine;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileWaterTurbine extends TileTurbine implements IMechanical
|
||||
public class TileWaterTurbine extends TileMechanicalTurbine
|
||||
{
|
||||
public TileWaterTurbine()
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ public class TileWaterTurbine extends TileTurbine implements IMechanical
|
|||
{
|
||||
int blockIDAbove = worldObj.getBlockId(xCoord, yCoord + 1, zCoord);
|
||||
|
||||
if (blockIDAbove == Block.waterStill.blockID || worldObj.isAirBlock(xCoord, yCoord - 1, zCoord))
|
||||
if (blockIDAbove == Block.waterStill.blockID && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord))
|
||||
{
|
||||
getMultiBlock().get().power += getWaterPower();
|
||||
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord);
|
||||
|
@ -73,138 +73,4 @@ public class TileWaterTurbine extends TileTurbine implements IMechanical
|
|||
{
|
||||
return 1 * 10 * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProduce()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound()
|
||||
{
|
||||
if (this.ticks % 18 == 0)
|
||||
{
|
||||
// this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord,
|
||||
// "atomicscience:turbine", 0.6f, (float) (0.7f + (0.2 * ((double) this.power / (double)
|
||||
// this.getMaxPower()))));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Packet getDescriptionPacket()
|
||||
{
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
writeToNBT(nbt);
|
||||
return ResonantInduction.PACKET_TILE.getPacket(this, (byte) 1, nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPowerUpdate()
|
||||
{
|
||||
PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacket(this, (byte) 2, angularVelocity), this.worldObj, new Vector3(this), 25);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mechanical Methods
|
||||
*
|
||||
* @return The connections.
|
||||
*/
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
Object[] connections = new Object[6];
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).translate(dir).getTileEntity(worldObj);
|
||||
|
||||
if (tile instanceof IMechanical)
|
||||
{
|
||||
IMechanical mech = ((IMechanical) tile).getInstance(dir.getOpposite());
|
||||
|
||||
// Don't connect with shafts
|
||||
if (mech != null && !(mech instanceof PartGearShaft) && canConnect(dir, this) && mech.canConnect(dir.getOpposite(), this))
|
||||
{
|
||||
connections[dir.ordinal()] = mech;
|
||||
getNetwork().merge(mech.getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
|
||||
private IMechanicalNetwork network;
|
||||
|
||||
@Override
|
||||
public IMechanicalNetwork getNetwork()
|
||||
{
|
||||
if (this.network == null)
|
||||
{
|
||||
this.network = new MechanicalNetwork();
|
||||
this.network.addConnector(this);
|
||||
}
|
||||
return this.network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(IMechanicalNetwork network)
|
||||
{
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAngularVelocity()
|
||||
{
|
||||
return angularVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngularVelocity(float velocity)
|
||||
{
|
||||
this.angularVelocity = velocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTorque()
|
||||
{
|
||||
return torque;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTorque(long torque)
|
||||
{
|
||||
this.torque = torque;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRatio(ForgeDirection dir, Object source)
|
||||
{
|
||||
return getMultiBlock().isConstructed() ? 1.5f : 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inverseRotation(ForgeDirection dir, IMechanical with)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMechanical getInstance(ForgeDirection dir)
|
||||
{
|
||||
return (IMechanical) getMultiBlock().get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object sourcen)
|
||||
{
|
||||
return from == getDirection().getOpposite();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,9 @@
|
|||
package resonantinduction.mechanical.turbine;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.biome.BiomeGenOcean;
|
||||
import net.minecraft.world.biome.BiomeGenPlains;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.api.mechanical.IMechanical;
|
||||
import resonantinduction.api.mechanical.IMechanicalNetwork;
|
||||
import resonantinduction.mechanical.gear.PartGearShaft;
|
||||
import resonantinduction.mechanical.network.MechanicalNetwork;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import calclavia.lib.prefab.turbine.TileTurbine;
|
||||
|
||||
/**
|
||||
* The vertical wind turbine collects airflow.
|
||||
|
@ -19,7 +12,7 @@ import calclavia.lib.prefab.turbine.TileTurbine;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileWindTurbine extends TileTurbine implements IMechanical
|
||||
public class TileWindTurbine extends TileMechanicalTurbine
|
||||
{
|
||||
@Override
|
||||
public void invalidate()
|
||||
|
@ -52,12 +45,6 @@ public class TileWindTurbine extends TileTurbine implements IMechanical
|
|||
super.updateEntity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection direction)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getWindPower()
|
||||
{
|
||||
BiomeGenBase biome = worldObj.getBiomeGenForCoords(xCoord, zCoord);
|
||||
|
@ -68,117 +55,4 @@ public class TileWindTurbine extends TileTurbine implements IMechanical
|
|||
|
||||
return (long) (((((float) yCoord + 4) / 256) * maxPower) * (hasBonus ? 2 : 1)) * (worldObj.isRaining() ? 2 : 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void playSound()
|
||||
{
|
||||
if (this.ticks % 18 == 0)
|
||||
{
|
||||
// this.worldObj.playSoundEffect(this.xCoord, this.yCoord, this.zCoord,
|
||||
// "atomicscience:turbine", 0.6f, (float) (0.7f + (0.2 * ((double) this.power / (double)
|
||||
// this.getMaxPower()))));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Mechanical Methods
|
||||
*
|
||||
* @return The connections.
|
||||
*/
|
||||
@Override
|
||||
public Object[] getConnections()
|
||||
{
|
||||
Object[] connections = new Object[6];
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).translate(dir).getTileEntity(worldObj);
|
||||
|
||||
if (tile instanceof IMechanical)
|
||||
{
|
||||
IMechanical mech = ((IMechanical) tile).getInstance(dir.getOpposite());
|
||||
|
||||
// Don't connect with shafts
|
||||
if (mech != null && !(mech instanceof PartGearShaft) && canConnect(dir, this) && mech.canConnect(dir.getOpposite(), this))
|
||||
{
|
||||
connections[dir.ordinal()] = mech;
|
||||
getNetwork().merge(mech.getNetwork());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return connections;
|
||||
}
|
||||
|
||||
private IMechanicalNetwork network;
|
||||
|
||||
@Override
|
||||
public IMechanicalNetwork getNetwork()
|
||||
{
|
||||
if (this.network == null)
|
||||
{
|
||||
this.network = new MechanicalNetwork();
|
||||
this.network.addConnector(this);
|
||||
}
|
||||
return this.network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNetwork(IMechanicalNetwork network)
|
||||
{
|
||||
this.network = network;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRatio(ForgeDirection dir, Object source)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAngularVelocity()
|
||||
{
|
||||
return angularVelocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAngularVelocity(float velocity)
|
||||
{
|
||||
this.angularVelocity = velocity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTorque(long torque)
|
||||
{
|
||||
this.torque = torque;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean inverseRotation(ForgeDirection dir, IMechanical with)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMechanical getInstance(ForgeDirection dir)
|
||||
{
|
||||
return (IMechanical) getMultiBlock().get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
/**
|
||||
* Face to face stick connection.
|
||||
*/
|
||||
TileEntity sourceTile = getPosition().translate(from).getTileEntity(getWorld());
|
||||
|
||||
if (sourceTile instanceof IMechanical)
|
||||
{
|
||||
IMechanical sourceInstance = ((IMechanical) sourceTile).getInstance(from.getOpposite());
|
||||
return sourceInstance == source && from == getDirection().getOpposite();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue