use of com.ldtteam.structurize.util.BlockInfo in project minecolonies by Minecolonies.
the class WorkerUtil method findFirstLevelSign.
/**
* Find the first level in a structure and return it.
*
* @param structure the structure to scan.
* @return the position of the sign.
*/
@Nullable
public static BlockPos findFirstLevelSign(final Blueprint structure, final BlockPos pos) {
for (int j = 0; j < structure.getSizeY(); j++) {
for (int k = 0; k < structure.getSizeZ(); k++) {
for (int i = 0; i < structure.getSizeX(); i++) {
@NotNull final BlockPos localPos = new BlockPos(i, j, k);
final BlockInfo te = structure.getBlockInfoAsMap().get(localPos);
if (te != null) {
final CompoundNBT teData = te.getTileEntityData();
if (teData != null && teData.getString(LEVEL_SIGN_FIRST_ROW).equals(LEVEL_SIGN_TEXT)) {
// try to make an anchor in 0,0,0 instead of the middle of the structure
return pos.subtract(structure.getPrimaryBlockOffset()).offset(localPos);
}
}
}
}
}
return null;
}
use of com.ldtteam.structurize.util.BlockInfo in project minecolonies by Minecolonies.
the class AbstractSchematicProvider method unsafeUpdateTEDataFromSchematic.
/**
* Load the schematic data from the TE schematic name, if it's a reattempt, calculate the name from the building (backup).
* Might throw exceptions if data is invalid.
*/
private void unsafeUpdateTEDataFromSchematic(final TileEntityColonyBuilding te) {
final String structureName;
if (te.getSchematicName().isEmpty()) {
structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, this.getSchematicName() + Math.max(1, buildingLevel)).toString();
} else {
structureName = new StructureName(Structures.SCHEMATICS_PREFIX, style, te.getSchematicName()).toString();
}
final LoadOnlyStructureHandler structure = new LoadOnlyStructureHandler(colony.getWorld(), getPosition(), structureName, new PlacementSettings(), true);
final Blueprint blueprint = structure.getBluePrint();
blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(getRotation()), isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE, colony.getWorld());
final BlockInfo info = blueprint.getBlockInfoAsMap().getOrDefault(blueprint.getPrimaryBlockOffset(), null);
if (info.getTileEntityData() != null) {
te.readSchematicDataFromNBT(info.getTileEntityData());
}
}
use of com.ldtteam.structurize.util.BlockInfo in project Structurize by ldtteam.
the class Blueprint method buildBlockInfoCaches.
/**
* Build the caches.
*/
private void buildBlockInfoCaches() {
cacheBlockInfo = new ArrayList<>(getVolume());
cacheBlockInfoMap = new HashMap<>(getVolume());
cacheEntitiesMap = new HashMap<>(getEntities().length);
for (short y = 0; y < this.sizeY; y++) {
for (short z = 0; z < this.sizeZ; z++) {
for (short x = 0; x < this.sizeX; x++) {
final BlockPos tempPos = new BlockPos(x, y, z);
final BlockInfo blockInfo = new BlockInfo(tempPos, palette.get(structure[y][z][x] & 0xFFFF), tileEntities[y][z][x]);
cacheBlockInfo.add(blockInfo);
cacheBlockInfoMap.put(tempPos, blockInfo);
cacheEntitiesMap.put(tempPos, Arrays.stream(this.getEntities()).filter(data -> data != null && isAtPos(data, tempPos)).toArray(CompoundNBT[]::new));
}
}
}
}
use of com.ldtteam.structurize.util.BlockInfo in project Structurize by ldtteam.
the class BlueprintRenderer method init.
private void init() {
clearVertexBuffers();
entities = BlueprintUtils.instantiateEntities(blockAccess.getBlueprint(), blockAccess);
tileEntities = BlueprintUtils.instantiateTileEntities(blockAccess.getBlueprint(), blockAccess);
final BlockRendererDispatcher blockRendererDispatcher = Minecraft.getInstance().getBlockRenderer();
final Random random = new Random();
final MatrixStack matrixStack = new MatrixStack();
final List<BlockInfo> blocks = blockAccess.getBlueprint().getBlockInfoAsList();
final Map<RenderType, VertexBuffer> newVertexBuffers = blockVertexBuffersFactory.get();
for (final RenderType renderType : RenderType.chunkBufferLayers()) {
final BufferBuilder buffer = new BufferBuilder(renderType.bufferSize());
buffer.begin(renderType.mode(), renderType.format());
for (final BlockInfo blockInfo : blocks) {
try {
BlockState state = blockInfo.getState();
if ((state.getBlock() == ModBlocks.blockSubstitution.get() && Settings.instance.renderLightPlaceholders()) || state.getBlock() == ModBlocks.blockTagSubstitution.get()) {
state = Blocks.AIR.defaultBlockState();
}
if (state.getBlock() == ModBlocks.blockFluidSubstitution.get()) {
state = Minecraft.getInstance().level != null ? BlockUtils.getFluidForDimension(Minecraft.getInstance().level) : Blocks.WATER.defaultBlockState();
}
final BlockPos blockPos = blockInfo.getPos();
final FluidState fluidState = state.getFluidState();
matrixStack.pushPose();
matrixStack.translate(blockPos.getX(), blockPos.getY(), blockPos.getZ());
if (state.getRenderShape() != BlockRenderType.INVISIBLE && RenderTypeLookup.canRenderInLayer(state, renderType)) {
blockRendererDispatcher.renderModel(state, blockPos, blockAccess, matrixStack, buffer, true, random, EmptyModelData.INSTANCE);
}
if (!fluidState.isEmpty() && RenderTypeLookup.canRenderInLayer(fluidState, renderType)) {
FluidRenderer.render(blockAccess, blockPos, buffer, fluidState);
}
matrixStack.popPose();
} catch (final ReportedException e) {
LOGGER.error("Error while trying to render structure part: " + e.getMessage(), e.getCause());
}
}
buffer.end();
OptifineCompat.getInstance().beforeBuilderUpload(buffer);
newVertexBuffers.get(renderType).upload(buffer);
}
vertexBuffers = newVertexBuffers;
}
use of com.ldtteam.structurize.util.BlockInfo in project Structurize by ldtteam.
the class Blueprint method getItem.
/**
* Calculate the item needed to place the current block in the structure.
*
* @param pos the pos its at.
* @return an item or null if not initialized.
*/
@Nullable
public Item getItem(final BlockPos pos) {
@Nullable final BlockInfo info = this.getBlockInfoAsMap().getOrDefault(pos, null);
if (info == null || info.getState() == null || info.getState().getBlock() instanceof AirBlock || info.getState().getMaterial().isLiquid()) {
return null;
}
final ItemStack stack = BlockUtils.getItemStackFromBlockState(info.getState());
if (!ItemStackUtils.isEmpty(stack)) {
return stack.getItem();
}
return null;
}
Aggregations