Search in sources :

Example 1 with LogicFacing

use of mcjty.rftools.blocks.logic.generic.LogicFacing in project RFTools by McJty.

the class AnalogBlock method checkRedstone.

@Override
protected void checkRedstone(World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    TileEntity te = world.getTileEntity(pos);
    if (state.getBlock() instanceof LogicSlabBlock && te instanceof AnalogTileEntity && loopDetector.add(pos)) {
        try {
            AnalogTileEntity tileEntity = (AnalogTileEntity) te;
            LogicFacing facing = tileEntity.getFacing(state);
            EnumFacing downSide = facing.getSide();
            EnumFacing inputSide = facing.getInputSide();
            EnumFacing rightSide = ThreeLogicBlock.rotateLeft(downSide, inputSide);
            EnumFacing leftSide = ThreeLogicBlock.rotateRight(downSide, inputSide);
            int outputStrength;
            int inputStrength = getInputStrength(world, pos, inputSide);
            int inputLeft = getInputStrength(world, pos, leftSide);
            int inputRight = getInputStrength(world, pos, rightSide);
            if (inputLeft == inputRight) {
                outputStrength = (int) (inputStrength * tileEntity.getMulEqual() + tileEntity.getAddEqual());
            } else if (inputLeft < inputRight) {
                outputStrength = (int) (inputStrength * tileEntity.getMulLess() + tileEntity.getAddLess());
            } else {
                outputStrength = (int) (inputStrength * tileEntity.getMulGreater() + tileEntity.getAddGreater());
            }
            if (outputStrength > 15) {
                outputStrength = 15;
            } else if (outputStrength < 0) {
                outputStrength = 0;
            }
            int oldPower = tileEntity.getPowerLevel();
            tileEntity.setPowerInput(outputStrength);
            if (oldPower != outputStrength) {
                world.notifyNeighborsOfStateChange(pos, this, false);
            }
        } finally {
            loopDetector.remove(pos);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) LogicSlabBlock(mcjty.rftools.blocks.logic.generic.LogicSlabBlock) EnumFacing(net.minecraft.util.EnumFacing) LogicFacing(mcjty.rftools.blocks.logic.generic.LogicFacing)

Example 2 with LogicFacing

use of mcjty.rftools.blocks.logic.generic.LogicFacing in project RFTools by McJty.

the class LogicSlabBlock method rotateBlock.

@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
    IBlockState state = world.getBlockState(pos);
    TileEntity te = world.getTileEntity(pos);
    if (state.getBlock() instanceof LogicSlabBlock && te instanceof LogicTileEntity) {
        LogicTileEntity logicTileEntity = (LogicTileEntity) te;
        LogicFacing facing = logicTileEntity.getFacing(state);
        int meta = facing.getMeta();
        switch(meta) {
            case 0:
                meta = 2;
                break;
            case 1:
                meta = 3;
                break;
            case 2:
                meta = 1;
                break;
            case 3:
                meta = 0;
                break;
        }
        LogicFacing newfacing = LogicFacing.getFacingWithMeta(facing, meta);
        logicTileEntity.setFacing(newfacing);
        world.setBlockState(pos, state.getBlock().getDefaultState().withProperty(META_INTERMEDIATE, meta).withProperty(OUTPUTPOWER, false), 3);
        return true;
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) LogicFacing(mcjty.rftools.blocks.logic.generic.LogicFacing)

Example 3 with LogicFacing

use of mcjty.rftools.blocks.logic.generic.LogicFacing in project RFTools by McJty.

the class LogicSlabBlock method getStateForPlacement.

@Override
public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    float dx = Math.abs(0.5f - hitX);
    float dy = Math.abs(0.5f - hitY);
    float dz = Math.abs(0.5f - hitZ);
    side = side.getOpposite();
    // System.out.println("LogicSlabBlock.getStateForPlacement");
    // System.out.println("  side = " + side);
    LogicFacing facing;
    switch(side) {
        case DOWN:
            if (dx < dz) {
                facing = hitZ < 0.5 ? DOWN_TOSOUTH : DOWN_TONORTH;
            } else {
                facing = hitX < 0.5 ? DOWN_TOEAST : DOWN_TOWEST;
            }
            break;
        case UP:
            if (dx < dz) {
                facing = hitZ < 0.5 ? UP_TOSOUTH : UP_TONORTH;
            } else {
                facing = hitX < 0.5 ? UP_TOEAST : UP_TOWEST;
            }
            break;
        case NORTH:
            if (dx < dy) {
                facing = hitY < 0.5 ? NORTH_TOUP : NORTH_TODOWN;
            } else {
                facing = hitX < 0.5 ? NORTH_TOEAST : NORTH_TOWEST;
            }
            break;
        case SOUTH:
            if (dx < dy) {
                facing = hitY < 0.5 ? SOUTH_TOUP : SOUTH_TODOWN;
            } else {
                facing = hitX < 0.5 ? SOUTH_TOEAST : SOUTH_TOWEST;
            }
            break;
        case WEST:
            if (dy < dz) {
                facing = hitZ < 0.5 ? WEST_TOSOUTH : WEST_TONORTH;
            } else {
                facing = hitY < 0.5 ? WEST_TOUP : WEST_TODOWN;
            }
            break;
        case EAST:
            if (dy < dz) {
                facing = hitZ < 0.5 ? EAST_TOSOUTH : EAST_TONORTH;
            } else {
                facing = hitY < 0.5 ? EAST_TOUP : EAST_TODOWN;
            }
            break;
        default:
            facing = DOWN_TOWEST;
            break;
    }
    // LOGIC_FACING doesn't get saved to metadata, but it doesn't need to. It only needs to be available until LogicTileEntity#onLoad() runs.
    return super.getStateForPlacement(worldIn, pos, side, hitX, hitY, hitZ, meta, placer).withProperty(META_INTERMEDIATE, facing.getMeta()).withProperty(OUTPUTPOWER, false).withProperty(LOGIC_FACING, facing);
}
Also used : LogicFacing(mcjty.rftools.blocks.logic.generic.LogicFacing)

Example 4 with LogicFacing

use of mcjty.rftools.blocks.logic.generic.LogicFacing in project RFTools by McJty.

the class ThreeLogicBlock method checkRedstone.

@Override
protected void checkRedstone(World world, BlockPos pos) {
    IBlockState state = world.getBlockState(pos);
    TileEntity te = world.getTileEntity(pos);
    if (state.getBlock() instanceof LogicSlabBlock && te instanceof ThreeLogicTileEntity && loopDetector.add(pos)) {
        try {
            ThreeLogicTileEntity tileEntity = (ThreeLogicTileEntity) te;
            LogicFacing facing = tileEntity.getFacing(state);
            EnumFacing downSide = facing.getSide();
            EnumFacing inputSide = facing.getInputSide();
            EnumFacing leftSide = rotateLeft(downSide, inputSide);
            EnumFacing rightSide = rotateRight(downSide, inputSide);
            int powered1 = getInputStrength(world, pos, leftSide) > 0 ? 1 : 0;
            int powered2 = getInputStrength(world, pos, inputSide) > 0 ? 2 : 0;
            int powered3 = getInputStrength(world, pos, rightSide) > 0 ? 4 : 0;
            tileEntity.setPowerInput(powered1 + powered2 + powered3);
            tileEntity.checkRedstone();
        } finally {
            loopDetector.remove(pos);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) LogicSlabBlock(mcjty.rftools.blocks.logic.generic.LogicSlabBlock) EnumFacing(net.minecraft.util.EnumFacing) LogicFacing(mcjty.rftools.blocks.logic.generic.LogicFacing)

Example 5 with LogicFacing

use of mcjty.rftools.blocks.logic.generic.LogicFacing in project RFTools by McJty.

the class LogicSlabBlock method getActualState.

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
    int meta = state.getValue(META_INTERMEDIATE);
    TileEntity te = world instanceof ChunkCache ? ((ChunkCache) world).getTileEntity(pos, Chunk.EnumCreateEntityType.CHECK) : world.getTileEntity(pos);
    if (te instanceof LogicTileEntity) {
        LogicTileEntity logicTileEntity = (LogicTileEntity) te;
        LogicFacing facing = logicTileEntity.getFacing(state);
        facing = LogicFacing.getFacingWithMeta(facing, meta);
        return state.withProperty(LOGIC_FACING, facing);
    } else {
        Logging.warn(null, "LogicSlabBlock missing its tile entity!");
        return state.withProperty(LOGIC_FACING, LogicFacing.DOWN_TONORTH);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ChunkCache(net.minecraft.world.ChunkCache) LogicFacing(mcjty.rftools.blocks.logic.generic.LogicFacing)

Aggregations

LogicFacing (mcjty.rftools.blocks.logic.generic.LogicFacing)5 TileEntity (net.minecraft.tileentity.TileEntity)4 IBlockState (net.minecraft.block.state.IBlockState)3 LogicSlabBlock (mcjty.rftools.blocks.logic.generic.LogicSlabBlock)2 EnumFacing (net.minecraft.util.EnumFacing)2 ChunkCache (net.minecraft.world.ChunkCache)1