Search in sources :

Example 31 with StructureName

use of com.ldtteam.structurize.management.StructureName in project Structurize by ldtteam.

the class WindowBuildTool method initSchematicNavigation.

/**
 * Initialise the previous/next and drop down list for schematic.
 */
private void initSchematicNavigation() {
    registerButton(BUTTON_PREVIOUS_SCHEMATIC_ID, this::previousSchematic);
    registerButton(BUTTON_NEXT_SCHEMATIC_ID, this::nextSchematic);
    schematicsDropDownList = findPaneOfTypeByID(DROPDOWN_SCHEMATIC_ID, DropDownList.class);
    schematicsDropDownList.setHandler(this::onDropDownListChanged);
    schematicsDropDownList.setDataProvider(new DropDownList.DataProvider() {

        @Override
        public int getElementCount() {
            return schematics.size();
        }

        @Override
        public String getLabel(final int index) {
            final StructureName sn = new StructureName(schematics.get(index));
            return sn.getLocalizedName();
        }
    });
}
Also used : DropDownList(com.ldtteam.blockout.views.DropDownList) StructureName(com.ldtteam.structurize.management.StructureName) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

Example 32 with StructureName

use of com.ldtteam.structurize.management.StructureName in project Structurize by ldtteam.

the class WindowBuildTool method deleteClicked.

/**
 * Action performed when rename button is clicked.
 */
private void deleteClicked() {
    confirmDeleteDialog = new DialogDoneCancel(getWindow());
    confirmDeleteDialog.setHandler(this::onDialogClosed);
    final StructureName structureName = new StructureName(schematics.get(schematicsDropDownList.getSelectedIndex()));
    confirmDeleteDialog.setTitle(LanguageHandler.format("com.ldtteam.gui.structure.delete.title"));
    confirmDeleteDialog.setTextContent(LanguageHandler.format("com.ldtteam.gui.structure.delete.body", structureName.toString()));
    confirmDeleteDialog.open();
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName)

Example 33 with StructureName

use of com.ldtteam.structurize.management.StructureName in project Structurize by ldtteam.

the class WindowBuildTool method paste.

/**
 * Paste a schematic in the world.
 *
 * @param complete if complete paste or partial.
 */
private void paste(final boolean complete) {
    final String sname;
    if (Settings.instance.isStaticSchematicMode()) {
        sname = schematics.get(schematicsDropDownList.getSelectedIndex());
    } else {
        sname = schematics.get(schematicsDropDownList.getSelectedIndex());
    }
    final StructureName structureName = new StructureName(sname);
    if (structureName.getPrefix().equals(Structures.SCHEMATICS_SCAN) && ServerLifecycleHooks.getCurrentServer() == null) {
        // We need to check that the server have it too using the md5
        requestAndPlaceScannedSchematic(structureName, true, complete);
    } else {
        paste(structureName, complete);
    }
    Settings.instance.softReset();
    close();
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName)

Example 34 with StructureName

use of com.ldtteam.structurize.management.StructureName in project Structurize by ldtteam.

the class WindowBuildTool method onDialogClosed.

/**
 * handle when a dialog is closed.
 *
 * @param dialog   which is being closed.
 * @param buttonId is the id of the button used to close the dialog.
 */
public void onDialogClosed(final DialogDoneCancel dialog, final int buttonId) {
    if (dialog == confirmDeleteDialog && buttonId == DialogDoneCancel.DONE) {
        final StructureName structureName = new StructureName(schematics.get(schematicsDropDownList.getSelectedIndex()));
        if (Structures.SCHEMATICS_SCAN.equals(structureName.getPrefix()) && Structures.deleteScannedStructure(structureName)) {
            Structures.loadScannedStyleMaps();
            if (schematics.size() > 1) {
                schematicsDropDownList.selectNext();
                stylesDropDownList.setSelectedIndex(stylesDropDownList.getSelectedIndex());
            } else if (styles.size() > 1) {
                stylesDropDownList.selectNext();
            } else {
                sectionsDropDownList.selectNext();
            }
        }
    }
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName)

Example 35 with StructureName

use of com.ldtteam.structurize.management.StructureName in project minecolonies by ldtteam.

the class ClientEventHandler method handleRenderBuildTool.

/**
 * Renders building bounding boxes into the client
 *
 * @param event  The caught event
 * @param world  The world in which to render
 * @param player The player for which to render
 */
private static void handleRenderBuildTool(@NotNull final RenderWorldLastEvent event, final ClientWorld world, final PlayerEntity player) {
    if (Settings.instance.getActiveStructure() == null) {
        return;
    }
    final IColonyView colony = IColonyManager.getInstance().getClosestColonyView(world, new BlockPos(player.position()));
    if (colony == null) {
        return;
    }
    final BlockPos activePosition = Settings.instance.getPosition();
    final Map<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> newCache = new HashMap<>();
    for (final IBuildingView buildingView : colony.getBuildings()) {
        if (MinecoloniesAPIProxy.getInstance().getConfig().getClient().neighborbuildingrendering.get()) {
            if (buildingView.getBuildingType() == ModBuildings.postBox || buildingView.getBuildingType() == ModBuildings.stash) {
                continue;
            }
            final BlockPos currentPosition = buildingView.getPosition();
            if (activePosition.closerThan(currentPosition, PREVIEW_RANGE)) {
                if (blueprintCache.containsKey(currentPosition)) {
                    newCache.put(currentPosition, blueprintCache.get(currentPosition));
                    continue;
                }
                final TileEntity tile = world.getBlockEntity(buildingView.getID());
                String schematicName = buildingView.getSchematicName();
                if (tile instanceof IBlueprintDataProvider) {
                    if (!((IBlueprintDataProvider) tile).getSchematicName().isEmpty()) {
                        schematicName = ((IBlueprintDataProvider) tile).getSchematicName().replaceAll("\\d$", "");
                    }
                }
                final StructureName sn = new StructureName(Structures.SCHEMATICS_PREFIX, buildingView.getStyle(), schematicName + buildingView.getBuildingMaxLevel());
                final String structureName = sn.toString();
                final String md5 = Structures.getMD5(structureName);
                final IStructureHandler wrapper = new LoadOnlyStructureHandler(world, buildingView.getID(), structureName, new PlacementSettings(), true);
                if (!wrapper.hasBluePrint() || !wrapper.isCorrectMD5(md5)) {
                    if (alreadyRequestedStructures.contains(structureName)) {
                        continue;
                    }
                    alreadyRequestedStructures.add(structureName);
                    Log.getLogger().error("Couldn't find schematic: " + structureName + " requesting to server if possible.");
                    if (ServerLifecycleHooks.getCurrentServer() == null) {
                        Network.getNetwork().sendToServer(new SchematicRequestMessage(structureName));
                    }
                    continue;
                }
                final Blueprint blueprint = wrapper.getBluePrint();
                final Mirror mirror = buildingView.isMirrored() ? Mirror.FRONT_BACK : Mirror.NONE;
                blueprint.rotateWithMirror(BlockPosUtil.getRotationFromRotations(buildingView.getRotation()), mirror, world);
                final BlockPos primaryOffset = blueprint.getPrimaryBlockOffset();
                final BlockPos boxStartPos = currentPosition.subtract(primaryOffset);
                final BlockPos size = new BlockPos(blueprint.getSizeX(), blueprint.getSizeY(), blueprint.getSizeZ());
                final BlockPos boxEndPos = boxStartPos.offset(size).subtract(new BlockPos(1, 1, 1));
                blueprint.setRenderSource(buildingView.getID());
                if (buildingView.getBuildingLevel() < buildingView.getBuildingMaxLevel()) {
                    newCache.put(currentPosition, new Triple(blueprint, boxStartPos, boxEndPos));
                } else {
                    newCache.put(currentPosition, new Triple<>(null, boxStartPos, boxEndPos));
                }
            }
        }
    }
    blueprintCache = newCache;
    for (final Map.Entry<BlockPos, Triple<Blueprint, BlockPos, BlockPos>> nearbyBuilding : blueprintCache.entrySet()) {
        final Triple<Blueprint, BlockPos, BlockPos> buildingData = nearbyBuilding.getValue();
        final BlockPos position = nearbyBuilding.getKey();
        if (buildingData.a != null) {
            StructureClientHandler.renderStructureAtPos(buildingData.a, event.getPartialTicks(), position, event.getMatrixStack());
        }
        RenderUtils.renderBox(buildingData.b, buildingData.c, 0, 0, 1, 1.0F, 0.002D, event.getMatrixStack(), linesWithCullAndDepth.get());
    }
}
Also used : IBlueprintDataProvider(com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider) IStructureHandler(com.ldtteam.structurize.placement.structure.IStructureHandler) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint) StructureName(com.ldtteam.structurize.management.StructureName) PlacementSettings(com.ldtteam.structurize.util.PlacementSettings) Triple(org.antlr.v4.runtime.misc.Triple) TileEntity(net.minecraft.tileentity.TileEntity) SchematicRequestMessage(com.ldtteam.structurize.network.messages.SchematicRequestMessage) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) BlockPos(net.minecraft.util.math.BlockPos) LoadOnlyStructureHandler(com.minecolonies.api.util.LoadOnlyStructureHandler) IColonyView(com.minecolonies.api.colony.IColonyView) Mirror(net.minecraft.util.Mirror) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

StructureName (com.ldtteam.structurize.management.StructureName)43 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)14 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)10 BlockPos (net.minecraft.util.math.BlockPos)9 LoadOnlyStructureHandler (com.minecolonies.api.util.LoadOnlyStructureHandler)7 Nullable (org.jetbrains.annotations.Nullable)6 SchematicRequestMessage (com.ldtteam.structurize.network.messages.SchematicRequestMessage)5 IStructureHandler (com.ldtteam.structurize.placement.structure.IStructureHandler)5 TileEntity (net.minecraft.tileentity.TileEntity)5 DropDownList (com.ldtteam.blockout.views.DropDownList)4 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)4 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)4 IColonyView (com.minecolonies.api.colony.IColonyView)4 IBuildingView (com.minecolonies.api.colony.buildings.views.IBuildingView)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 StringTextComponent (net.minecraft.util.text.StringTextComponent)4 Button (com.ldtteam.blockout.controls.Button)3 IAltersBuildingFootprint (com.minecolonies.api.colony.buildings.modules.IAltersBuildingFootprint)3 Log (com.minecolonies.api.util.Log)3 Predicate (java.util.function.Predicate)3