Search in sources :

Example 6 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class WindowBuildTool method init.

private void init(final BlockPos pos, final int rot, final int groundstyle) {
    @Nullable final Blueprint structure = Settings.instance.getActiveStructure();
    this.groundstyle = groundstyle;
    if (structure != null) {
        this.rotation = Settings.instance.getRotation();
    } else if (pos != null) {
        this.pos = pos;
        Settings.instance.setPosition(pos);
        Settings.instance.setRotation(rot);
    }
    initBuildingTypeNavigation();
    initStyleNavigation();
    initSchematicNavigation();
    // Register all necessary buttons with the window.
    registerButton(BUTTON_CONFIRM, this::confirmClicked);
    registerButton(BUTTON_CANCEL, this::cancelClicked);
    registerButton(BUTTON_LEFT, this::moveLeftClicked);
    registerButton(BUTTON_MIRROR, this::mirror);
    registerButton(BUTTON_RIGHT, this::moveRightClicked);
    registerButton(BUTTON_BACKWARD, this::moveBackClicked);
    registerButton(BUTTON_FORWARD, this::moveForwardClicked);
    registerButton(BUTTON_UP, WindowBuildTool::moveUpClicked);
    registerButton(BUTTON_DOWN, WindowBuildTool::moveDownClicked);
    registerButton(BUTTON_ROTATE_RIGHT, this::rotateRightClicked);
    registerButton(BUTTON_ROTATE_LEFT, this::rotateLeftClicked);
    registerButton(BUTTON_PASTE, this::pasteComplete);
    registerButton(BUTTON_PASTE_NICE, this::pasteNice);
    registerButton(BUTTON_SHOW_INVIS, this::showInvis);
    registerButton(BUTTON_RENAME, this::renameClicked);
    registerButton(BUTTON_DELETE, this::deleteClicked);
    registerButton(BUTTON_UNDOREDO, b -> {
        close();
        new WindowUndoRedo().open();
    });
    renameButton = findPaneOfTypeByID(BUTTON_RENAME, Button.class);
    deleteButton = findPaneOfTypeByID(BUTTON_DELETE, Button.class);
    Structures.loadScannedStyleMaps();
    if (Settings.instance.isStaticSchematicMode()) {
        sections.clear();
        sections.add("schematics");
        setStructureName(Settings.instance.getStructureName());
    } else {
        sections.clear();
        final PlayerInventory inventory = this.mc.player.inventory;
        final List<String> allSections = Structures.getSections();
        for (final String section : allSections) {
            if (section.equals(Structures.SCHEMATICS_PREFIX) || section.equals(Structures.SCHEMATICS_SCAN) || hasMatchingBlock(inventory, section)) {
                sections.add(section);
            }
        }
        if (Minecraft.getInstance().player.isCreative()) {
            findPaneOfTypeByID(BUTTON_PASTE, Button.class).setVisible(true);
            findPaneOfTypeByID(BUTTON_PASTE_NICE, Button.class).setVisible(true);
        } else {
            findPaneOfTypeByID(BUTTON_PASTE, Button.class).setVisible(false);
            findPaneOfTypeByID(BUTTON_UNDOREDO, Button.class).setVisible(false);
            findPaneOfTypeByID(BUTTON_PASTE_NICE, Button.class).setVisible(false);
        }
        setStructureName(Settings.instance.getStructureName());
    }
    if (Manager.isSchematicDownloaded()) {
        Manager.setSchematicDownloaded(false);
    }
    if (!DataFixerUtils.isVanillaDF) {
        findPaneByID(LABEL_WARNING).show();
    }
    updateRotationState();
    init = false;
    changeSchematic();
}
Also used : Button(com.ldtteam.blockout.controls.Button) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) PlayerInventory(net.minecraft.entity.player.PlayerInventory) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class BlueprintHandler method drawAtListOfPositions.

/**
 * Render a blueprint at a list of points.
 *
 * @param points       the points to render it at.
 * @param partialTicks the partial ticks.
 * @param blueprint    the blueprint.
 */
public void drawAtListOfPositions(final Blueprint blueprint, final List<BlockPos> points, final MatrixStack stack, final float partialTicks) {
    if (points.isEmpty() || blueprint == null) {
        return;
    }
    Minecraft.getInstance().getProfiler().push("struct_render_multi");
    final int blueprintHash = blueprint.hashCode();
    final BlueprintRenderer rendererRef = rendererCache.get(blueprintHash);
    final BlueprintRenderer renderer = rendererRef == null ? BlueprintRenderer.buildRendererForBlueprint(blueprint) : rendererRef;
    if (rendererRef == null) {
        rendererCache.put(blueprintHash, renderer);
    }
    renderer.updateBlueprint(blueprint);
    for (final BlockPos coord : points) {
        renderer.draw(coord, stack, partialTicks);
    }
    evictTimeCache.put(blueprintHash, System.currentTimeMillis());
    Minecraft.getInstance().getProfiler().pop();
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 8 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class Settings method setRotation.

/**
 * Sets the rotation.
 *
 * @param rotation the rotation to set.
 */
public void setRotation(final int rotation) {
    int offset = rotation - this.rotation;
    this.rotation = rotation;
    if (blueprint != null) {
        blueprint.rotateWithMirror(offset == 1 || offset == -3 ? Rotation.CLOCKWISE_90 : Rotation.COUNTERCLOCKWISE_90, Mirror.NONE, Minecraft.getInstance().level);
    }
    scheduleRefresh();
}
Also used : Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 9 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class ClientEventSubscriber method renderWorldLastEvent.

/**
 * Used to catch the renderWorldLastEvent in order to draw the debug nodes for pathfinding.
 *
 * @param event the catched event.
 */
@SubscribeEvent
public static void renderWorldLastEvent(@NotNull final RenderWorldLastEvent event) {
    Settings.instance.startStructurizePass();
    OptifineCompat.getInstance().preBlueprintDraw();
    final MatrixStack matrixStack = event.getMatrixStack();
    final float partialTicks = event.getPartialTicks();
    final IRenderTypeBuffer.Impl renderBuffer = renderBuffers.bufferSource();
    final Supplier<IVertexBuilder> linesWithCullAndDepth = () -> renderBuffer.getBuffer(RenderType.lines());
    final Supplier<IVertexBuilder> linesWithoutCullAndDepth = () -> renderBuffer.getBuffer(RenderUtils.LINES_GLINT);
    final PlayerEntity player = Minecraft.getInstance().player;
    final Blueprint blueprint = Settings.instance.getActiveStructure();
    if (blueprint != null) {
        Minecraft.getInstance().getProfiler().push("struct_render");
        final BlockPos pos = Settings.instance.getPosition();
        final BlockPos posMinusOffset = pos.subtract(blueprint.getPrimaryBlockOffset());
        StructureClientHandler.renderStructure(blueprint, partialTicks, pos, matrixStack);
        renderAnchorPos(pos, matrixStack, linesWithoutCullAndDepth.get());
        RenderUtils.renderWhiteOutlineBox(posMinusOffset, posMinusOffset.offset(blueprint.getSizeX() - 1, blueprint.getSizeY() - 1, blueprint.getSizeZ() - 1), matrixStack, linesWithCullAndDepth.get());
        renderBuffer.endBatch(RenderType.lines());
        renderBuffer.endBatch(RenderUtils.LINES_GLINT);
        Minecraft.getInstance().getProfiler().pop();
    }
    if (Settings.instance.getBox() != null) {
        Minecraft.getInstance().getProfiler().push("struct_box");
        // Used to render a red box around a scan's Primary offset (primary block)
        Settings.instance.getAnchorPos().ifPresent(pos -> renderAnchorPos(pos, matrixStack, linesWithoutCullAndDepth.get()));
        RenderUtils.renderWhiteOutlineBox(Settings.instance.getBox().getA(), Settings.instance.getBox().getB(), matrixStack, linesWithoutCullAndDepth.get());
        renderBuffer.endBatch(RenderUtils.LINES_GLINT);
        Minecraft.getInstance().getProfiler().pop();
    }
    final ItemStack itemStack = player.getItemInHand(Hand.MAIN_HAND);
    if (itemStack.getItem() == ModItems.tagTool.get() && itemStack.getOrCreateTag().contains(ItemTagTool.TAG_ANCHOR_POS)) {
        final BlockPos tagAnchor = BlockPosUtil.readFromNBT(itemStack.getTag(), ItemTagTool.TAG_ANCHOR_POS);
        final TileEntity te = Minecraft.getInstance().player.level.getBlockEntity(tagAnchor);
        renderAnchorPos(tagAnchor, matrixStack, linesWithoutCullAndDepth.get());
        if (te instanceof IBlueprintDataProvider) {
            final Map<BlockPos, List<String>> tagPosList = ((IBlueprintDataProvider) te).getWorldTagPosMap();
            for (final Map.Entry<BlockPos, List<String>> entry : tagPosList.entrySet()) {
                RenderUtils.renderWhiteOutlineBox(entry.getKey(), entry.getKey(), matrixStack, linesWithoutCullAndDepth.get());
                IRenderTypeBuffer.Impl buffer = IRenderTypeBuffer.immediate(Tessellator.getInstance().getBuilder());
                RenderUtils.renderDebugText(entry.getKey(), entry.getValue(), matrixStack, true, 3, buffer);
                RenderSystem.disableDepthTest();
                buffer.endBatch();
                RenderSystem.enableDepthTest();
            }
            renderBuffer.endBatch(RenderUtils.LINES_GLINT);
        }
    }
    renderBuffer.endBatch();
    OptifineCompat.getInstance().postBlueprintDraw();
    Settings.instance.endStructurizePass();
    final Vector3d viewPosition = Minecraft.getInstance().gameRenderer.getMainCamera().getPosition();
    matrixStack.pushPose();
    matrixStack.translate(-viewPosition.x(), -viewPosition.y(), -viewPosition.z());
    HookRegistries.render(matrixStack, partialTicks);
    matrixStack.popPose();
}
Also used : IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) MatrixStack(com.mojang.blaze3d.matrix.MatrixStack) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) IVertexBuilder(com.mojang.blaze3d.vertex.IVertexBuilder) PlayerEntity(net.minecraft.entity.player.PlayerEntity) TileEntity(net.minecraft.tileentity.TileEntity) Vector3d(net.minecraft.util.math.vector.Vector3d) IRenderTypeBuffer(net.minecraft.client.renderer.IRenderTypeBuffer) BlockPos(net.minecraft.util.math.BlockPos) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 10 with Blueprint

use of com.ldtteam.structures.blueprints.v1.Blueprint in project Structurize by ldtteam.

the class Manager method generateSphere.

/**
 * Generates a hollow sphere with the specific size and adds it to the blueprint provided.
 *
 * @param height    the height.
 * @param block     the block to use.
 * @param fillBlock the fill block.
 * @param hollow    if hollow.
 * @param shape     the type of shape.
 */
private static Blueprint generateSphere(final int height, final BlockState block, final BlockState fillBlock, final boolean hollow, final Shape shape) {
    final Map<BlockPos, BlockState> posList = new HashMap<>();
    for (int y = 0; y <= height + 1; y++) {
        for (int x = 0; x <= height + 1; x++) {
            for (int z = 0; z <= height + 1; z++) {
                int sum = x * x + z * z + y * y;
                if (sum < height * height && (!hollow || sum > height * height - 2 * height)) {
                    final BlockState blockToUse = (sum > height * height - 2 * height) ? block : fillBlock;
                    if (shape == Shape.HALF_SPHERE || shape == Shape.SPHERE) {
                        addPosToList(new BlockPos(height + x, height + y, height + z), blockToUse, posList);
                        addPosToList(new BlockPos(height + x, height + y, height - z), blockToUse, posList);
                        addPosToList(new BlockPos(height - x, height + y, height + z), blockToUse, posList);
                        addPosToList(new BlockPos(height - x, height + y, height - z), blockToUse, posList);
                    }
                    if (shape == Shape.BOWL || shape == Shape.SPHERE) {
                        addPosToList(new BlockPos(height + x, height - y, height + z), blockToUse, posList);
                        addPosToList(new BlockPos(height + x, height - y, height - z), blockToUse, posList);
                        addPosToList(new BlockPos(height - x, height - y, height + z), blockToUse, posList);
                        addPosToList(new BlockPos(height - x, height - y, height - z), blockToUse, posList);
                    }
                }
            }
        }
    }
    final Blueprint blueprint = new Blueprint((short) ((height + 2) * 2), (short) ((height + 2) * 2), (short) ((height + 2) * 2));
    posList.forEach(blueprint::addBlockState);
    return blueprint;
}
Also used : BlockState(net.minecraft.block.BlockState) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) BlockPos(net.minecraft.util.math.BlockPos) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Aggregations

Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)37 BlockPos (net.minecraft.util.math.BlockPos)23 BlockState (net.minecraft.block.BlockState)13 StructureName (com.ldtteam.structurize.management.StructureName)8 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)8 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 TileEntity (net.minecraft.tileentity.TileEntity)6 Nullable (org.jetbrains.annotations.Nullable)6 BlockInfo (com.ldtteam.structurize.util.BlockInfo)5 NotNull (org.jetbrains.annotations.NotNull)5 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)4 World (net.minecraft.world.World)4 Optional (java.util.Optional)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)2 PlacementError (com.ldtteam.structurize.placement.handlers.placement.PlacementError)2 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 IColony (com.minecolonies.api.colony.IColony)2