@Override public String getName() { return property.getName(); }
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; }
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); }
@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; }
@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; }
@SuppressWarnings("unchecked") private static <T extends Comparable<T>> String getPropertyName(IProperty<T> property, Comparable<?> value) { return property.getName((T) value); } }
@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); }; }
public static IProperty getPropertyByName(IBlockState blockState, String propertyName) { for (IProperty property : (ImmutableSet<IProperty<?>>) blockState.getProperties().keySet()) { if (property.getName().equals(propertyName)) return property; } return null; }
public BlockStatePredicate(ResourceLocation blockRegistryLoc, Map<IProperty<?>, Comparable<?>> properties) { this.blockRegistryName = blockRegistryLoc.toString(); this.properties = Maps.newHashMap(); for (Map.Entry<IProperty<?>, Comparable<?>> entry : properties.entrySet()) { this.properties.put(entry.getKey().getName(), entry.getValue().toString()); } }
private <T extends Comparable<T>> IBlockState findProperty(IBlockState state, IProperty<T> prop, String key, String newValue) { if (key.equals(prop.getName())) { for (T value : prop.getAllowedValues()) { if (prop.getName(value).equals(newValue)) { return state.withProperty(prop, value); } } } return null; } }
@SuppressWarnings({ "rawtypes", "unchecked" }) public static <T extends Comparable<T>> IProperty<T> getProperty(final IBlockState blockState, final String name) { for (final IProperty prop : blockState.getPropertyKeys()) { if (prop.getName().equals(name)) { return prop; } } return null; }
public static IProperty getPropertyByName(IBlockState blockState, String propertyName) { for (IProperty property : (ImmutableSet<IProperty<?>>) blockState.getProperties().keySet()) { if (property.getName().equals(propertyName)) return property; } return null; }
private static EnumFacing getStateFacing(IBlockState state) { Collection<IProperty<?>> props = state.getPropertyKeys(); for(IProperty prop : props) if(prop.getName().equals("facing")) { Object obj = state.getValue(prop); if(obj instanceof EnumFacing) return (EnumFacing) obj; } return null; }
private static NBTTagCompound getStatePropertiesTag(ImmutableMap<IProperty<?>, Comparable<?>> properties) { NBTTagCompound propertiesTag = new NBTTagCompound(); for (Map.Entry<IProperty<?>, Comparable<?>> property : properties.entrySet()) { propertiesTag.setString(property.getKey().getName(), serializeValue(property.getKey(), property.getValue())); } return propertiesTag; }
@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; } }
private static PropertyBool getBoolProperty(IBlockState blockState, String property) { UnmodifiableIterator<Entry<IProperty<?>, Comparable<?>>> unmodifiableiterator = blockState.getProperties().entrySet().iterator(); while (unmodifiableiterator.hasNext()) { // Entry<IProperty<?>, Comparable<?>> entry = unmodifiableiterator.next(); IProperty<?> iproperty = unmodifiableiterator.next().getKey(); if (iproperty instanceof PropertyBool && iproperty.getName().equals(property)) { return (PropertyBool) iproperty; } } return null; }
@Override public boolean rotateBlock(net.minecraft.world.World world, BlockPos pos, EnumFacing axis) { net.minecraft.block.state.IBlockState state = world.getBlockState(pos); for (net.minecraft.block.properties.IProperty<?> prop : state.getProperties().keySet()) { if (prop.getName().equals("axis")) { world.setBlockState(pos, state.cycleProperty(prop)); return true; } } return false; }
private void printSimpleMessage(EntityPlayer player, IBlockState state) { //noinspection ConstantConditions player.sendMessage(new TextComponentString("Block name: " + state.getBlock().getRegistryName().toString())); if (!state.getProperties().isEmpty()) { player.sendMessage(new TextComponentString("Properties:")); for (Map.Entry<IProperty<?>, Comparable<?>> prop : state.getProperties().entrySet()) { player.sendMessage(new TextComponentString(prop.getKey().getName() + " : " + prop.getValue().toString())); } } }
@Nonnull @Override public List<String> getWailaBody(ItemStack itemStack, List<String> tooltip, IWailaDataAccessor accessor, IWailaConfigHandler config) { if (config.getConfig("general.showstates")) { IBlockState actualState = accessor.getBlockState().getBlock().getActualState(accessor.getBlockState(), accessor.getWorld(), accessor.getPosition()); BlockStateContainer container = accessor.getBlock().getBlockState(); for (IProperty<?> property : container.getProperties()) { Comparable<?> value = actualState.getValue(property); tooltip.add(property.getName() + ": " + (property instanceof PropertyBool ? value == Boolean.TRUE ? TextFormatting.GREEN : TextFormatting.RED : "") + value.toString()); } } return tooltip; }