use of net.minecraft.util.StringRepresentable 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;
}
Aggregations