Water turbine now works on all sides

This commit is contained in:
Calclavia 2014-03-18 21:26:18 +08:00
parent fab6b40376
commit a53ab674da
3 changed files with 44 additions and 35 deletions

View file

@ -89,32 +89,36 @@ public class TileWaterTurbine extends TileMechanicalTurbine
else
{
maxPower = 2500;
ForgeDirection currentDir = getDirection();
int checkX = xCoord;
int checkY = yCoord - 1;
int checkZ = zCoord;
int blockID = worldObj.getBlockId(xCoord, checkY, checkZ);
int metadata = worldObj.getBlockMetadata(xCoord, checkY, checkZ);
if (blockID == Block.waterMoving.blockID || blockID == Block.waterStill.blockID)
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
try
if (dir != currentDir && dir != currentDir.getOpposite())
{
Method m = ReflectionHelper.findMethod(BlockFluid.class, null, new String[] { "getFlowVector", "func_72202_i" }, IBlockAccess.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
Vector3 vector = new Vector3((Vec3) m.invoke(Block.waterMoving, worldObj, xCoord, checkY, checkZ));
ForgeDirection dir = getDirection();
Vector3 check = new Vector3(this).translate(dir);
int blockID = worldObj.getBlockId(check.intX(), check.intY(), check.intZ());
int metadata = worldObj.getBlockMetadata(check.intX(), check.intY(), check.intZ());
if ((dir.offsetZ > 0 && vector.x < 0) || (dir.offsetZ < 0 && vector.x > 0) || (dir.offsetX > 0 && vector.z > 0) || (dir.offsetX < 0 && vector.z < 0))
torque = -torque;
if (blockID == Block.waterMoving.blockID || blockID == Block.waterStill.blockID)
{
try
{
Method m = ReflectionHelper.findMethod(BlockFluid.class, null, new String[] { "getFlowVector", "func_72202_i" }, IBlockAccess.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
Vector3 vector = new Vector3((Vec3) m.invoke(Block.waterMoving, worldObj, check.intX(), check.intY(), check.intZ()));
if (getDirection().offsetX != 0)
getMultiBlock().get().power += Math.abs(getWaterPower() * vector.z * (7 - metadata) / 7f);
if (getDirection().offsetZ != 0)
getMultiBlock().get().power += Math.abs(getWaterPower() * vector.x * (7 - metadata) / 7f);
}
catch (Exception e)
{
e.printStackTrace();
if ((currentDir.offsetZ > 0 && vector.x < 0) || (currentDir.offsetZ < 0 && vector.x > 0) || (currentDir.offsetX > 0 && vector.z > 0) || (currentDir.offsetX < 0 && vector.z < 0))
torque = -torque;
if (getDirection().offsetX != 0)
getMultiBlock().get().power += Math.abs(getWaterPower() * vector.z * (7 - metadata) / 7f);
if (getDirection().offsetZ != 0)
getMultiBlock().get().power += Math.abs(getWaterPower() * vector.x * (7 - metadata) / 7f);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}

View file

@ -57,7 +57,7 @@ public class RenderMechanicalPiston extends TileEntitySpecialRenderer
*/
GL11.glPushMatrix();
// TODO: Temporary, unless new models come out.
GL11.glTranslated(0, 0, (0.06 * Math.sin(angle - Math.PI)) - 0.01);
GL11.glTranslated(0, 0, (0.06 * Math.sin(angle)) - 0.01);
MODEL.renderOnly("PistonShaft", "PistonFace", "PistonFace2");
GL11.glPopMatrix();

View file

@ -93,25 +93,28 @@ public class TileMechanicalPiston extends TileMechanical implements IRotatable
if (resources.length > 0)
{
int breakStatus = (int) (((float) (mechanicalPistonBreakCount - breakCount) / (float) mechanicalPistonBreakCount) * 10f);
world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), breakStatus);
if (breakCount <= 0)
if (!worldObj.isRemote)
{
if (!world().isRemote)
int breakStatus = (int) (((float) (mechanicalPistonBreakCount - breakCount) / (float) mechanicalPistonBreakCount) * 10f);
world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), breakStatus);
if (breakCount <= 0)
{
for (RecipeResource recipe : resources)
if (!world().isRemote)
{
if (Math.random() <= recipe.getChance())
for (RecipeResource recipe : resources)
{
InventoryUtility.dropItemStack(world(), blockPos.clone().translate(0.5), recipe.getItemStack(), 10);
if (Math.random() <= recipe.getChance())
{
InventoryUtility.dropItemStack(world(), blockPos.clone().translate(0.5), recipe.getItemStack(), 10);
}
}
world().setBlockToAir(blockPos.intX(), blockPos.intY(), blockPos.intZ());
}
world().setBlockToAir(blockPos.intX(), blockPos.intY(), blockPos.intZ());
breakCount = mechanicalPistonBreakCount;
}
breakCount = mechanicalPistonBreakCount;
}
ResonantInduction.proxy.renderBlockParticle(worldObj, blockPos.clone().translate(0.5), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), block.blockID, 1);
@ -120,8 +123,10 @@ public class TileMechanicalPiston extends TileMechanical implements IRotatable
}
}
breakCount = 0;
world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), 10);
breakCount = mechanicalPistonBreakCount;
if (!worldObj.isRemote)
world().destroyBlockInWorldPartially(0, blockPos.intX(), blockPos.intY(), blockPos.intZ(), -1);
return false;
}