From 8a62bdb2e3da2e6b59966a6983e0e0fe46f3c526 Mon Sep 17 00:00:00 2001 From: Robert S Date: Sat, 7 Jun 2014 07:27:35 -0400 Subject: [PATCH] Merged TileTurbine & TileMechanicalTurbine --- .../energy/grid/MechanicalNode.java | 5 + .../turbine/BlockMechanicalTurbine.java | 28 ++--- .../energy/turbine/BlockTurbineBase.java | 8 +- .../energy/turbine/RenderWaterTurbine.java | 4 +- .../energy/turbine/RenderWindTurbine.java | 4 +- .../energy/turbine/TileMechanicalTurbine.java | 108 ------------------ ...{TileTurbineBase.java => TileTurbine.java} | 45 +++++++- .../energy/turbine/TileWaterTurbine.java | 4 +- .../energy/turbine/TileWindTurbine.java | 2 +- .../energy/turbine/TurbineMBlockHandler.java | 10 +- .../energy/turbine/TurbineNode.java | 10 +- 11 files changed, 81 insertions(+), 147 deletions(-) delete mode 100644 mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileMechanicalTurbine.java rename mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/{TileTurbineBase.java => TileTurbine.java} (79%) diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java index 5b53f22e..d9fcec37 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java @@ -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) { diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockMechanicalTurbine.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockMechanicalTurbine.java index 7839ba8f..458e44b1 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockMechanicalTurbine.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockMechanicalTurbine.java @@ -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 toFlip = new HashSet(); + Set toFlip = new HashSet(); - if (!((TileTurbineBase) tileEntity).getMultiBlock().isConstructed()) + if (!((TileTurbine) tileEntity).getMultiBlock().isConstructed()) { - toFlip.add((TileTurbineBase) tileEntity); + toFlip.add((TileTurbine) tileEntity); } else { - Set str = ((TileTurbineBase) tileEntity).getMultiBlock().getPrimary().getMultiBlock().getStructure(); + Set 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); diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockTurbineBase.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockTurbineBase.java index c12daf1d..3969a6cb 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockTurbineBase.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/BlockTurbineBase.java @@ -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); diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWaterTurbine.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWaterTurbine.java index 210fdbcf..e236c222 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWaterTurbine.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWaterTurbine.java @@ -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()); diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWindTurbine.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWindTurbine.java index b2f33264..e0b6f16f 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWindTurbine.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/RenderWindTurbine.java @@ -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()); diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileMechanicalTurbine.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileMechanicalTurbine.java deleted file mode 100644 index 4231c170..00000000 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileMechanicalTurbine.java +++ /dev/null @@ -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 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); - } -} diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileTurbineBase.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileTurbine.java similarity index 79% rename from mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileTurbineBase.java rename to mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileTurbine.java index 2ad38ce3..2ef81041 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileTurbineBase.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileTurbine.java @@ -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 +public class TileTurbine extends TileBase implements IMultiBlockStructure, 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 nodeType, ForgeDirection from) + { + if (nodeType.isAssignableFrom(mechanicalNode.getClass())) + return ((TileTurbine) getMultiBlock().get()).mechanicalNode; + return null; + } + + @Override + public void invalidate() + { + mechanicalNode.deconstruct(); + super.invalidate(); + } + } diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWaterTurbine.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWaterTurbine.java index d3221614..0c8503ad 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWaterTurbine.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWaterTurbine.java @@ -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. diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWindTurbine.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWindTurbine.java index a5371712..78ce235f 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWindTurbine.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TileWindTurbine.java @@ -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; diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineMBlockHandler.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineMBlockHandler.java index 3280f418..90ad13c6 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineMBlockHandler.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineMBlockHandler.java @@ -4,22 +4,22 @@ import net.minecraft.tileentity.TileEntity; import resonant.lib.multiblock.MultiBlockHandler; import universalelectricity.api.vector.Vector3; -public class TurbineMBlockHandler extends MultiBlockHandler +public class TurbineMBlockHandler extends MultiBlockHandler { - 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; } } diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineNode.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineNode.java index 4488f624..fe2bcc67 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineNode.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/turbine/TurbineNode.java @@ -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());