Search in sources :

Example 1 with ComparatorBlock

use of net.minecraft.world.level.block.ComparatorBlock in project fabric-carpet by gnembon.

the class BlockRotator method alternativeBlockPlacement.

public static // World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
BlockState alternativeBlockPlacement(// World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
Block block, // World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
BlockPlaceContext context) {
    // 
    if (true)
        throw new UnsupportedOperationException("Alternative Block Placement / client controlled / is not implemnted");
    Direction facing;
    Vec3 vec3d = context.getClickLocation();
    float hitX = (float) vec3d.x;
    if (// vanilla
    hitX < 2)
        return null;
    int code = (int) (hitX - 2) / 2;
    // 
    // now it would be great if hitX was adjusted in context to original range from 0.0 to 1.0
    // since its actually using it. Its private - maybe with Reflections?
    // 
    Player placer = context.getPlayer();
    BlockPos pos = context.getClickedPos();
    Level world = context.getLevel();
    if (block instanceof GlazedTerracottaBlock) {
        facing = Direction.from3DDataValue(code);
        if (facing == Direction.UP || facing == Direction.DOWN) {
            facing = placer.getDirection().getOpposite();
        }
        return block.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, facing);
    } else if (block instanceof ObserverBlock) {
        return block.defaultBlockState().setValue(DirectionalBlock.FACING, Direction.from3DDataValue(code)).setValue(ObserverBlock.POWERED, true);
    } else if (block instanceof RepeaterBlock) {
        facing = Direction.from3DDataValue(code % 16);
        if (facing == Direction.UP || facing == Direction.DOWN) {
            facing = placer.getDirection().getOpposite();
        }
        return block.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, facing).setValue(RepeaterBlock.DELAY, Mth.clamp(code / 16, 1, 4)).setValue(RepeaterBlock.LOCKED, Boolean.FALSE);
    } else if (block instanceof TrapDoorBlock) {
        return block.defaultBlockState().setValue(TrapDoorBlock.FACING, Direction.from3DDataValue(code % 16)).setValue(TrapDoorBlock.OPEN, Boolean.FALSE).setValue(TrapDoorBlock.HALF, (code >= 16) ? Half.TOP : Half.BOTTOM).setValue(TrapDoorBlock.OPEN, world.hasNeighborSignal(pos));
    } else if (block instanceof ComparatorBlock) {
        facing = Direction.from3DDataValue(code % 16);
        if ((facing == Direction.UP) || (facing == Direction.DOWN)) {
            facing = placer.getDirection().getOpposite();
        }
        ComparatorMode m = (hitX >= 16) ? ComparatorMode.SUBTRACT : ComparatorMode.COMPARE;
        return block.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, facing).setValue(ComparatorBlock.POWERED, Boolean.FALSE).setValue(ComparatorBlock.MODE, m);
    } else if (block instanceof DispenserBlock) {
        return block.defaultBlockState().setValue(DispenserBlock.FACING, Direction.from3DDataValue(code)).setValue(DispenserBlock.TRIGGERED, Boolean.FALSE);
    } else if (block instanceof PistonBaseBlock) {
        return block.defaultBlockState().setValue(DirectionalBlock.FACING, Direction.from3DDataValue(code)).setValue(PistonBaseBlock.EXTENDED, Boolean.FALSE);
    } else if (block instanceof StairBlock) {
        return // worldIn, pos, facing, hitX, hitY, hitZ, meta, placer)
        block.getStateForPlacement(context).setValue(StairBlock.FACING, Direction.from3DDataValue(code % 16)).setValue(StairBlock.HALF, (hitX >= 16) ? Half.TOP : Half.BOTTOM);
    }
    return null;
}
Also used : GlazedTerracottaBlock(net.minecraft.world.level.block.GlazedTerracottaBlock) Player(net.minecraft.world.entity.player.Player) DispenserBlock(net.minecraft.world.level.block.DispenserBlock) ObserverBlock(net.minecraft.world.level.block.ObserverBlock) ComparatorBlock(net.minecraft.world.level.block.ComparatorBlock) StairBlock(net.minecraft.world.level.block.StairBlock) Direction(net.minecraft.core.Direction) ComparatorMode(net.minecraft.world.level.block.state.properties.ComparatorMode) PistonBaseBlock(net.minecraft.world.level.block.piston.PistonBaseBlock) TrapDoorBlock(net.minecraft.world.level.block.TrapDoorBlock) Vec3(net.minecraft.world.phys.Vec3) BlockPos(net.minecraft.core.BlockPos) Level(net.minecraft.world.level.Level) RepeaterBlock(net.minecraft.world.level.block.RepeaterBlock)

Aggregations

BlockPos (net.minecraft.core.BlockPos)1 Direction (net.minecraft.core.Direction)1 Player (net.minecraft.world.entity.player.Player)1 Level (net.minecraft.world.level.Level)1 ComparatorBlock (net.minecraft.world.level.block.ComparatorBlock)1 DispenserBlock (net.minecraft.world.level.block.DispenserBlock)1 GlazedTerracottaBlock (net.minecraft.world.level.block.GlazedTerracottaBlock)1 ObserverBlock (net.minecraft.world.level.block.ObserverBlock)1 RepeaterBlock (net.minecraft.world.level.block.RepeaterBlock)1 StairBlock (net.minecraft.world.level.block.StairBlock)1 TrapDoorBlock (net.minecraft.world.level.block.TrapDoorBlock)1 PistonBaseBlock (net.minecraft.world.level.block.piston.PistonBaseBlock)1 ComparatorMode (net.minecraft.world.level.block.state.properties.ComparatorMode)1 Vec3 (net.minecraft.world.phys.Vec3)1