Finished turntable and fixed grate rotation issues

This commit is contained in:
Calclavia 2014-01-18 16:28:00 +08:00
parent 0666f18a8a
commit 93fbc7e0ce
8 changed files with 42 additions and 207 deletions

View file

@ -11,24 +11,27 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon; import net.minecraft.util.Icon;
import net.minecraft.util.MathHelper; import net.minecraft.util.MathHelper;
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 resonantinduction.core.Reference; import resonantinduction.core.Reference;
import resonantinduction.core.prefab.block.BlockRI; import resonantinduction.core.prefab.block.BlockRIRotatable;
import universalelectricity.api.vector.Vector3; import universalelectricity.api.vector.Vector3;
import calclavia.lib.prefab.block.IRotatableBlock; import calclavia.lib.prefab.block.IRotatableBlock;
import calclavia.lib.prefab.tile.IRotatable; import calclavia.lib.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;
public class BlockTurntable extends BlockRI public class BlockTurntable extends BlockRIRotatable
{ {
private Icon top; private Icon top;
public BlockTurntable() public BlockTurntable()
{ {
super("turntable", Material.piston); super("turntable");
this.setTickRandomly(true); setTextureName(Reference.PREFIX + "turntable_side");
setTickRandomly(true);
rotationMask = 0b111111;
} }
@Override @Override
@ -53,48 +56,34 @@ public class BlockTurntable extends BlockRI
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta) public Icon getBlockTexture(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int side)
{ {
int meta = par1IBlockAccess.getBlockMetadata(par2, par3, par4);
if (side == meta) if (side == meta)
{ {
return this.top; return this.top;
} }
return this.blockIcon; return this.blockIcon;
} }
@Override @Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack stack) @SideOnly(Side.CLIENT)
public Icon getIcon(int side, int meta)
{ {
int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if (side == 1)
int change = 3;
switch (angle)
{ {
case 0: return this.top;
change = 2;
break;
case 1:
change = 5;
break;
case 2:
change = 3;
break;
case 3:
change = 4;
break;
} }
world.setBlockMetadataWithNotify(x, y, z, change, 3); return this.blockIcon;
world.scheduleBlockUpdate(x, y, z, this.blockID, 20);
} }
@Override @Override
public void onNeighborBlockChange(World world, int x, int y, int z, int side) public void onNeighborBlockChange(World world, int x, int y, int z, int side)
{ {
world.scheduleBlockUpdate(x, y, z, this.blockID, 20); world.scheduleBlockUpdate(x, y, z, this.blockID, 10);
} }
private void updateTurntableState(World world, int x, int y, int z) private void updateTurntableState(World world, int x, int y, int z)
@ -103,98 +92,29 @@ public class BlockTurntable extends BlockRI
{ {
try try
{ {
ForgeDirection direction = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z)); ForgeDirection facing = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
ForgeDirection blockRotation = null;
Vector3 position = new Vector3(x, y, z).modifyPositionFromSide(direction); Vector3 position = new Vector3(x, y, z).modifyPositionFromSide(facing);
TileEntity tileEntity = position.getTileEntity(world); TileEntity tileEntity = position.getTileEntity(world);
int blockID = position.getBlockID(world); Block block = Block.blocksList[position.getBlockID(world)];
if (tileEntity instanceof IRotatable) if (tileEntity instanceof IRotatable)
{ {
blockRotation = ((IRotatable) tileEntity).getDirection(); ForgeDirection blockRotation = ((IRotatable) tileEntity).getDirection();
((IRotatable) tileEntity).setDirection(blockRotation.getRotation(facing.getOpposite()));
} }
else if (Block.blocksList[blockID] instanceof IRotatableBlock) else if (block instanceof IRotatableBlock)
{ {
blockRotation = ((IRotatableBlock) Block.blocksList[blockID]).getDirection(world, position.intX(), position.intY(), position.intZ()); ForgeDirection blockRotation = ((IRotatableBlock) block).getDirection(world, position.intX(), position.intY(), position.intZ());
((IRotatableBlock) block).setDirection(world, position.intX(), position.intY(), position.intZ(), blockRotation.getRotation(facing.getOpposite()));
} }
else if (Block.blocksList[blockID] != null) else if (block != null)
{ {
Block.blocksList[blockID].rotateBlock(world, position.intX(), position.intY(), position.intZ(), direction.getOpposite()); Block.blocksList[blockID].rotateBlock(world, position.intX(), position.intY(), position.intZ(), facing.getOpposite());
} }
if (direction != null)
{
if (direction == ForgeDirection.UP || direction == ForgeDirection.DOWN)
{
if (blockRotation == ForgeDirection.NORTH)
{
blockRotation = ForgeDirection.EAST;
}
else if (blockRotation == ForgeDirection.EAST)
{
blockRotation = ForgeDirection.SOUTH;
}
else if (blockRotation == ForgeDirection.SOUTH)
{
blockRotation = ForgeDirection.WEST;
}
else if (blockRotation == ForgeDirection.WEST)
{
blockRotation = ForgeDirection.NORTH;
}
}
else if (direction == ForgeDirection.EAST || direction == ForgeDirection.WEST)
{
if (blockRotation == ForgeDirection.NORTH)
{
blockRotation = ForgeDirection.UP;
}
else if (blockRotation == ForgeDirection.UP)
{
blockRotation = ForgeDirection.SOUTH;
}
else if (blockRotation == ForgeDirection.SOUTH)
{
blockRotation = ForgeDirection.DOWN;
}
else if (blockRotation == ForgeDirection.DOWN)
{
blockRotation = ForgeDirection.NORTH;
}
}
else if (direction == ForgeDirection.NORTH || direction == ForgeDirection.SOUTH)
{
if (blockRotation == ForgeDirection.EAST)
{
blockRotation = ForgeDirection.UP;
}
else if (blockRotation == ForgeDirection.UP)
{
blockRotation = ForgeDirection.WEST;
}
else if (blockRotation == ForgeDirection.WEST)
{
blockRotation = ForgeDirection.DOWN;
}
else if (blockRotation == ForgeDirection.DOWN)
{
blockRotation = ForgeDirection.EAST;
}
}
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(blockRotation);
world.scheduleBlockUpdate(position.intX(), position.intY(), position.intZ(), this.blockID, 20);
} world.markBlockForUpdate(position.intX(), position.intY(), position.intZ());
else if (Block.blocksList[blockID] instanceof IRotatableBlock) world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "tile.piston.in", 0.5F, world.rand.nextFloat() * 0.15F + 0.6F);
{
((IRotatableBlock) Block.blocksList[blockID]).setDirection(world, position.intX(), position.intY(), position.intZ(), blockRotation);
world.scheduleBlockUpdate(position.intX(), position.intY(), position.intZ(), this.blockID, 20);
}
}
} }
catch (Exception e) catch (Exception e)
{ {
@ -204,57 +124,4 @@ public class BlockTurntable extends BlockRI
} }
} }
@Override
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (world.isRemote)
{
return true;
}
world.setBlockMetadataWithNotify(x, y, z, side, 3);
return true;
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (world.isRemote)
{
return true;
}
ForgeDirection currentDirection = ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
if (currentDirection == ForgeDirection.NORTH)
{
currentDirection = ForgeDirection.UP;
}
else if (currentDirection == ForgeDirection.UP)
{
currentDirection = ForgeDirection.DOWN;
}
else if (currentDirection == ForgeDirection.DOWN)
{
currentDirection = ForgeDirection.EAST;
}
else if (currentDirection == ForgeDirection.EAST)
{
currentDirection = ForgeDirection.SOUTH;
}
else if (currentDirection == ForgeDirection.SOUTH)
{
currentDirection = ForgeDirection.WEST;
}
else if (currentDirection == ForgeDirection.WEST)
{
currentDirection = ForgeDirection.NORTH;
}
world.setBlockMetadataWithNotify(x, y, z, currentDirection.ordinal(), 3);
return true;
}
@Override
public TileEntity createNewTileEntity(World world)
{
// TODO Auto-generated method stub
return null;
}
} }

View file

@ -17,12 +17,11 @@ import resonantinduction.core.prefab.tile.TileEntityFilterable;
* *
* @author Calclavia * @author Calclavia
*/ */
public abstract class BlockImprintable extends BlockRI public abstract class BlockImprintable extends BlockRIRotatable
{ {
public BlockImprintable(String blockName)
public BlockImprintable(String blockName, Material material)
{ {
super(blockName, material); super(blockName);
} }
/** Allows filters to be placed inside of this block. */ /** Allows filters to be placed inside of this block. */

View file

@ -1,5 +1,6 @@
package resonantinduction.core.prefab.block; package resonantinduction.core.prefab.block;
import net.minecraft.block.material.Material;
import net.minecraftforge.common.Configuration; import net.minecraftforge.common.Configuration;
import resonantinduction.core.Reference; import resonantinduction.core.Reference;
import resonantinduction.core.ResonantInductionTabs; import resonantinduction.core.ResonantInductionTabs;

View file

@ -13,6 +13,7 @@ import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess; 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 resonantinduction.core.Reference;
import resonantinduction.core.prefab.block.BlockRI; import resonantinduction.core.prefab.block.BlockRI;
import resonantinduction.core.render.RIBlockRenderingHandler; import resonantinduction.core.render.RIBlockRenderingHandler;
import resonantinduction.mechanical.belt.TileConveyorBelt.SlantType; import resonantinduction.mechanical.belt.TileConveyorBelt.SlantType;
@ -29,6 +30,7 @@ public class BlockConveyorBelt extends BlockRI
public BlockConveyorBelt() public BlockConveyorBelt()
{ {
super("conveyorBelt"); super("conveyorBelt");
setTextureName(Reference.PREFIX + "material_metal_side");
this.setBlockBounds(0, 0, 0, 1, 0.3f, 1); this.setBlockBounds(0, 0, 0, 1, 0.3f, 1);
} }

View file

@ -24,6 +24,7 @@ public class BlockGrate extends BlockRIRotatable
public BlockGrate() public BlockGrate()
{ {
super("grate"); super("grate");
rotationMask = 0b111111;
} }
@Override @Override
@ -88,56 +89,21 @@ public class BlockGrate extends BlockRIRotatable
return this.blockIcon; return this.blockIcon;
} }
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase p, ItemStack itemStack)
{
int angle = MathHelper.floor_double((p.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
world.setBlockMetadataWithNotify(x, y, z, angle, 3);
TileEntity entity = world.getBlockTileEntity(x, y, z);
}
@Override @Override
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{ {
if (!world.isRemote) if (!world.isRemote)
{ {
int meta = world.getBlockMetadata(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (world.getBlockMetadata(x, y, z) < 6) if (tile instanceof TileGrate)
{ {
meta += 6; entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("Draining Sources? " + ((TileGrate) tile).canDrain()));
}
else
{
meta -= 6;
} }
world.setBlockMetadataWithNotify(x, y, z, meta, 3);
TileEntity entity = world.getBlockTileEntity(x, y, z);
if (entity instanceof TileGrate)
{
entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("Draining Sources? " + ((TileGrate) entity).canDrain()));
}
return true; return true;
} }
return true;
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
if (!world.isRemote)
{
int meta = side;
if (world.getBlockMetadata(x, y, z) > 5)
{
meta += 6;
}
world.setBlockMetadataWithNotify(x, y, z, meta, 3);
return true;
}
return true; return true;
} }
} }

View file

@ -24,7 +24,7 @@ public class BlockDetector extends BlockImprintable
public BlockDetector() public BlockDetector()
{ {
super("detector", UniversalElectricity.machine); super("detector");
} }
@Override @Override

View file

@ -20,7 +20,7 @@ public class BlockManipulator extends BlockImprintable
{ {
public BlockManipulator() public BlockManipulator()
{ {
super("manipulator", UniversalElectricity.machine); super("manipulator");
this.setBlockBounds(0, 0, 0, 1, 0.29f, 1); this.setBlockBounds(0, 0, 0, 1, 0.29f, 1);
} }

View file

@ -18,7 +18,7 @@ public class BlockRejector extends BlockImprintable
public BlockRejector() public BlockRejector()
{ {
super("rejector", UniversalElectricity.machine); super("rejector");
} }
@Override @Override