public <T extends Comparable<T>> T getValue(IProperty<T> property) { final Comparable<?> value = values.get(property); Preconditions.checkArgument(value != null, "Cannot get property %s", property); return property.getValueClass().cast(value); }
@Override public <T extends Comparable<T>> T getValue(IProperty<T> property) { int offset = ((IPatchedBlockStateContainer) container).getPropertyOffsets().getOrDefault(property, -1); if (offset == -1) { throw new IllegalArgumentException("Cannot get property " + property + " as it does not exist in " + container); } int width = propertyWidths.get(property); int number = data >>> offset & 0xFFFFFFFF >>> 32 - width; Comparable<?> value = numberToValue.get(new Pair<>(property, number)); return property.getValueClass().cast(value); }
public static IBlockState rotateFacing(IBlockState state, int turns) { for (Map.Entry<IProperty<?>, Comparable<?>> property : state.getProperties().entrySet()) { Class<?> valueClass = property.getKey().getValueClass(); if (ROTATORS.containsKey(valueClass)) { //noinspection unchecked state = rotateY(state, property.getKey(), turns); } } return state; }
@Nullable public static <T extends Comparable<T>> IProperty<T> getProperty(Block block, String propertyName, Class<T> valueClass) { for (IProperty<?> property : block.getDefaultState().getPropertyKeys()) { if (property.getName().equals(propertyName)) { if (property.getValueClass().isAssignableFrom(valueClass)) { //noinspection unchecked return (IProperty<T>) property; } } } return null; } }
public static EnumFacing getRotation(IBlockState state) { for (IProperty<?> prop : state.getProperties().keySet()) { if ((prop.getName().equals("facing") || prop.getName().equals("rotation")) && prop.getValueClass() == EnumFacing.class) { return (EnumFacing) state.getValue(prop); } } return null; }
private static <T extends Comparable<T>> IBlockState rotateY(IBlockState state, IProperty<T> property, int turns) { //noinspection unchecked return state.withProperty(property, ((IRotator<T>) ROTATORS.get(property.getValueClass())).rotateY(state.getValue(property), turns)); }
private void showGrowthLevel(IProbeInfo probeInfo, IBlockState blockState) { for (IProperty<?> property : blockState.getProperties().keySet()) { if(!"age".equals(property.getName())) continue; if(property.getValueClass() == Integer.class) { IProperty<Integer> integerProperty = (IProperty<Integer>)property; int age = blockState.getValue(integerProperty); int maxAge = Collections.max(integerProperty.getAllowedValues()); if (age == maxAge) { probeInfo.text(OK + "Fully grown"); } else { probeInfo.text(LABEL + "Growth: " + WARNING + (age * 100) / maxAge + "%"); } } return; } }
if (BlockLever.EnumOrientation.class.isAssignableFrom(propertyFacing.getValueClass())) { final BlockLever.EnumOrientation orientation = (BlockLever.EnumOrientation) blockState.getValue(propertyFacing); final BlockLever.EnumOrientation orientationRotated = getRotatedLeverFacing(axisRotation, orientation); if (EnumFacing.Axis.class.isAssignableFrom(propertyAxis.getValueClass())) { final EnumFacing.Axis axis = (EnumFacing.Axis) blockState.getValue(propertyAxis); final EnumFacing.Axis axisRotated = getRotatedAxis(axisRotation, axis); if (BlockLog.EnumAxis.class.isAssignableFrom(propertyAxis.getValueClass())) { final BlockLog.EnumAxis axis = (BlockLog.EnumAxis) blockState.getValue(propertyAxis); final BlockLog.EnumAxis axisRotated = getRotatedLogAxis(axisRotation, axis); if (BlockQuartz.EnumType.class.isAssignableFrom(propertyVariant.getValueClass())) { final BlockQuartz.EnumType type = (BlockQuartz.EnumType) blockState.getValue(propertyVariant); final BlockQuartz.EnumType typeRotated = getRotatedQuartzType(axisRotation, type);
@SuppressWarnings({ "rawtypes", "unchecked" }) private IBlockState flipBlock(final IBlockState blockState, final EnumFacing axis, final boolean forced) throws FlipException { final IProperty propertyFacing = BlockStateHelper.getProperty(blockState, "facing"); if (propertyFacing instanceof PropertyDirection) { final Comparable value = blockState.getValue(propertyFacing); if (value instanceof EnumFacing) { final EnumFacing facing = getFlippedFacing(axis, (EnumFacing) value); if (propertyFacing.getAllowedValues().contains(facing)) { return blockState.withProperty(propertyFacing, facing); } } } else if (propertyFacing instanceof PropertyEnum) { if (BlockLever.EnumOrientation.class.isAssignableFrom(propertyFacing.getValueClass())) { final BlockLever.EnumOrientation orientation = (BlockLever.EnumOrientation) blockState.getValue(propertyFacing); final BlockLever.EnumOrientation orientationRotated = getFlippedLeverFacing(axis, orientation); if (propertyFacing.getAllowedValues().contains(orientationRotated)) { return blockState.withProperty(propertyFacing, orientationRotated); } } } else if (propertyFacing != null) { Reference.logger.error("'{}': found 'facing' property with unknown type {}", Block.REGISTRY.getNameForObject(blockState.getBlock()), propertyFacing.getClass().getSimpleName()); } if (!forced && propertyFacing != null) { throw new FlipException("'%s' cannot be flipped across '%s'", Block.REGISTRY.getNameForObject(blockState.getBlock()), axis); } return blockState; }
if (propertyFacing != null && propertyFacing.getValueClass().equals(EnumFacing.class)) { final EnumFacing facing = ((EnumFacing) blockState.getValue(propertyFacing)); for (final EnumFacing side : solidSides) { if (propertyFacing != null && propertyFacing.getValueClass().equals(EnumFacing.class)) { final EnumFacing facing = (EnumFacing) blockState.getValue(propertyFacing); for (final EnumFacing side : solidSides) {