Search in sources :

Example 1 with BuildToolPasteMessage

use of com.minecolonies.coremod.network.messages.BuildToolPasteMessage in project minecolonies by Minecolonies.

the class WindowBuildTool method requestScannedSchematic.

/**
 * Request to build a player scan.
 *
 * @param paste if it should be pasted.
 * @param complete if pasted, should it be complete.
 * @param structureName of the scan to be built.
 */
private static void requestScannedSchematic(@NotNull final StructureName structureName, final boolean paste, final boolean complete) {
    if (!Structures.isPlayerSchematicsAllowed()) {
        return;
    }
    if (Structures.hasMD5(structureName)) {
        final String md5 = Structures.getMD5(structureName.toString());
        final String serverSideName = Structures.SCHEMATICS_CACHE + '/' + md5;
        if (!Structures.hasMD5(new StructureName(serverSideName))) {
            final InputStream stream = Structure.getStream(structureName.toString());
            if (stream != null) {
                final UUID id = UUID.randomUUID();
                final byte[] structureAsByteArray = Structure.getStreamAsByteArray(stream);
                if (structureAsByteArray.length <= MAX_MESSAGE_SIZE) {
                    MineColonies.getNetwork().sendToServer(new SchematicSaveMessage(structureAsByteArray, id, 1, 1));
                } else {
                    final int pieces = structureAsByteArray.length / MAX_MESSAGE_SIZE;
                    Log.getLogger().info("BuilderTool: sending: " + pieces + " pieces with the schematic " + structureName + "(md5:" + md5 + ") to the server");
                    for (int i = 1; i <= pieces; i++) {
                        final int start = (i - 1) * MAX_MESSAGE_SIZE;
                        final int size;
                        if (i == pieces) {
                            size = structureAsByteArray.length - (start);
                        } else {
                            size = MAX_MESSAGE_SIZE;
                        }
                        final byte[] bytes = new byte[size];
                        Array.copy(structureAsByteArray, start, bytes, 0, size);
                        MineColonies.getNetwork().sendToServer(new SchematicSaveMessage(bytes, id, pieces, i));
                    }
                }
            } else {
                Log.getLogger().warn("BuilderTool: Can not load " + structureName);
            }
        } else {
            Log.getLogger().warn("BuilderTool: server does not have " + serverSideName);
        }
        if (paste) {
            MineColonies.getNetwork().sendToServer(new BuildToolPasteMessage(serverSideName, structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), false, Settings.instance.getMirror(), complete, null));
        } else {
            MineColonies.getNetwork().sendToServer(new BuildToolPlaceMessage(serverSideName, structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), false, Settings.instance.getMirror()));
        }
    } else {
        Log.getLogger().warn("BuilderTool: Can not send schematic without md5: " + structureName);
    }
}
Also used : BuildToolPlaceMessage(com.minecolonies.coremod.network.messages.BuildToolPlaceMessage) InputStream(java.io.InputStream) StructureName(com.minecolonies.coremod.colony.StructureName) SchematicSaveMessage(com.minecolonies.coremod.network.messages.SchematicSaveMessage) BuildToolPasteMessage(com.minecolonies.coremod.network.messages.BuildToolPasteMessage)

Example 2 with BuildToolPasteMessage

use of com.minecolonies.coremod.network.messages.BuildToolPasteMessage in project minecolonies by Minecolonies.

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 = Settings.instance.getStaticSchematicName();
    } else {
        sname = schematics.get(schematicsDropDownList.getSelectedIndex());
    }
    final StructureName structureName = new StructureName(sname);
    if (structureName.getPrefix().equals(Structures.SCHEMATICS_SCAN) && FMLCommonHandler.instance().getMinecraftServerInstance() == null) {
        // We need to check that the server have it too using the md5
        requestScannedSchematic(structureName, true, complete);
    } else {
        MineColonies.getNetwork().sendToServer(new BuildToolPasteMessage(structureName.toString(), structureName.toString(), Settings.instance.getPosition(), Settings.instance.getRotation(), structureName.isHut(), Settings.instance.getMirror(), complete, Settings.instance.getFreeMode()));
    }
    Settings.instance.reset();
    close();
}
Also used : StructureName(com.minecolonies.coremod.colony.StructureName) BuildToolPasteMessage(com.minecolonies.coremod.network.messages.BuildToolPasteMessage)

Aggregations

StructureName (com.minecolonies.coremod.colony.StructureName)2 BuildToolPasteMessage (com.minecolonies.coremod.network.messages.BuildToolPasteMessage)2 BuildToolPlaceMessage (com.minecolonies.coremod.network.messages.BuildToolPlaceMessage)1 SchematicSaveMessage (com.minecolonies.coremod.network.messages.SchematicSaveMessage)1 InputStream (java.io.InputStream)1