use of net.minecraft.block.properties.IProperty in project ForestryMC by ForestryMC.
the class MachineStateMapper method putStateModelLocations.
@Override
public Map<IBlockState, ModelResourceLocation> putStateModelLocations(Block block) {
if (!(type.getMachineProperties() instanceof IMachinePropertiesTesr)) {
for (EnumFacing facing : EnumFacing.values()) {
if (facing == EnumFacing.DOWN || facing == EnumFacing.UP) {
continue;
}
IBlockState state = block.getDefaultState().withProperty(BlockBase.FACING, facing);
LinkedHashMap<IProperty<?>, Comparable<?>> linkedhashmap = Maps.newLinkedHashMap(state.getProperties());
ResourceLocation blockLocation = Block.REGISTRY.getNameForObject(block);
String s = String.format("%s:%s", blockLocation.getResourceDomain(), blockLocation.getResourcePath());
mapStateModelLocations.put(state, new ModelResourceLocation(s, getPropertyString(linkedhashmap)));
}
}
return this.mapStateModelLocations;
}
use of net.minecraft.block.properties.IProperty in project ForestryMC by ForestryMC.
the class PluginImmersiveEngineering method postInit.
@Override
public void postInit() {
IFarmRegistry farmRegistry = ForestryAPI.farmRegistry;
ItemStack hempSeed = getItemStack("seed");
Block hempCrop = getBlock("hemp");
if (hempCrop != null) {
int seedAmount = ForestryAPI.activeMode.getIntegerSetting("squeezer.liquid.seed");
Stream<IProperty<?>> propertyStream = hempCrop.getBlockState().getProperties().stream();
IProperty age = propertyStream.filter(p -> p.getName().equals("type")).findAny().orElseGet(null);
if (hempSeed != null && hempCrop != Blocks.AIR && age != null) {
Optional bottom0 = age.parseValue("bottom0");
Optional bottom4 = age.parseValue("bottom4");
Optional top0 = age.parseValue("top0");
if (bottom0.isPresent() && top0.isPresent()) {
IBlockState defaultState = hempCrop.getDefaultState();
IBlockState planted = defaultState.withProperty(age, (Comparable) bottom0.get());
IBlockState mature = defaultState.withProperty(age, (Comparable) bottom4.get());
IBlockState topMature = defaultState.withProperty(age, (Comparable) top0.get());
farmRegistry.registerFarmables("farmWheat", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, false));
farmRegistry.registerFarmables("farmOrchard", new FarmableDoubleCrop(hempSeed, planted, mature, topMature, true));
RecipeManagers.squeezerManager.addRecipe(10, hempSeed, Fluids.SEED_OIL.getFluid(seedAmount));
}
}
}
Fluid ethanol = FluidRegistry.getFluid("ethanol");
if (ethanol != null) {
GeneratorFuel ethanolFuel = new GeneratorFuel(new FluidStack(ethanol, 1), (int) (32 * ForestryAPI.activeMode.getFloatSetting("fuel.ethanol.generator")), 4);
FuelManager.generatorFuel.put(ethanol, ethanolFuel);
}
}
use of net.minecraft.block.properties.IProperty in project GregTech by GregTechCE.
the class MetaBlocks method registerItemModelWithOverride.
@SideOnly(Side.CLIENT)
private static void registerItemModelWithOverride(Block block, Map<IProperty<?>, Comparable<?>> stateOverrides) {
for (IBlockState state : block.getBlockState().getValidStates()) {
HashMap<IProperty<?>, Comparable<?>> stringProperties = new HashMap<>(state.getProperties());
stringProperties.putAll(stateOverrides);
// noinspection ConstantConditions
ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), block.getMetaFromState(state), new ModelResourceLocation(block.getRegistryName(), statePropertiesToString(stringProperties)));
}
}
use of net.minecraft.block.properties.IProperty in project GregTech by GregTechCE.
the class PredicateConfigUtils method parseBlockStatePropertyPredicate.
private static Predicate<IBlockState> parseBlockStatePropertyPredicate(JsonObject object) {
Block block = OreConfigUtils.getBlockByName(object.get("block").getAsString());
Map<IProperty<?>, List<Object>> allowedValues = new HashMap<>();
for (IProperty<?> property : block.getBlockState().getProperties()) {
JsonElement valueElement = object.get(property.getName());
if (valueElement == null) {
continue;
}
if (valueElement.isJsonPrimitive()) {
JsonElement singleValue = valueElement;
valueElement = new JsonArray();
valueElement.getAsJsonArray().add(singleValue);
}
if (valueElement.isJsonArray()) {
ArrayList<Object> allValues = new ArrayList<>();
JsonArray valuesArray = valueElement.getAsJsonArray();
boolean isBlacklist = false;
for (JsonElement allowedValue : valuesArray) {
String elementValue = allowedValue.getAsString();
if (elementValue.startsWith("!")) {
elementValue = elementValue.substring(1);
isBlacklist = true;
}
Optional<?> parsedValue = property.parseValue(elementValue);
if (!parsedValue.isPresent()) {
throw new IllegalArgumentException("Couldn't parse property " + property.getName() + " value " + valueElement);
}
allValues.add(parsedValue.get());
}
if (isBlacklist) {
ArrayList<Object> blacklistValues = allValues;
allValues = new ArrayList<>(property.getAllowedValues());
allValues.removeAll(blacklistValues);
}
allowedValues.put(property, allValues);
}
}
return blockState -> {
for (IProperty<?> property : blockState.getPropertyKeys()) {
if (!allowedValues.containsKey(property))
// do not check unspecified properties
continue;
Object propertyValue = blockState.getValue(property);
if (!allowedValues.get(property).contains(propertyValue))
return false;
}
return true;
};
}
use of net.minecraft.block.properties.IProperty in project malmo by Microsoft.
the class MovingTargetDecoratorImplementation method isValid.
private boolean isValid(World world, BlockPos pos) {
// In bounds?
if (!blockInBounds(pos, this.arenaBounds))
return false;
// Already in path?
if (this.path.contains(pos))
return false;
// Does there need to be air above the target?
if (this.targetParams.isRequiresAirAbove() && !world.isAirBlock(pos.up()))
return false;
// Check the current block is "permeable"...
IBlockState block = world.getBlockState(pos);
List<IProperty> extraProperties = new ArrayList<IProperty>();
DrawBlock db = MinecraftTypeHelper.getDrawBlockFromBlockState(block, extraProperties);
boolean typesMatch = this.targetParams.getPermeableBlocks().getType().isEmpty();
for (BlockType bt : this.targetParams.getPermeableBlocks().getType()) {
if (db.getType() == bt) {
typesMatch = true;
break;
}
}
if (!typesMatch)
return false;
if (db.getColour() != null) {
boolean coloursMatch = this.targetParams.getPermeableBlocks().getColour().isEmpty();
for (Colour col : this.targetParams.getPermeableBlocks().getColour()) {
if (db.getColour() == col) {
coloursMatch = true;
break;
}
}
if (!coloursMatch)
return false;
}
if (db.getVariant() != null) {
boolean variantsMatch = this.targetParams.getPermeableBlocks().getVariant().isEmpty();
for (Variation var : this.targetParams.getPermeableBlocks().getVariant()) {
if (db.getVariant() == var) {
variantsMatch = true;
break;
}
}
if (!variantsMatch)
return false;
}
return true;
}
Aggregations