Started working on turntable

Updating it including redoing rotation so it can function as a rotator
for all blocks including vanilla ones.
This commit is contained in:
DarkGuardsman 2013-10-23 09:44:56 -04:00
parent 2dae212204
commit 99b53635f1

View file

@ -15,6 +15,7 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3; import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.block.IRotatableBlock;
import universalelectricity.prefab.tile.IRotatable; import universalelectricity.prefab.tile.IRotatable;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -105,41 +106,58 @@ public class BlockTurntable extends BlockAssembly
try try
{ {
ForgeDirection direction = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); ForgeDirection direction = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
Vector3 position = new Vector3(x, y, z); ForgeDirection currentDirection = null;
position.modifyPositionFromSide(direction);
IRotatable rotatable = null; Vector3 position = new Vector3(x, y, z).modifyPositionFromSide(direction);
TileEntity tileEntity = position.getTileEntity(world); TileEntity tileEntity = position.getTileEntity(world);
int blockID = position.getBlockID(world); int blockID = position.getBlockID(world);
if (tileEntity instanceof IRotatable) if (tileEntity instanceof IRotatable)
{ {
rotatable = ((IRotatable) tileEntity); currentDirection = ((IRotatable) tileEntity).getDirection();
} }
else if (Block.blocksList[blockID] instanceof IRotatable) else if (Block.blocksList[blockID] instanceof IRotatableBlock)
{ {
rotatable = ((IRotatable) Block.blocksList[blockID]); currentDirection = ((IRotatableBlock) Block.blocksList[blockID]).getDirection(world, position.intX(), position.intY(), position.intZ());
} }
if (direction == ForgeDirection.UP || direction == ForgeDirection.DOWN)
if (rotatable != null)
{ {
int newDir = ((IRotatable) tileEntity).getDirection().ordinal(); if (currentDirection == ForgeDirection.NORTH)
newDir++;
while (newDir >= 6)
{ {
newDir -= 6; currentDirection = ForgeDirection.EAST;
} }
else if (currentDirection == ForgeDirection.EAST)
while (newDir < 0)
{ {
newDir += 6; currentDirection = ForgeDirection.SOUTH;
} }
else if (currentDirection == ForgeDirection.SOUTH)
{
currentDirection = ForgeDirection.WEST;
}
else if (currentDirection == ForgeDirection.WEST)
{
currentDirection = ForgeDirection.NORTH;
}
}
else if (direction == ForgeDirection.EAST || direction == ForgeDirection.WEST)
{
rotatable.setDirection(ForgeDirection.getOrientation(newDir)); }
else if (direction == ForgeDirection.NORTH || direction == ForgeDirection.SOUTH)
{
world.markBlockForUpdate(position.intX(), position.intY(), position.intZ()); }
world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "tile.piston.in", 0.5F, world.rand.nextFloat() * 0.15F + 0.6F); world.markBlockForUpdate(position.intX(), position.intY(), position.intZ());
world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "tile.piston.in", 0.5F, world.rand.nextFloat() * 0.15F + 0.6F);
if (tileEntity instanceof IRotatable)
{
((IRotatable) tileEntity).setDirection(currentDirection);
}
else if (Block.blocksList[blockID] instanceof IRotatableBlock)
{
((IRotatableBlock) Block.blocksList[blockID]).setDirection(world, position.intX(), position.intY(), position.intZ(), currentDirection);
} }
} }
catch (Exception e) catch (Exception e)