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