use of net.minecraft.world.level.block.state.properties.Property in project MinecraftForge by MinecraftForge.
the class VariantBlockStateBuilder method forAllStatesExcept.
public VariantBlockStateBuilder forAllStatesExcept(Function<BlockState, ConfiguredModel[]> mapper, Property<?>... ignored) {
Set<PartialBlockstate> seen = new HashSet<>();
for (BlockState fullState : owner.getStateDefinition().getPossibleStates()) {
Map<Property<?>, Comparable<?>> propertyValues = Maps.newLinkedHashMap(fullState.getValues());
for (Property<?> p : ignored) {
propertyValues.remove(p);
}
PartialBlockstate partialState = new PartialBlockstate(owner, propertyValues, this);
if (seen.add(partialState)) {
setModels(partialState, mapper.apply(fullState));
}
}
return this;
}
use of net.minecraft.world.level.block.state.properties.Property in project SpongeCommon by SpongePowered.
the class BlockStatePropertiesGenerator method computeUsedProperties.
private Map<PropertyType, Map<Property<?>, Set<ResourceLocation>>> computeUsedProperties() {
// get all block state properties
final Map<PropertyType, Map<Property<?>, Set<ResourceLocation>>> propertyUsages = new HashMap<>();
for (final Block block : Registry.BLOCK) {
for (final Property<?> property : block.defaultBlockState().getProperties()) {
final var type = PropertyType.ofProperty(property);
if (type == null) {
Logger.warn("Unknown property type for state property {} in block {}", property, Registry.BLOCK.getKey(block));
}
propertyUsages.computeIfAbsent(type, $ -> new IdentityHashMap<>()).computeIfAbsent(property, $ -> new HashSet<>()).add(Registry.BLOCK.getKey(block));
}
}
return propertyUsages;
}
use of net.minecraft.world.level.block.state.properties.Property in project MC-Prefab by Brian-Wuest.
the class Structure method createBuildBlockFromBlockState.
/**
* Creates a build block from the current block state.
*
* @param currentState The block state.
* @param currentBlock The current block.
* @param currentPos The current position.
* @return A new Build block object.
*/
public static BuildBlock createBuildBlockFromBlockState(BlockState currentState, Block currentBlock, BlockPos currentPos, BlockPos originalPos) {
BuildBlock buildBlock = new BuildBlock();
buildBlock.setBlockDomain(currentBlock.getRegistryName().getNamespace());
buildBlock.setBlockName(currentBlock.getRegistryName().getPath());
buildBlock.setStartingPosition(Structure.getStartingPositionFromOriginalAndCurrentPosition(currentPos, originalPos));
buildBlock.blockPos = currentPos;
Collection<Property<?>> properties = currentState.getProperties();
for (Property<?> entry : properties) {
BuildProperty property = new BuildProperty();
property.setName(entry.getName());
Comparable<?> value = currentState.getValue(entry);
try {
if (currentBlock instanceof RotatedPillarBlock && property.getName().equals("axis")) {
property.setValue(((Direction.Axis) value).getSerializedName());
} else if (currentBlock instanceof CarpetBlock && property.getName().equals("color")) {
DyeColor dyeColor = (DyeColor) value;
property.setValue(dyeColor.getSerializedName());
} else if (value instanceof StringRepresentable) {
StringRepresentable stringSerializable = (StringRepresentable) value;
property.setValue(stringSerializable.getSerializedName());
} else {
property.setValue(value.toString());
}
} catch (Exception ex) {
Prefab.LOGGER.error("Unable to set property [" + property.getName() + "] to value [" + value + "] for Block [" + buildBlock.getBlockDomain() + ":" + buildBlock.getBlockName() + "].");
throw ex;
}
buildBlock.getProperties().add(property);
}
return buildBlock;
}
use of net.minecraft.world.level.block.state.properties.Property in project MC-Prefab by Brian-Wuest.
the class BuildBlock method SetBlockState.
public static BuildBlock SetBlockState(StructureConfiguration configuration, BlockPos originalPos, BuildBlock block, Block foundBlock, BlockState blockState, Direction structureDirection) {
try {
if (!block.blockStateData.equals("")) {
return BuildBlock.SetBlockStateFromTagData(configuration, originalPos, block, foundBlock, blockState, structureDirection);
}
Direction vineFacing = BuildBlock.getVineFacing(configuration, foundBlock, block, structureDirection);
Direction.Axis logFacing = BuildBlock.getBoneFacing(configuration, foundBlock, block, structureDirection);
Direction.Axis boneFacing = BuildBlock.getBoneFacing(configuration, foundBlock, block, structureDirection);
Direction leverOrientation = BuildBlock.getLeverOrientation(configuration, foundBlock, block, structureDirection);
Map<Direction, Boolean> fourWayFacings = BuildBlock.getFourWayBlockFacings(configuration, foundBlock, block, structureDirection);
Map<Direction, WallSide> wallShapes = BuildBlock.getWallFacings(configuration, foundBlock, block, structureDirection);
// expected to place the block.
if (block.getProperties().size() > 0) {
Collection<Property<?>> properties = blockState.getProperties();
// applied.
for (Property<?> property : properties) {
BuildProperty buildProperty = block.getProperty(property.getName());
// mod (or sometimes vanilla) adds properties to vanilla blocks.
if (buildProperty != null) {
try {
Optional<?> propertyValue = property.getValue(buildProperty.getValue());
if (!propertyValue.isPresent() || propertyValue.getClass().getName().equals("com.google.common.base.Absent")) {
Prefab.LOGGER.warn("Property value for property name [" + property.getName() + "] for block [" + block.getBlockName() + "] is considered Absent, figure out why.");
continue;
}
Comparable<?> comparable = property.getValueClass().cast(propertyValue.get());
comparable = BuildBlock.setComparable(comparable, foundBlock, property, configuration.houseFacing, block, propertyValue, vineFacing, logFacing, boneFacing, leverOrientation, structureDirection, fourWayFacings, wallShapes);
if (comparable == null) {
continue;
}
try {
if (blockState.getValue(property) != comparable) {
blockState = BuildBlock.setProperty(blockState, property, comparable);
}
} catch (Exception ex) {
System.out.println("Error setting properly value for property name [" + property.getName() + "] property value [" + buildProperty.getValue() + "] for block [" + block.getBlockName() + "] The default value will be used.");
}
} catch (Exception ex) {
System.out.println("Error getting properly value for property name [" + property.getName() + "] property value [" + buildProperty.getValue() + "] for block [" + block.getBlockName() + "]");
throw ex;
}
}
}
}
block.setBlockState(blockState);
return block;
} catch (Exception ex) {
System.out.println("Error setting block state for block [" + block.getBlockName() + "] for structure configuration class [" + configuration.getClass().getName() + "]");
throw ex;
}
}
use of net.minecraft.world.level.block.state.properties.Property in project MinecraftForge by MinecraftForge.
the class MultiPartBlockStateBuilder method toJson.
private static JsonObject toJson(Multimap<Property<?>, Comparable<?>> conditions, boolean useOr) {
JsonObject groupJson = new JsonObject();
for (Entry<Property<?>, Collection<Comparable<?>>> e : conditions.asMap().entrySet()) {
StringBuilder activeString = new StringBuilder();
for (Comparable<?> val : e.getValue()) {
if (activeString.length() > 0)
activeString.append("|");
activeString.append(((Property) e.getKey()).getName(val));
}
groupJson.addProperty(e.getKey().getName(), activeString.toString());
}
if (useOr) {
JsonArray innerWhen = new JsonArray();
for (Entry<String, JsonElement> entry : groupJson.entrySet()) {
JsonObject obj = new JsonObject();
obj.add(entry.getKey(), entry.getValue());
innerWhen.add(obj);
}
groupJson = new JsonObject();
groupJson.add("OR", innerWhen);
}
return groupJson;
}
Aggregations