Merged TileTurbine & TileMechanicalTurbine
This commit is contained in:
parent
63918f16b3
commit
8a62bdb2e3
11 changed files with 81 additions and 147 deletions
|
@ -84,6 +84,11 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj, IVectorWorld
|
|||
return 0.5;
|
||||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
update(0.05f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(float deltaTime)
|
||||
{
|
||||
|
|
|
@ -26,8 +26,8 @@ public class BlockMechanicalTurbine extends BlockTurbineBase
|
|||
{
|
||||
TileEntity tile = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tile instanceof TileTurbineBase)
|
||||
return ((TileTurbineBase) tile).tier;
|
||||
if (tile instanceof TileTurbine)
|
||||
return ((TileTurbine) tile).tier;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -54,9 +54,9 @@ public class BlockMechanicalTurbine extends BlockTurbineBase
|
|||
super.onBlockPlacedBy(world, x, y, z, entityLiving, itemStack);
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileMechanicalTurbine)
|
||||
if (tileEntity instanceof TileTurbine)
|
||||
{
|
||||
((TileMechanicalTurbine) tileEntity).tier = itemStack.getItemDamage();
|
||||
((TileTurbine) tileEntity).tier = itemStack.getItemDamage();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,11 +67,11 @@ public class BlockMechanicalTurbine extends BlockTurbineBase
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileTurbineBase)
|
||||
if (tileEntity instanceof TileTurbine)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
TileMechanicalTurbine tile = (TileMechanicalTurbine) tileEntity;
|
||||
TileTurbine tile = (TileTurbine) tileEntity;
|
||||
tile.mechanicalNode.torque = -tile.mechanicalNode.torque;
|
||||
tile.mechanicalNode.angularVelocity = -tile.mechanicalNode.angularVelocity;
|
||||
}
|
||||
|
@ -87,11 +87,11 @@ public class BlockMechanicalTurbine extends BlockTurbineBase
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileTurbineBase)
|
||||
if (tileEntity instanceof TileTurbine)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
TileTurbineBase tile = (TileTurbineBase) tileEntity;
|
||||
TileTurbine tile = (TileTurbine) tileEntity;
|
||||
|
||||
if (tile.getMultiBlock().isConstructed())
|
||||
{
|
||||
|
@ -126,23 +126,23 @@ public class BlockMechanicalTurbine extends BlockTurbineBase
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (!world.isRemote && tileEntity instanceof TileTurbineBase)
|
||||
if (!world.isRemote && tileEntity instanceof TileTurbine)
|
||||
{
|
||||
Set<TileTurbineBase> toFlip = new HashSet<TileTurbineBase>();
|
||||
Set<TileTurbine> toFlip = new HashSet<TileTurbine>();
|
||||
|
||||
if (!((TileTurbineBase) tileEntity).getMultiBlock().isConstructed())
|
||||
if (!((TileTurbine) tileEntity).getMultiBlock().isConstructed())
|
||||
{
|
||||
toFlip.add((TileTurbineBase) tileEntity);
|
||||
toFlip.add((TileTurbine) tileEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
Set<TileTurbineBase> str = ((TileTurbineBase) tileEntity).getMultiBlock().getPrimary().getMultiBlock().getStructure();
|
||||
Set<TileTurbine> str = ((TileTurbine) tileEntity).getMultiBlock().getPrimary().getMultiBlock().getStructure();
|
||||
|
||||
if (str != null)
|
||||
toFlip.addAll(str);
|
||||
}
|
||||
|
||||
for (TileTurbineBase turbine : toFlip)
|
||||
for (TileTurbine turbine : toFlip)
|
||||
{
|
||||
if (side == turbine.getDirection().ordinal())
|
||||
world.setBlockMetadataWithNotify(turbine.xCoord, turbine.yCoord, turbine.zCoord, side ^ 1, 3);
|
||||
|
|
|
@ -22,11 +22,11 @@ public class BlockTurbineBase extends BlockRotatable
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileTurbineBase)
|
||||
if (tileEntity instanceof TileTurbine)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
return ((TileTurbineBase) tileEntity).getMultiBlock().toggleConstruct();
|
||||
return ((TileTurbine) tileEntity).getMultiBlock().toggleConstruct();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -40,9 +40,9 @@ public class BlockTurbineBase extends BlockRotatable
|
|||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity instanceof TileTurbineBase)
|
||||
if (tileEntity instanceof TileTurbine)
|
||||
{
|
||||
((TileTurbineBase) tileEntity).getMultiBlock().deconstruct();
|
||||
((TileTurbine) tileEntity).getMultiBlock().deconstruct();
|
||||
}
|
||||
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
|
|
|
@ -22,7 +22,7 @@ public class RenderWaterTurbine extends TileEntitySpecialRenderer implements ISi
|
|||
@Override
|
||||
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
|
||||
{
|
||||
TileMechanicalTurbine tile = (TileMechanicalTurbine) t;
|
||||
TileTurbine tile = (TileTurbine) t;
|
||||
|
||||
if (tile.getMultiBlock().isPrimary())
|
||||
{
|
||||
|
@ -31,7 +31,7 @@ public class RenderWaterTurbine extends TileEntitySpecialRenderer implements ISi
|
|||
GL11.glPushMatrix();
|
||||
|
||||
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection());
|
||||
GL11.glRotatef((float) Math.toDegrees(tile.renderAngle), 0, 1, 0);
|
||||
GL11.glRotatef((float) Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0);
|
||||
|
||||
if (tile.getDirection().offsetY != 0)
|
||||
renderWaterTurbine(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
|
||||
|
|
|
@ -22,7 +22,7 @@ public class RenderWindTurbine extends TileEntitySpecialRenderer implements ISim
|
|||
@Override
|
||||
public void renderTileEntityAt(TileEntity t, double x, double y, double z, float f)
|
||||
{
|
||||
TileMechanicalTurbine tile = (TileMechanicalTurbine) t;
|
||||
TileTurbine tile = (TileTurbine) t;
|
||||
|
||||
if (tile.getMultiBlock().isPrimary())
|
||||
{
|
||||
|
@ -33,7 +33,7 @@ public class RenderWindTurbine extends TileEntitySpecialRenderer implements ISim
|
|||
RenderUtility.rotateBlockBasedOnDirectionUp(tile.getDirection());
|
||||
|
||||
GL11.glTranslatef(0, -0.35f, 0);
|
||||
GL11.glRotatef((float) Math.toDegrees(tile.renderAngle), 0, 1, 0);
|
||||
GL11.glRotatef((float) Math.toDegrees(tile.mechanicalNode.renderAngle), 0, 1, 0);
|
||||
|
||||
render(tile.tier, tile.multiBlockRadius, tile.getMultiBlock().isConstructed());
|
||||
|
||||
|
|
|
@ -1,108 +0,0 @@
|
|||
package resonantinduction.mechanical.energy.turbine;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
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.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 double prevAngularVelocity;
|
||||
|
||||
public TileMechanicalTurbine()
|
||||
{
|
||||
super();
|
||||
mechanicalNode = new TurbineNode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
mechanicalNode.reconstruct();
|
||||
super.initiate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
mechanicalNode.deconstruct();
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
mechanicalNode.update(0.05f);
|
||||
if (!worldObj.isRemote)
|
||||
{
|
||||
renderAngularVelocity = (double) mechanicalNode.angularVelocity;
|
||||
|
||||
if (renderAngularVelocity != prevAngularVelocity)
|
||||
{
|
||||
prevAngularVelocity = renderAngularVelocity;
|
||||
sendPowerUpdate();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
renderAngle = (renderAngle + renderAngularVelocity / 20) % (Math.PI * 2);
|
||||
|
||||
// TODO: Make this neater
|
||||
onProduce();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -9,6 +9,8 @@ import net.minecraft.network.packet.Packet;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonant.api.grid.INode;
|
||||
import resonant.api.grid.INodeProvider;
|
||||
import resonant.core.ResonantEngine;
|
||||
import resonant.lib.References;
|
||||
import resonant.lib.content.module.TileBase;
|
||||
|
@ -16,12 +18,13 @@ import resonant.lib.multiblock.IMultiBlockStructure;
|
|||
import resonant.lib.network.Synced;
|
||||
import resonant.lib.network.Synced.SyncedInput;
|
||||
import resonant.lib.network.Synced.SyncedOutput;
|
||||
import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/** Reduced version of the main turbine class */
|
||||
public abstract class TileTurbineBase extends TileBase implements IMultiBlockStructure<TileTurbineBase>
|
||||
public class TileTurbine extends TileBase implements IMultiBlockStructure<TileTurbine>, INodeProvider
|
||||
{
|
||||
/** Radius of large turbine? */
|
||||
public int multiBlockRadius = 1;
|
||||
|
@ -44,9 +47,12 @@ public abstract class TileTurbineBase extends TileBase implements IMultiBlockStr
|
|||
@Synced
|
||||
public int tier = 0;
|
||||
|
||||
public TileTurbineBase()
|
||||
protected MechanicalNode mechanicalNode;
|
||||
|
||||
public TileTurbine()
|
||||
{
|
||||
super(Material.wood);
|
||||
mechanicalNode = new TurbineNode(this);
|
||||
}
|
||||
|
||||
public ForgeDirection getDirection()
|
||||
|
@ -57,14 +63,15 @@ public abstract class TileTurbineBase extends TileBase implements IMultiBlockStr
|
|||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
super.initiate();
|
||||
mechanicalNode.reconstruct();
|
||||
super.initiate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
mechanicalNode.update();
|
||||
getMultiBlock().update();
|
||||
|
||||
if (getMultiBlock().isPrimary())
|
||||
|
@ -112,8 +119,19 @@ public abstract class TileTurbineBase extends TileBase implements IMultiBlockStr
|
|||
return (int) (((multiBlockRadius + 0.5) * 2) * ((multiBlockRadius + 0.5) * 2));
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
public void playSound()
|
||||
|
@ -139,6 +157,8 @@ public abstract class TileTurbineBase extends TileBase implements IMultiBlockStr
|
|||
{
|
||||
super.readFromNBT(nbt);
|
||||
multiBlockRadius = nbt.getInteger("multiBlockRadius");
|
||||
tier = nbt.getInteger("tier");
|
||||
mechanicalNode.load(nbt);
|
||||
getMultiBlock().load(nbt);
|
||||
}
|
||||
|
||||
|
@ -149,6 +169,8 @@ public abstract class TileTurbineBase extends TileBase implements IMultiBlockStr
|
|||
{
|
||||
super.writeToNBT(nbt);
|
||||
nbt.setInteger("multiBlockRadius", multiBlockRadius);
|
||||
nbt.setInteger("tier", tier);
|
||||
mechanicalNode.save(nbt);
|
||||
getMultiBlock().save(nbt);
|
||||
}
|
||||
|
||||
|
@ -214,4 +236,19 @@ public abstract class TileTurbineBase extends TileBase implements IMultiBlockStr
|
|||
return worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
|
||||
{
|
||||
if (nodeType.isAssignableFrom(mechanicalNode.getClass()))
|
||||
return ((TileTurbine) getMultiBlock().get()).mechanicalNode;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
mechanicalNode.deconstruct();
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
}
|
|
@ -21,7 +21,7 @@ import cpw.mods.fml.relauncher.ReflectionHelper;
|
|||
* @author Calclavia
|
||||
*
|
||||
*/
|
||||
public class TileWaterTurbine extends TileMechanicalTurbine
|
||||
public class TileWaterTurbine extends TileTurbine
|
||||
{
|
||||
public int powerTicks = 0;
|
||||
|
||||
|
@ -33,7 +33,7 @@ public class TileWaterTurbine extends TileMechanicalTurbine
|
|||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
if (source instanceof MechanicalNode && !(source instanceof TileMechanicalTurbine))
|
||||
if (source instanceof MechanicalNode && !(source instanceof TileTurbine))
|
||||
{
|
||||
/**
|
||||
* Face to face stick connection.
|
||||
|
|
|
@ -15,7 +15,7 @@ import universalelectricity.api.vector.Vector3;
|
|||
* power plants.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class TileWindTurbine extends TileMechanicalTurbine
|
||||
public class TileWindTurbine extends TileTurbine
|
||||
{
|
||||
private final byte[] openBlockCache = new byte[224];
|
||||
private int checkCount = 0;
|
||||
|
|
|
@ -4,22 +4,22 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import resonant.lib.multiblock.MultiBlockHandler;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
public class TurbineMBlockHandler extends MultiBlockHandler<TileTurbineBase>
|
||||
public class TurbineMBlockHandler extends MultiBlockHandler<TileTurbine>
|
||||
{
|
||||
public TurbineMBlockHandler(TileTurbineBase wrapper)
|
||||
public TurbineMBlockHandler(TileTurbine wrapper)
|
||||
{
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
public TileTurbineBase getWrapperAt(Vector3 position)
|
||||
public TileTurbine getWrapperAt(Vector3 position)
|
||||
{
|
||||
TileEntity tile = position.getTileEntity(self.getWorld());
|
||||
|
||||
if (tile != null && wrapperClass.isAssignableFrom(tile.getClass()))
|
||||
{
|
||||
if (((TileTurbineBase) tile).getDirection() == self.getDirection() && ((TileTurbineBase) tile).tier == self.tier)
|
||||
if (((TileTurbine) tile).getDirection() == self.getDirection() && ((TileTurbine) tile).tier == self.tier)
|
||||
{
|
||||
return (TileTurbineBase) tile;
|
||||
return (TileTurbine) tile;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,20 +11,20 @@ import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
|||
* @author Calclavia, Darkguardsman */
|
||||
public class TurbineNode extends MechanicalNode
|
||||
{
|
||||
public TurbineNode(TileMechanicalTurbine parent)
|
||||
public TurbineNode(TileTurbine tileTurbineBase)
|
||||
{
|
||||
super(parent);
|
||||
super(tileTurbineBase);
|
||||
}
|
||||
|
||||
public TileMechanicalTurbine turbine()
|
||||
public TileTurbine turbine()
|
||||
{
|
||||
return (TileMechanicalTurbine) getParent();
|
||||
return (TileTurbine) getParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnect(ForgeDirection from, Object source)
|
||||
{
|
||||
if (source instanceof MechanicalNode && !(source instanceof TileMechanicalTurbine))
|
||||
if (source instanceof MechanicalNode && !(source instanceof TileTurbine))
|
||||
{
|
||||
/** Face to face stick connection. */
|
||||
TileEntity sourceTile = position().translate(from).getTileEntity(turbine().getWorld());
|
||||
|
|
Loading…
Reference in a new issue