package com.infinityraider.infinitylib.block;

import com.infinityraider.infinitylib.block.multiblock.IMultiBlockComponent;
import com.infinityraider.infinitylib.block.tile.IRotatableTile;
import com.infinityraider.infinitylib.block.tile.TileEntityBase;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public abstract class BlockBaseTile<T extends TileEntityBase> extends BlockBase implements ITileEntityProvider {
    public BlockBaseTile(String name, Material blockMaterial) {
        super(name, blockMaterial);
    }

    @Override
    public abstract T createNewTileEntity(World worldIn, int meta);

    @Override
    public boolean hasTileEntity(IBlockState state) {
        return true;
    }

    /**
     * Sets the block's orientation based upon the direction the player is
     * looking when the block is placed.
     */
    @Override
    @SuppressWarnings("unchecked")
    public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase entity, ItemStack stack) {
        TileEntity te = world.getTileEntity(pos);
        if (te != null && te instanceof TileEntityBase) {
            TileEntityBase tile = (TileEntityBase) world.getTileEntity(pos);
            if (tile instanceof IRotatableTile) {
                ((IRotatableTile) tile).setOrientation(entity.getHorizontalFacing());
            }
            if ((tile instanceof IMultiBlockComponent) && !world.isRemote) {
                IMultiBlockComponent component = (IMultiBlockComponent) tile;
                component.getMultiBlockManager().onBlockPlaced(world, pos, component);
            }
        }
    }

    @Override
    @SuppressWarnings("unchecked")
    public void breakBlock(World world, BlockPos pos, IBlockState state) {
        TileEntity tile = world.getTileEntity(pos);
        if ((tile instanceof IMultiBlockComponent) && !world.isRemote) {
            IMultiBlockComponent component = (IMultiBlockComponent) tile;
            component.getMultiBlockManager().onBlockBroken(world, pos, component);
        }
        super.breakBlock(world, pos, state);
        world.removeTileEntity(pos);
    }

    @Override
    public boolean eventReceived(IBlockState state, World world, BlockPos pos, int id, int data) {
        super.eventReceived(state, world, pos, id, data);
        TileEntity tileentity = world.getTileEntity(pos);
        return tileentity != null && tileentity.receiveClientEvent(id, data);
    }

    @Override
    public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
        if(axis.getAxis() != EnumFacing.Axis.Y) {
            return false;
        }
        TileEntity tile = world.getTileEntity(pos);
        if(!(tile instanceof IRotatableTile)) {
            return false;
        }
        int offset = axis.getFrontOffsetY();
        IRotatableTile rotatable = (IRotatableTile) tile;
        rotatable.incrementRotation(offset);
        return true;
    }
}

@@ -1561,24 +1561,207 @@
 ableTile) %7B%0A
+                EnumFacing dir = entity.getHorizontalFacing();%0A                if(dir.getAxis() == EnumFacing.Axis.X) %7B%0A                    dir = dir.getOpposite();%0A                %7D%0A
             
@@ -1807,36 +1807,11 @@
 ion(
-entity.getHorizontalFacing()
+dir
 );%0A 

Tweak rotatable block placement