Gears now work omni-directional

This commit is contained in:
Calclavia 2014-01-16 21:32:30 +08:00
parent 4c4423e282
commit 102db7356d
5 changed files with 201 additions and 170 deletions

View file

@ -19,7 +19,7 @@ public class TileGenerator extends TileElectrical implements IMechanical
public TileGenerator()
{
energy = new EnergyStorageHandler(10000);
energy = new EnergyStorageHandler(10000, 100);
this.ioMap = 728;
}
@ -30,7 +30,7 @@ public class TileGenerator extends TileElectrical implements IMechanical
{
if (!isInversed)
{
this.energy.receiveEnergy(power, true);
this.power -= this.energy.receiveEnergy(power, true);
this.produce();
}
else
@ -51,6 +51,12 @@ public class TileGenerator extends TileElectrical implements IMechanical
this.power = (long) Math.abs(torque * speed);
}
@Override
public long getPower()
{
return this.power;
}
@Override
public void onTorqueChange(ForgeDirection side, int speed)
{

View file

@ -22,175 +22,175 @@ import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderPipe extends TileEntitySpecialRenderer
{
public static ModelPipe MODEL_PIPE = new ModelPipe();
public static ModelOpenTrough MODEL_TROUGH_PIPE = new ModelOpenTrough();
private static HashMap<Pair<FluidContainerMaterial, Integer>, ResourceLocation> TEXTURES = new HashMap<Pair<FluidContainerMaterial, Integer>, ResourceLocation>();
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_DIRECTORY + "pipe/iron.png");
public static ModelPipe MODEL_PIPE = new ModelPipe();
public static ModelOpenTrough MODEL_TROUGH_PIPE = new ModelOpenTrough();
private static HashMap<Pair<FluidContainerMaterial, Integer>, ResourceLocation> TEXTURES = new HashMap<Pair<FluidContainerMaterial, Integer>, ResourceLocation>();
public static ResourceLocation TEXTURE = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "pipe/iron.png");
@Override
public void renderTileEntityAt(TileEntity te, double d, double d1, double d2, float f)
{
FluidContainerMaterial mat = FluidContainerMaterial.IRON;
if (te.getBlockMetadata() < FluidContainerMaterial.values().length)
{
mat = FluidContainerMaterial.values()[te.getBlockMetadata()];
}
@Override
public void renderTileEntityAt(TileEntity te, double d, double d1, double d2, float f)
{
FluidContainerMaterial mat = FluidContainerMaterial.IRON;
if (te.getBlockMetadata() < FluidContainerMaterial.values().length)
{
mat = FluidContainerMaterial.values()[te.getBlockMetadata()];
}
if (te instanceof TilePipe)
{
TilePipe tile = (TilePipe) te;
if (te instanceof TilePipe)
{
TilePipe tile = (TilePipe) te;
if (mat == FluidContainerMaterial.WOOD || mat == FluidContainerMaterial.STONE)
{
FluidStack liquid = tile.getInternalTank().getFluid();
int cap = tile.getInternalTank().getCapacity();
if (mat == FluidContainerMaterial.WOOD || mat == FluidContainerMaterial.STONE)
{
FluidStack liquid = tile.getInternalTank().getFluid();
int cap = tile.getInternalTank().getCapacity();
// FluidStack liquid = new FluidStack(FluidRegistry.WATER, cap);
if (liquid != null && liquid.amount > 100)
{
float per = Math.max(1, (float) liquid.amount / (float) (cap));
int[] displayList = RenderFluidHelper.getFluidDisplayLists(liquid, te.worldObj, false);
bindTexture(RenderFluidHelper.getFluidSheet(liquid));
// FluidStack liquid = new FluidStack(FluidRegistry.WATER, cap);
if (liquid != null && liquid.amount > 100)
{
float per = Math.max(1, (float) liquid.amount / (float) (cap));
int[] displayList = RenderFluidHelper.getFluidDisplayLists(liquid, te.worldObj, false);
bindTexture(RenderFluidHelper.getFluidSheet(liquid));
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glTranslatef((float) d + 0.3F, (float) d1 + 0.1F, (float) d2 + 0.3F);
GL11.glScalef(0.4F, 0.4F, 0.4F);
GL11.glTranslatef((float) d + 0.3F, (float) d1 + 0.1F, (float) d2 + 0.3F);
GL11.glScalef(0.4F, 0.4F, 0.4F);
GL11.glCallList(displayList[(int) (per * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
GL11.glCallList(displayList[(int) (per * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib();
GL11.glPopMatrix();
GL11.glPopAttrib();
GL11.glPopMatrix();
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (tile.canRenderSide(direction) && direction != ForgeDirection.UP && direction != ForgeDirection.DOWN)
{
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (tile.canRenderSide(direction) && direction != ForgeDirection.UP && direction != ForgeDirection.DOWN)
{
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
switch (direction.ordinal())
{
case 4:
GL11.glTranslatef((float) d + 0F, (float) d1 + 0.1F, (float) d2 + 0.3F);
break;
case 5:
GL11.glTranslatef((float) d + 0.7F, (float) d1 + 0.1F, (float) d2 + 0.3F);
break;
case 2:
GL11.glTranslatef((float) d + 0.3F, (float) d1 + 0.1F, (float) d2 + 0F);
break;
case 3:
GL11.glTranslatef((float) d + 0.3F, (float) d1 + 0.1F, (float) d2 + 0.7F);
break;
}
GL11.glScalef(0.3F, 0.4F, 0.4F);
switch (direction.ordinal())
{
case 4:
GL11.glTranslatef((float) d + 0F, (float) d1 + 0.1F, (float) d2 + 0.3F);
break;
case 5:
GL11.glTranslatef((float) d + 0.7F, (float) d1 + 0.1F, (float) d2 + 0.3F);
break;
case 2:
GL11.glTranslatef((float) d + 0.3F, (float) d1 + 0.1F, (float) d2 + 0F);
break;
case 3:
GL11.glTranslatef((float) d + 0.3F, (float) d1 + 0.1F, (float) d2 + 0.7F);
break;
}
GL11.glScalef(0.3F, 0.4F, 0.4F);
GL11.glCallList(displayList[(int) (per * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
GL11.glCallList(displayList[(int) (per * (RenderFluidHelper.DISPLAY_STAGES - 1))]);
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}
}
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
}
}
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
bindTexture(RenderPipe.getTexture(mat, 0));
render(mat, tile.getSubID(), tile.renderSides);
GL11.glPopMatrix();
}
else
{
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
render(mat, 0, (byte) 0b0);
GL11.glPopMatrix();
}
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
bindTexture(RenderPipe.getTexture(mat, 0));
render(mat, tile.getSubID(), tile.renderSides);
GL11.glPopMatrix();
}
else
{
GL11.glPushMatrix();
GL11.glTranslatef((float) d + 0.5F, (float) d1 + 1.5F, (float) d2 + 0.5F);
GL11.glScalef(1.0F, -1F, -1F);
render(mat, 0, (byte) 0b0);
GL11.glPopMatrix();
}
}
}
public static ResourceLocation getTexture(FluidContainerMaterial mat, int pipeID)
{
if (mat != null)
{
Pair<FluidContainerMaterial, Integer> index = new Pair<FluidContainerMaterial, Integer>(mat, pipeID);
public static ResourceLocation getTexture(FluidContainerMaterial mat, int pipeID)
{
if (mat != null)
{
Pair<FluidContainerMaterial, Integer> index = new Pair<FluidContainerMaterial, Integer>(mat, pipeID);
if (!TEXTURES.containsKey(index))
{
String pipeName = "";
if (EnumPipeType.get(pipeID) != null)
{
pipeName = EnumPipeType.get(pipeID).getName(pipeID);
}
TEXTURES.put(index, new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "pipe/" + mat.matName + ".png"));
}
return TEXTURES.get(index);
}
return TEXTURE;
}
if (!TEXTURES.containsKey(index))
{
String pipeName = "";
if (EnumPipeType.get(pipeID) != null)
{
pipeName = EnumPipeType.get(pipeID).getName(pipeID);
}
TEXTURES.put(index, new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "pipe/" + mat.matName + ".png"));
}
return TEXTURES.get(index);
}
return TEXTURE;
}
public static ResourceLocation getTexture(int meta)
{
return getTexture(FluidContainerMaterial.getFromItemMeta(meta), FluidContainerMaterial.getType(meta));
}
public static ResourceLocation getTexture(int meta)
{
return getTexture(FluidContainerMaterial.getFromItemMeta(meta), FluidContainerMaterial.getType(meta));
}
public static void render(FluidContainerMaterial mat, int pipeID, byte side)
{
if (mat == FluidContainerMaterial.WOOD)
{
MODEL_TROUGH_PIPE.render(side, false);
}
else if (mat == FluidContainerMaterial.STONE)
{
MODEL_TROUGH_PIPE.render(side, true);
}
else
{
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.DOWN))
{
MODEL_PIPE.renderBottom();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.UP))
{
MODEL_PIPE.renderTop();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.NORTH))
{
MODEL_PIPE.renderBack();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.SOUTH))
{
MODEL_PIPE.renderFront();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.WEST))
{
MODEL_PIPE.renderLeft();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.EAST))
{
MODEL_PIPE.renderRight();
}
public static void render(FluidContainerMaterial mat, int pipeID, byte side)
{
if (mat == FluidContainerMaterial.WOOD)
{
MODEL_TROUGH_PIPE.render(side, false);
}
else if (mat == FluidContainerMaterial.STONE)
{
MODEL_TROUGH_PIPE.render(side, true);
}
else
{
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.DOWN))
{
MODEL_PIPE.renderBottom();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.UP))
{
MODEL_PIPE.renderTop();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.NORTH))
{
MODEL_PIPE.renderBack();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.SOUTH))
{
MODEL_PIPE.renderFront();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.WEST))
{
MODEL_PIPE.renderLeft();
}
if (TileFluidNetwork.canRenderSide(side, ForgeDirection.EAST))
{
MODEL_PIPE.renderRight();
}
MODEL_PIPE.renderMiddle();
}
}
MODEL_PIPE.renderMiddle();
}
}
public static void render(int meta, byte sides)
{
render(FluidContainerMaterial.getFromItemMeta(meta), FluidContainerMaterial.getType(meta), sides);
}
public static void render(int meta, byte sides)
{
render(FluidContainerMaterial.getFromItemMeta(meta), FluidContainerMaterial.getType(meta), sides);
}
}

View file

@ -77,18 +77,17 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
public long getTorque()
{
return (long) (force * radius);
return (long) torque;// (force * radius);
}
@Override
public void update()
{
/**
* Update angle rotation.
*/
if (angularVelocity > 0 && torque > 0)
if (angularVelocity < 0 || torque == 0)
{
angle += angularVelocity / 20;
angularVelocity = 0;
torque = 0;
}
// TODO: Should we average the torque?
@ -103,12 +102,12 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
if (part instanceof PartGear)
{
torque = (torque + ((PartGear) part).torque) / 2;
((PartGear) part).torque = torque;
equatePower((PartGear) part, false);
}
}
else if (tile instanceof IMechanical)
{
torque = (long) (((IMechanical) tile).getPower() / angularVelocity);
((IMechanical) tile).setPower(torque, angularVelocity);
}
@ -124,10 +123,9 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
{
TMultiPart neighbor = ((TileMultipart) checkTile).partMap(this.placementSide.ordinal());
if (neighbor instanceof PartGear)
if (neighbor != this && neighbor instanceof PartGear)
{
torque = (torque - ((PartGear) neighbor).torque) / 2;
((PartGear) neighbor).torque = -torque;
equatePower((PartGear) neighbor, false);
}
}
}
@ -136,28 +134,53 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart
for (int i = 0; i < 6; i++)
{
// TODO: Make it work with UP-DOWN
if (i < 2)
if (i < 4)
{
TMultiPart neighbor = tile().partMap(this.placementSide.getRotation(ForgeDirection.getOrientation(i)).ordinal());
if (neighbor instanceof PartGear)
if (neighbor != this && neighbor instanceof PartGear)
{
torque = (torque - ((PartGear) neighbor).torque) / 2;
((PartGear) neighbor).torque = -torque;
equatePower((PartGear) neighbor, false);
}
}
}
/**
* Update angle rotation.
*/
if (angularVelocity > 0 && torque != 0)
{
angle += angularVelocity / 20;
}
}
public void equatePower(PartGear neighbor, boolean isPositive)
{
if (isPositive)
{
torque = (torque + ((PartGear) neighbor).torque) / 2;
((PartGear) neighbor).torque = torque;
}
else
{
torque = (torque - ((PartGear) neighbor).torque) / 2;
((PartGear) neighbor).torque = -torque;
}
angularVelocity = (angularVelocity + ((PartGear) neighbor).angularVelocity) / 2;
((PartGear) neighbor).angularVelocity = angularVelocity;
}
@Override
public boolean activate(EntityPlayer player, MovingObjectPosition hit, ItemStack item)
{
System.out.println("Torque" + this.torque + " Angular Velocity" + this.angularVelocity);
System.out.println("Torque" + torque + " Angular Velocity" + angularVelocity);
if (player.isSneaking())
{
this.torque += 10;
this.angularVelocity += 0.1f;
this.angularVelocity += 0.2f;
}
return false;

View file

@ -63,7 +63,7 @@ public class RenderGear
break;
}
GL11.glRotatef((float) Math.toDegrees(part.angle), 0, 1, 0);
GL11.glRotatef((float) Math.toDegrees(part.angle) * (part.getTorque() > 0 ? 1 : -1), 0, 1, 0);
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
MODEL.renderAll();

View file

@ -12,6 +12,8 @@ public interface IMechanical extends IConnectable
{
public void setPower(long torque, float speed);
public long getPower();
/** Called by the network when its torque value changes. */
public void onTorqueChange(ForgeDirection side, int speed);