use of net.minecraft.world.level.block.state.properties.ComparatorMode 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;
}
Aggregations