Fixed gear shaft rendering rotation

This commit is contained in:
Calclavia 2014-01-28 14:11:03 +08:00
parent 17108484f9
commit 05b903f07b
7 changed files with 45 additions and 6 deletions

View file

@ -138,6 +138,7 @@ public class Mechanical
{ {
// Add recipes // Add recipes
GameRegistry.addRecipe(new ShapedOreRecipe(itemGear, "SWS", "W W", "SWS", 'W', "plankWood", 'S', Item.stick)); GameRegistry.addRecipe(new ShapedOreRecipe(itemGear, "SWS", "W W", "SWS", 'W', "plankWood", 'S', Item.stick));
GameRegistry.addRecipe(new ShapedOreRecipe(itemGearShaft, "S", "S", "S", 'S', Item.stick));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 4), "III", "GGG", 'I', Item.ingotIron, 'G', itemGear)); GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(blockConveyorBelt, 4), "III", "GGG", 'I', Item.ingotIron, 'G', itemGear));
GameRegistry.addRecipe(new ShapedOreRecipe(blockManipulator, "SSS", "SRS", "SCS", 'S', Item.ingotIron, 'C', blockConveyorBelt, 'R', Block.blockRedstone)); GameRegistry.addRecipe(new ShapedOreRecipe(blockManipulator, "SSS", "SRS", "SCS", 'S', Item.ingotIron, 'C', blockConveyorBelt, 'R', Block.blockRedstone));
GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, "SWS", "SRS", "SWS", 'S', Item.ingotIron, 'W', UniversalRecipe.WIRE.get())); GameRegistry.addRecipe(new ShapedOreRecipe(blockDetector, "SWS", "SRS", "SWS", 'S', Item.ingotIron, 'W', UniversalRecipe.WIRE.get()));

View file

@ -459,4 +459,10 @@ public class PartGear extends PartMechanical implements IMechanical, IMultiBlock
{ {
return FaceMicroClass.aBounds()[0x10 | this.placementSide.ordinal()]; return FaceMicroClass.aBounds()[0x10 | this.placementSide.ordinal()];
} }
@Override
public boolean inverseRotation(ForgeDirection dir)
{
return dir != placementSide.getOpposite();
}
} }

View file

@ -149,4 +149,10 @@ public class PartGearShaft extends PartMechanical
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625); return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625);
} }
@Override
public boolean inverseRotation(ForgeDirection dir)
{
return false;
}
} }

View file

@ -1,14 +1,17 @@
package resonantinduction.mechanical.gear; package resonantinduction.mechanical.gear;
import static org.lwjgl.opengl.GL11.glRotatef;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.AdvancedModelLoader;
import net.minecraftforge.client.model.IModelCustom; import net.minecraftforge.client.model.IModelCustom;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference; import resonantinduction.core.Reference;
import calclavia.lib.render.RenderUtility; import calclavia.lib.render.RenderUtility;
import calclavia.lib.utility.WorldUtility;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -30,10 +33,22 @@ public class RenderGearShaft
GL11.glPushMatrix(); GL11.glPushMatrix();
// Center the model first. // Center the model first.
GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f); GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f);
GL11.glTranslatef(0, 0.5f, 0);
GL11.glPushMatrix(); GL11.glPushMatrix();
RenderUtility.rotateFaceBlockToSide(part.placementSide); ForgeDirection dir = part.placementSide;
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal());
switch (dir)
{
default:
break;
case NORTH:
glRotatef(90, 1, 0, 0);
break;
case WEST:
glRotatef(90, 0, 0, 1);
break;
}
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0); GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);

View file

@ -21,6 +21,8 @@ public interface IMechanical extends IConnector<IMechanicalNetwork>
public float getRatio(ForgeDirection dir); public float getRatio(ForgeDirection dir);
public boolean inverseRotation(ForgeDirection dir);
public IMechanical getInstance(ForgeDirection dir); public IMechanical getInstance(ForgeDirection dir);
/** /**

View file

@ -80,16 +80,19 @@ public class MechanicalNetwork extends Network<IMechanicalNetwork, IMechanical>
float ratio = adjacentMech.getRatio(dir) / mechanical.getRatio(dir.getOpposite()); float ratio = adjacentMech.getRatio(dir) / mechanical.getRatio(dir.getOpposite());
long torque = mechanical.getTorque(); long torque = mechanical.getTorque();
if (Math.abs(torque - adjacentMech.getTorque() / ratio * ACCELERATION) < Math.abs(adjacentMech.getTorque() / ratio)) boolean inverseRotation = mechanical.inverseRotation(dir) && adjacentMech.inverseRotation(dir.getOpposite());
int inversion = inverseRotation ? -1 : 1;
if (Math.abs(torque + inversion * (adjacentMech.getTorque() / ratio * ACCELERATION)) < Math.abs(adjacentMech.getTorque() / ratio))
{ {
mechanical.setTorque((long) (torque - (adjacentMech.getTorque() / ratio * ACCELERATION))); mechanical.setTorque((long) (torque + inversion * ((adjacentMech.getTorque() / ratio * ACCELERATION))));
} }
float velocity = mechanical.getAngularVelocity(); float velocity = mechanical.getAngularVelocity();
if (Math.abs(velocity - adjacentMech.getAngularVelocity() * ratio * ACCELERATION) < Math.abs(adjacentMech.getAngularVelocity() * ratio)) if (Math.abs(velocity + inversion * (adjacentMech.getAngularVelocity() * ratio * ACCELERATION)) < Math.abs(adjacentMech.getAngularVelocity() * ratio))
{ {
mechanical.setAngularVelocity(velocity - (adjacentMech.getAngularVelocity() * ratio * ACCELERATION)); mechanical.setAngularVelocity(velocity + inversion * ((adjacentMech.getAngularVelocity() * ratio * ACCELERATION)));
} }
} }
} }

View file

@ -138,4 +138,10 @@ public abstract class TileMechanical extends TileAdvanced implements IMechanical
{ {
return new Vector3(this); return new Vector3(this);
} }
@Override
public boolean inverseRotation(ForgeDirection dir)
{
return true;
}
} }