@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(); }
private <T extends Comparable<T>> IBlockState setProperty(IBlockState state, IProperty<T> prop, String valueString) { com.google.common.base.Optional<T> value = prop.parseValue(valueString); if (value.isPresent()) { state = state.withProperty(prop, value.get()); } return state; }
/** * This method is just a workaround for wildcards. Only to be used internally. */ private <T extends Comparable<T>> IBlockState withProperty(final IBlockState state, final IProperty<T> prop, final String value){ return state.withProperty(prop, prop.parseValue(value).get()); }
@Nullable private static <T extends Comparable<T>> IBlockState getStateWithValue(IBlockState baseState, IProperty<T> property, String valueString) { Optional<T> value = property.parseValue(valueString); if (value.isPresent()) { return baseState.withProperty(property, value.get()); } return null; }
private static <T extends Comparable<T>> Optional<T> getValueHelper(IProperty<T> property, String valueString) { return toJUtilOptional(property.parseValue(valueString)); }
@Override public IBlockState build() { if(!Block.REGISTRY.containsKey(this.rLoc)) throw new IllegalArgumentException("No block found for resource location "+this.rLoc); final Block block = Block.REGISTRY.getObject(this.rLoc); final BlockStateContainer container = block.getBlockState(); IBlockState state = block.getDefaultState(); final Iterator<Entry<String, String>> it = this.properties.entrySet().iterator(); while(it.hasNext()){ final Entry<String, String> entry = it.next(); final IProperty<?> prop = container.getProperty(entry.getKey()); if(prop == null){ LogHelper.error("No property "+entry.getKey()+" found for block "+this.rLoc+". Skipping it."); it.remove(); continue; } if(!prop.parseValue(entry.getValue()).isPresent()){ LogHelper.error("Value "+entry.getValue()+" is not valid for property "+entry.getKey()+". Skipping it."); continue; } state = this.withProperty(state, prop, entry.getValue()); } return state; }
public static IBlockState parseBlockStateDefinition(JsonObject object) { Block block = getBlockByName(object.get("block").getAsString()); IBlockState blockState = block.getDefaultState(); for(IProperty<?> property : block.getBlockState().getProperties()) { JsonElement valueElement = object.get(property.getName()); if(valueElement != null && valueElement.isJsonPrimitive()) { String stringValue = valueElement.getAsString(); Optional<?> parsedValue = property.parseValue(stringValue); if(!parsedValue.isPresent()) { throw new IllegalArgumentException("Couldn't parse property " + property.getName() + " value " + valueElement); } //fuck java @SuppressWarnings("UnnecessaryLocalVariable") IProperty areYouFuckingSerious = property; Comparable fuckJava = (Comparable) parsedValue.get(); //noinspection unchecked blockState = blockState.withProperty(areYouFuckingSerious, fuckJava); } } return blockState; }
isBlacklist = true; Optional<?> parsedValue = property.parseValue(elementValue); if(!parsedValue.isPresent()) { throw new IllegalArgumentException("Couldn't parse property " + property.getName() + " value " + valueElement);
public static IBlockState parseState(String blockInfo) { String[] split = blockInfo.split("\\["); split[1] = split[1].substring(0, split[1].lastIndexOf("]")); // Make sure brackets are removed from state Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(split[0])); // Find the block if (block == Blocks.AIR) return Blocks.AIR.getDefaultState(); // The block is air, so we're looking at invalid data BlockStateContainer blockState = block.getBlockState(); IBlockState returnState = blockState.getBaseState(); // Force our values into the state String[] stateValues = split[1].split(","); // Splits up each value for (String value : stateValues) { String[] valueSplit = value.split("="); // Separates property and value IProperty property = blockState.getProperty(valueSplit[0]); if (property != null) returnState = returnState.withProperty(property, (Comparable) property.parseValue(valueSplit[1]).get()); // Force the property into the state } return returnState; } }
Optional bottom0 = age.parseValue("bottom0"); Optional bottom4 = age.parseValue("bottom4"); Optional top0 = age.parseValue("top0"); if (bottom0.isPresent() && top0.isPresent()) { IBlockState defaultState = hempCrop.getDefaultState();
@SuppressWarnings( { "unchecked", "rawtypes" } ) private static IBlockState withState( final IBlockState state, final Block blk, final String[] nameval ) { final IProperty prop = blk.getBlockState().getProperty( nameval[0] ); if ( prop == null ) { Log.info( nameval[0] + " is not a valid property for " + Block.REGISTRY.getNameForObject( blk ) ); return state; } final Optional pv = prop.parseValue( nameval[1] ); if ( pv.isPresent() ) { return state.withProperty( prop, (Comparable) pv.get() ); } else { Log.info( nameval[1] + " is not a valid value of " + nameval[0] + " for " + Block.REGISTRY.getNameForObject( blk ) ); return state; } }