@Override public String getName() { return property.getName(); }
public IPropertyAdapter(IProperty<T> property) { this.property = property; this.values = ImmutableList.copyOf(property.getAllowedValues()); }
public static Property<?> adaptProperty(IProperty<?> property) { if (property instanceof PropertyBool) { return new BooleanProperty(property.getName(), ImmutableList.copyOf(((PropertyBool) property).getAllowedValues())); } if (property instanceof PropertyInteger) { return new IntegerProperty(property.getName(), ImmutableList.copyOf(((PropertyInteger) property).getAllowedValues())); } if (property instanceof PropertyDirection) { return new DirectionalProperty(property.getName(), ((PropertyDirection) property).getAllowedValues().stream() .map(ForgeAdapter::adaptEnumFacing) .collect(Collectors.toList())); } if (property instanceof PropertyEnum) { return new EnumProperty(property.getName(), ((PropertyEnum<?>) property).getAllowedValues().stream() .map(e -> e.getName()) .collect(Collectors.toList())); } return new IPropertyAdapter<>(property); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private IBlockState applyProperties(BlockStateContainer stateContainer, IBlockState newState, Map<Property<?>, Object> states) { for (Map.Entry<Property<?>, Object> state : states.entrySet()) { IProperty property = stateContainer.getProperty(state.getKey().getName()); Comparable value = (Comparable) state.getValue(); // we may need to adapt this value, depending on the source prop if (property instanceof PropertyDirection) { Direction dir = (Direction) value; value = ForgeAdapter.adapt(dir); } else if (property instanceof PropertyEnum) { String enumName = (String) value; value = ((PropertyEnum<?>) property).parseValue((String) value).or(() -> { throw new IllegalStateException("Enum property " + property.getName() + " does not contain " + enumName); }); } newState = newState.withProperty(property, value); } return newState; }
@SideOnly(Side.CLIENT) @Override public void registerModels() { ModelHandler.registerBlockToState(this, BotaniaStateProps.PAVEMENT_COLOR.getAllowedValues().size()); }
@Override public T getValueFor(String string) throws IllegalArgumentException { Optional<T> val = property.parseValue(string); checkArgument(val.isPresent(), "%s has no value for %s", getName(), string); return val.get(); }
@Override public boolean canPlaceBlockAt(World worldIn, BlockPos pos){ for(EnumFacing enumfacing : BlockTorch.FACING.getAllowedValues()){ if(this.canPlaceAt(worldIn, pos, enumfacing)){ return true; } } return false; }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj instanceof PropertyMaterial && super.equals(obj)) { PropertyMaterial propertyMaterial = (PropertyMaterial) obj; return this.allowedValues.equals(propertyMaterial.allowedValues); } else { return false; } }
@Override public int hashCode() { int i = super.hashCode(); i = 31 * i + this.allowedValues.hashCode(); return i; }
private Map<Property<?>, Object> adaptProperties(BlockType block, Map<IProperty<?>, Comparable<?>> mcProps) { Map<Property<?>, Object> props = new TreeMap<>(Comparator.comparing(Property::getName)); for (Map.Entry<IProperty<?>, Comparable<?>> prop : mcProps.entrySet()) { Object value = prop.getValue(); if (prop.getKey() instanceof PropertyDirection) { value = ForgeAdapter.adaptEnumFacing((EnumFacing) value); } else if (prop.getKey() instanceof PropertyEnum) { value = ((IStringSerializable) value).getName(); } props.put(block.getProperty(prop.getKey().getName()), value); } return props; }
@Nonnull @Override public IBlockState getStateFromMeta(int meta) { if (meta < 0 || meta >= BotaniaStateProps.BIOMESTONEWALL_VARIANT.getAllowedValues().size()) { meta = 0; } return getDefaultState().withProperty(BotaniaStateProps.BIOMESTONEWALL_VARIANT, BiomeStoneVariant.values()[meta + 8]); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } else if (obj instanceof PropertyStoneType && super.equals(obj)) { PropertyStoneType propertyStoneType = (PropertyStoneType) obj; return this.allowedValues.equals(propertyStoneType.allowedValues); } else { return false; } }
@Override public int hashCode() { int i = super.hashCode(); i = 31 * i + this.allowedValues.hashCode(); return i; }
@Override public Map<String, ? extends Property<?>> getProperties(BlockType blockType) { Map<String, Property<?>> map = new TreeMap<>(); Collection<IProperty<?>> propertyKeys = Block.getBlockFromName(blockType.getId()) .getDefaultState() .getPropertyKeys(); for (IProperty<?> key : propertyKeys) { map.put(key.getName(), ForgeAdapter.adaptProperty(key)); } return map; }
&& BotaniaAPI.paintableBlocks.get(block).getAllowedValues().contains(placeColor)) { entity.world.setBlockState(coords, stateThere.withProperty(BotaniaAPI.paintableBlocks.get(block), placeColor), 2); PacketHandler.sendToNearby(entity.world, coords,
@SuppressWarnings("unchecked") private static <T extends Comparable<T>> String getPropertyName(IProperty<T> property, Comparable<?> value) { return property.getName((T) value); } }
private static <T extends Comparable<T>> String serializeValue(IProperty<T> property, Comparable<?> valueString) { //noinspection unchecked return property.getName((T) valueString); }
@SuppressWarnings("unchecked") private static <T extends Comparable<T>> String getPropertyName(IProperty<T> property, Comparable<?> comparable) { return property.getName((T) comparable); }
private static <T extends Comparable<T>> String serializeValue(IProperty<T> property, Comparable<?> valueString) { //noinspection unchecked return property.getName((T) valueString); }
@SuppressWarnings("unchecked") private static <T extends Comparable<T>> Function<Map.Entry<IProperty<?>, Comparable<?>>, String> createConverter() { return entry -> { final IProperty<T> property = (IProperty<T>)entry.getKey(); final T value = (T)entry.getValue(); return property.getName() + "=" + property.getName(value); }; }