Search in sources :

Example 11 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

the class BuildToolPasteMessage method messageOnServerThread.

@Override
public void messageOnServerThread(final BuildToolPasteMessage message, final EntityPlayerMP player) {
    final StructureName sn = new StructureName(message.structureName);
    if (!Structures.hasMD5(sn)) {
        player.sendMessage(new TextComponentString("Can not build " + message.workOrderName + ": schematic missing!"));
        return;
    }
    if (player.capabilities.isCreativeMode) {
        if (message.isHut) {
            handleHut(CompatibilityUtils.getWorld(player), player, sn, message.rotation, message.pos, message.mirror);
        }
        StructureWrapper.loadAndPlaceStructureWithRotation(player.world, message.structureName, message.pos, message.rotation, message.mirror ? Mirror.FRONT_BACK : Mirror.NONE, message.complete);
        if (message.isHut) {
            @Nullable final AbstractBuilding building = ColonyManager.getBuilding(CompatibilityUtils.getWorld(player), message.pos);
            if (building != null) {
                final WorkOrderBuild workOrder = new WorkOrderBuild(building, 1);
                ConstructionTapeHelper.removeConstructionTape(workOrder, CompatibilityUtils.getWorld(player));
            }
        }
    } else if (message.freeMode != null) {
        if (player.getStatFile().readStat(StatList.getObjectUseStats(ModItems.supplyChest)) > 0) {
            LanguageHandler.sendPlayerMessage(player, "com.minecolonies.coremod.error.supplyChestAlreadyPlaced");
            return;
        }
        final List<ItemStack> stacks = new ArrayList<>();
        final int chestHeight;
        if (message.freeMode == WindowBuildTool.FreeMode.SUPPLYSHIP) {
            stacks.add(new ItemStack(ModItems.supplyChest));
            chestHeight = SUPPLY_SHIP_CHEST_HEIGHT;
        } else if (message.freeMode == WindowBuildTool.FreeMode.SUPPLYCAMP) {
            stacks.add(new ItemStack(ModItems.supplyCamp));
            chestHeight = 1;
        } else {
            chestHeight = 0;
        }
        player.addStat(StatList.getObjectUseStats(ModItems.supplyChest));
        if (InventoryUtils.removeStacksFromItemHandler(new InvWrapper(player.inventory), stacks)) {
            StructureWrapper.loadAndPlaceStructureWithRotation(player.world, message.structureName, message.pos, message.rotation, message.mirror ? Mirror.FRONT_BACK : Mirror.NONE, message.complete);
            player.getServerWorld().setBlockState(message.pos.up(chestHeight), Blocks.CHEST.getDefaultState().withProperty(BlockChest.FACING, player.getHorizontalFacing()));
            fillChest((TileEntityChest) player.getServerWorld().getTileEntity(message.pos.up(chestHeight)));
        } else {
            LanguageHandler.sendPlayerMessage(player, "item.supplyChestDeployer.missing");
        }
    }
}
Also used : WorkOrderBuild(com.minecolonies.coremod.colony.workorders.WorkOrderBuild) TileEntityChest(net.minecraft.tileentity.TileEntityChest) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) StructureName(com.minecolonies.coremod.colony.StructureName) ArrayList(java.util.ArrayList) StatList(net.minecraft.stats.StatList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack) Nullable(org.jetbrains.annotations.Nullable) TextComponentString(net.minecraft.util.text.TextComponentString) AbstractBuilding(com.minecolonies.coremod.colony.buildings.AbstractBuilding)

Example 12 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

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();
    MineColonies.proxy.openBuildToolWindow(null);
}
Also used : StructureName(com.minecolonies.coremod.colony.StructureName)

Example 13 with StructureName

use of com.minecolonies.coremod.colony.StructureName 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 14 with StructureName

use of com.minecolonies.coremod.colony.StructureName 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)

Example 15 with StructureName

use of com.minecolonies.coremod.colony.StructureName in project minecolonies by Minecolonies.

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.minecolonies.coremod.gui.structure.delete.title"));
    confirmDeleteDialog.setTextContent(LanguageHandler.format("com.minecolonies.coremod.gui.structure.delete.body", structureName.toString()));
    confirmDeleteDialog.open();
}
Also used : StructureName(com.minecolonies.coremod.colony.StructureName)

Aggregations

StructureName (com.minecolonies.coremod.colony.StructureName)16 DropDownList (com.minecolonies.blockout.views.DropDownList)2 BuildToolPasteMessage (com.minecolonies.coremod.network.messages.BuildToolPasteMessage)2 ArrayList (java.util.ArrayList)2 ItemStack (net.minecraft.item.ItemStack)2 Nullable (org.jetbrains.annotations.Nullable)2 Button (com.minecolonies.blockout.controls.Button)1 ScrollingList (com.minecolonies.blockout.views.ScrollingList)1 AbstractBuilding (com.minecolonies.coremod.colony.buildings.AbstractBuilding)1 WorkOrderBuild (com.minecolonies.coremod.colony.workorders.WorkOrderBuild)1 BuildToolPlaceMessage (com.minecolonies.coremod.network.messages.BuildToolPlaceMessage)1 SchematicRequestMessage (com.minecolonies.coremod.network.messages.SchematicRequestMessage)1 SchematicSaveMessage (com.minecolonies.coremod.network.messages.SchematicSaveMessage)1 StructureWrapper (com.minecolonies.coremod.util.StructureWrapper)1 Structure (com.minecolonies.structures.helpers.Structure)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1