Search in sources :

Example 26 with StructureName

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

the class BuildToolPlaceMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final PlayerEntity player = ctxIn.getSender();
    final StructureName sn = new StructureName(structureName);
    if (!Structures.hasMD5(sn)) {
        MessageUtils.format(new StringTextComponent("Can not build " + workOrderName + ": schematic missing!")).sendTo(player);
        return;
    }
    if (isHut) {
        handleHut(CompatibilityUtils.getWorldFromEntity(player), player, sn, rotation, pos, mirror, state);
    } else {
        handleDecoration(CompatibilityUtils.getWorldFromEntity(player), player, sn, workOrderName, rotation, pos, mirror, builder);
    }
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName) StringTextComponent(net.minecraft.util.text.StringTextComponent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 27 with StructureName

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

the class ClientStructureWrapper method handleSaveScanMessage.

/**
 * Handles the save message of scans.
 *
 * @param CompoundNBT compound to store.
 * @param fileName       milli seconds for fileName.
 */
public static void handleSaveScanMessage(final CompoundNBT CompoundNBT, final String fileName) {
    final StructureName structureName = new StructureName(Structures.SCHEMATICS_SCAN, "new", fileName);
    final File file = new File(new File(Minecraft.getInstance().gameDirectory, Constants.MOD_ID), structureName.toString() + Structures.SCHEMATIC_EXTENSION_NEW);
    Utils.checkDirectory(file.getParentFile());
    try (final OutputStream outputstream = new FileOutputStream(file)) {
        CompressedStreamTools.writeCompressed(CompoundNBT, outputstream);
    } catch (final IOException e) {
        LanguageHandler.sendPlayerMessage(Minecraft.getInstance().player, "item.scepterSteel.scanFailure");
        Log.getLogger().warn("Exception while trying to scan.", e);
        return;
    }
    LanguageHandler.sendPlayerMessage(Minecraft.getInstance().player, "item.scepterSteel.scanSuccess", file);
    Settings.instance.setStructureName(structureName.toString());
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) StructureName(com.ldtteam.structurize.management.StructureName) IOException(java.io.IOException) File(java.io.File)

Example 28 with StructureName

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

the class WindowShapeTool method save.

/**
 * Saves the current shape to the server.
 * @return A name that can be used to place it.
 */
protected StructureName save() {
    final ByteArrayOutputStream stream = new ByteArrayOutputStream();
    BlueprintUtil.writeToStream(stream, Settings.instance.getActiveStructure());
    // cache it locally...
    Structures.handleSaveSchematicMessage(stream.toByteArray(), true);
    if (!Minecraft.getInstance().hasSingleplayerServer()) {
        // and also on the server if needed
        Network.getNetwork().sendToServer(new GenerateAndSaveMessage(Settings.instance.getPosition(), Settings.instance.getLength(), Settings.instance.getWidth(), Settings.instance.getHeight(), Settings.instance.getFrequency(), Settings.instance.getEquation(), Settings.instance.getShape(), Settings.instance.getBlock(true), Settings.instance.getBlock(false), Settings.instance.isHollow(), BlockUtils.getRotation(Settings.instance.getRotation()), Settings.instance.getMirror()));
    }
    // hopefully that is true, since they should be using the same algorithm to do it...
    return new StructureName(Structures.SCHEMATICS_CACHE + Structures.SCHEMATICS_SEPARATOR + StructureUtils.calculateMD5(stream.toByteArray()));
}
Also used : GenerateAndSaveMessage(com.ldtteam.structurize.network.messages.GenerateAndSaveMessage) StructureName(com.ldtteam.structurize.management.StructureName) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 29 with StructureName

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

the class WindowStructureNameEntry method onButtonClicked.

@Override
public void onButtonClicked(@NotNull final Button button) {
    if (button.getID().equals(BUTTON_DONE)) {
        final String name = inputName.getText();
        if (!name.isEmpty()) {
            final StructureName newStructureName = Structures.renameScannedStructure(structureName, name);
            if (newStructureName != null) {
                Settings.instance.setStructureName(newStructureName.toString());
            }
        }
    } else if (!button.getID().equals(BUTTON_CANCEL)) {
        return;
    }
    close();
    Structurize.proxy.openBuildToolWindow(null, GROUNDSTYLE_RELATIVE);
}
Also used : StructureName(com.ldtteam.structurize.management.StructureName)

Example 30 with StructureName

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

the class WindowBuildTool method updateSchematics.

/**
 * Update the list a available schematics.
 */
private void updateSchematics() {
    String schematic = "";
    if (schematicsDropDownList.getSelectedIndex() > -1 && schematicsDropDownList.getSelectedIndex() < schematics.size()) {
        schematic = schematics.get(schematicsDropDownList.getSelectedIndex());
    }
    final String currentSchematic = schematic.isEmpty() ? "" : (new StructureName(schematic)).getSchematic();
    final String section = sections.get(sectionsDropDownList.getSelectedIndex());
    final String style = styles.get(stylesDropDownList.getSelectedIndex());
    schematics = Structures.getSchematicsFor(section, style);
    int newIndex = -1;
    for (int i = 0; i < schematics.size(); i++) {
        final StructureName sn = new StructureName(schematics.get(i));
        if (sn.getSchematic().equals(currentSchematic)) {
            newIndex = i;
            break;
        }
    }
    if (newIndex == -1) {
        newIndex = 0;
    }
    final boolean enabled;
    enabled = schematics.size() > 1;
    findPaneOfTypeByID(BUTTON_PREVIOUS_SCHEMATIC_ID, Button.class).setEnabled(enabled);
    findPaneOfTypeByID(DROPDOWN_SCHEMATIC_ID, DropDownList.class).setEnabled(enabled);
    findPaneOfTypeByID(BUTTON_NEXT_SCHEMATIC_ID, Button.class).setEnabled(enabled);
    schematicsDropDownList.setSelectedIndex(newIndex);
}
Also used : Button(com.ldtteam.blockout.controls.Button) StructureName(com.ldtteam.structurize.management.StructureName) DropDownList(com.ldtteam.blockout.views.DropDownList) Blueprint(com.ldtteam.structures.blueprints.v1.Blueprint)

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