Fixed turbine's mech node not updating

This commit is contained in:
Robert S 2014-06-07 07:11:10 -04:00
parent 72b268611a
commit 63918f16b3

View file

@ -1,151 +1,108 @@
package resonantinduction.mechanical.energy.turbine;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import resonant.api.grid.INode;
import resonant.api.grid.INodeProvider;
import resonant.lib.network.Synced;
import resonant.lib.network.Synced.SyncedInput;
import resonant.lib.network.Synced.SyncedOutput;
import resonantinduction.core.interfaces.IMechanicalNode;
import resonantinduction.mechanical.energy.grid.MechanicalNode;
//TODO: MC 1.7, merge turbines in.
public class TileMechanicalTurbine extends TileTurbineBase implements INodeProvider
{
protected MechanicalNode mechanicalNode;
@Synced(1)
protected double renderAngularVelocity;
protected double renderAngle;
protected MechanicalNode mechanicalNode;
@Synced(1)
protected double renderAngularVelocity;
protected double renderAngle;
protected double prevAngularVelocity;
protected double prevAngularVelocity;
protected class TurbineNode extends MechanicalNode
{
public TurbineNode(INodeProvider parent)
{
super(parent);
}
public TileMechanicalTurbine()
{
super();
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());
@Override
public void initiate()
{
mechanicalNode.reconstruct();
super.initiate();
}
if (sourceTile instanceof INodeProvider)
{
MechanicalNode sourceInstance = (MechanicalNode) ((INodeProvider) sourceTile).getNode(MechanicalNode.class, from.getOpposite());
return sourceInstance == source && from == getDirection().getOpposite();
}
}
@Override
public void invalidate()
{
mechanicalNode.deconstruct();
super.invalidate();
}
return false;
}
@Override
public void updateEntity()
{
mechanicalNode.update(0.05f);
if (!worldObj.isRemote)
{
renderAngularVelocity = (double) mechanicalNode.angularVelocity;
@Override
public boolean inverseRotation(ForgeDirection dir, IMechanicalNode with)
{
return dir == getDirection().getOpposite();
}
if (renderAngularVelocity != prevAngularVelocity)
{
prevAngularVelocity = renderAngularVelocity;
sendPowerUpdate();
}
}
else
{
renderAngle = (renderAngle + renderAngularVelocity / 20) % (Math.PI * 2);
@Override
public float getRatio(ForgeDirection dir, IMechanicalNode with)
{
return getMultiBlock().isConstructed() ? multiBlockRadius - 0.5f : 0.5f;
}
};
// TODO: Make this neater
onProduce();
}
public TileMechanicalTurbine()
{
super();
mechanicalNode = new TurbineNode(this);
}
super.updateEntity();
}
@Override
public void initiate()
{
mechanicalNode.reconstruct();
super.initiate();
}
@Override
public void onProduce()
{
if (!worldObj.isRemote)
{
if (mechanicalNode.torque < 0)
torque = -Math.abs(torque);
@Override
public void invalidate()
{
mechanicalNode.deconstruct();
super.invalidate();
}
if (mechanicalNode.angularVelocity < 0)
angularVelocity = -Math.abs(angularVelocity);
@Override
public void updateEntity()
{
if (!worldObj.isRemote)
{
renderAngularVelocity = (double) mechanicalNode.angularVelocity;
mechanicalNode.apply(this, (torque - mechanicalNode.getTorque()) / 10, (angularVelocity - mechanicalNode.getAngularSpeed()) / 10);
}
}
if (renderAngularVelocity != prevAngularVelocity)
{
prevAngularVelocity = renderAngularVelocity;
sendPowerUpdate();
}
}
else
{
renderAngle = (renderAngle + renderAngularVelocity / 20) % (Math.PI * 2);
@Override
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
{
if (nodeType.isAssignableFrom(mechanicalNode.getClass()))
return ((TileMechanicalTurbine) getMultiBlock().get()).mechanicalNode;
return null;
}
// TODO: Make this neater
onProduce();
}
@Override
@SyncedInput
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
tier = nbt.getInteger("tier");
mechanicalNode.load(nbt);
}
super.updateEntity();
}
@Override
public void onProduce()
{
if (!worldObj.isRemote)
{
if (mechanicalNode.torque < 0)
torque = -Math.abs(torque);
if (mechanicalNode.angularVelocity < 0)
angularVelocity = -Math.abs(angularVelocity);
mechanicalNode.apply(this, (torque - mechanicalNode.getTorque()) / 10, (angularVelocity - mechanicalNode.getAngularSpeed()) / 10);
}
}
@Override
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
{
if (nodeType.isAssignableFrom(mechanicalNode.getClass()))
return ((TileMechanicalTurbine) getMultiBlock().get()).mechanicalNode;
return null;
}
@Override
@SyncedInput
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
tier = nbt.getInteger("tier");
mechanicalNode.load(nbt);
}
/**
* Writes a tile entity to NBT.
*/
@Override
@SyncedOutput
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("tier", tier);
mechanicalNode.save(nbt);
}
/** Writes a tile entity to NBT. */
@Override
@SyncedOutput
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("tier", tier);
mechanicalNode.save(nbt);
}
}