Search in sources :

Example 1 with BlockInfo

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;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockInfo(com.ldtteam.structurize.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) NotNull(org.jetbrains.annotations.NotNull) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with BlockInfo

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());
    }
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockInfo(com.ldtteam.structurize.util.BlockInfo) StructureName(com.ldtteam.structurize.management.StructureName) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings)

Example 3 with BlockInfo

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));
            }
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockInfo(com.ldtteam.structurize.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with BlockInfo

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;
}
Also used : VertexBuffer(net.minecraft.client.renderer.vertex.VertexBuffer) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) BlockRenderType(net.minecraft.block.BlockRenderType) BlockState(net.minecraft.block.BlockState) Random(java.util.Random) BlockInfo(com.ldtteam.structurize.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) FluidState(net.minecraft.fluid.FluidState) ReportedException(net.minecraft.crash.ReportedException)

Example 5 with BlockInfo

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;
}
Also used : AirBlock(net.minecraft.block.AirBlock) BlockInfo(com.ldtteam.structurize.util.BlockInfo) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

BlockInfo (com.ldtteam.structurize.util.BlockInfo)8 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)5 BlockPos (net.minecraft.util.math.BlockPos)5 StructureName (com.ldtteam.structurize.management.StructureName)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)2 BlockState (net.minecraft.block.BlockState)2 ItemStack (net.minecraft.item.ItemStack)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 BlueprintUtil (com.ldtteam.structures.blueprints.v1.BlueprintUtil)1 Settings (com.ldtteam.structures.helpers.Settings)1 Network (com.ldtteam.structurize.Network)1 Structurize (com.ldtteam.structurize.Structurize)1 BlockPosUtil (com.ldtteam.structurize.api.util.BlockPosUtil)1 Log (com.ldtteam.structurize.api.util.Log)1 Utils (com.ldtteam.structurize.api.util.Utils)1 ANCHOR_POS_OUTSIDE_SCHEMATIC (com.ldtteam.structurize.api.util.constant.TranslationConstants.ANCHOR_POS_OUTSIDE_SCHEMATIC)1 MAX_SCHEMATIC_SIZE_REACHED (com.ldtteam.structurize.api.util.constant.TranslationConstants.MAX_SCHEMATIC_SIZE_REACHED)1