Search in sources :

Example 1 with BitmapFont

use of eu.pb4.mapcanvas.impl.font.BitmapFont in project map-canvas-api by Patbox.

the class TestMod method onInitialize.

public void onInitialize() {
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> {
        dispatcher.register(literal("test").then(argument("dir", IntegerArgumentType.integer(0, Direction.values().length)).then(argument("rot", IntegerArgumentType.integer(0, 4)).executes(this::test))));
        dispatcher.register(literal("setfps").then(argument("fps", IntegerArgumentType.integer(1)).executes((ctx) -> {
            this.msPerFrame = 1000 / IntegerArgumentType.getInteger(ctx, "fps");
            return 0;
        })));
        dispatcher.register(literal("saveimage").executes((ctx -> {
            var image = CanvasUtils.toImage(this.lastImage);
            try {
                ImageIO.write(image, "png", Files.newOutputStream(FabricLoader.getInstance().getGameDir().resolve("output.png"), StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.CREATE));
            } catch (IOException e) {
                e.printStackTrace();
            }
            return 0;
        })));
    });
    ServerPlayConnectionEvents.JOIN.register((ServerPlayNetworkHandler handler, PacketSender sender, MinecraftServer server) -> {
        this.canvas.addPlayer(handler);
    });
    ServerPlayConnectionEvents.DISCONNECT.register((ServerPlayNetworkHandler handler, MinecraftServer server) -> {
        this.canvas.removePlayer(handler);
    });
    try {
        var image = ImageIO.read(new URL("https://cdn.discordapp.com/attachments/552976908070027270/854881217950122024/tinypotato.png"));
        for (int i = 0; i < 10; i++) {
            long start = System.currentTimeMillis();
            this.tater = CanvasImage.from(image);
            System.out.println("Buildin time passed = " + (System.currentTimeMillis() - start));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        this.logo = CanvasImage.from(ImageIO.read(Files.newInputStream(FabricLoader.getInstance().getModContainer("map-canvas-api").get().getPath("assets/icon.png"))));
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        var vanillaZip = PolymerUtils.getClientJar();
        var compPath = FabricLoader.getInstance().getGameDir().resolve("coml.zip");
        var unsPath = FabricLoader.getInstance().getGameDir().resolve("uns.zip");
        var vanillaJsonPath = FabricLoader.getInstance().getGameDir().resolve("../vanilla-font-json.zip");
        if (!Files.exists(compPath)) {
            FileUtils.copyURLToFile(new URL("https://github.com/Compliance-Resource-Pack/Compliance-Java-32x/releases/download/beta-20/Compliance-32x-Java-Beta-20.zip"), compPath.toFile(), 10000, 10000);
        }
        if (!Files.exists(unsPath)) {
            FileUtils.copyURLToFile(new URL("https://media.forgecdn.net/files/3354/621/Unsanded-1.1.zip"), unsPath.toFile(), 10000, 10000);
        }
        var hdPack = new ZipFile(compPath.toFile());
        var unsPack = new ZipFile(unsPath.toFile());
        var jsonPack = new ZipFile(vanillaJsonPath.toFile());
        this.font = FontUtils.fromVanillaFormat(new Identifier("minecraft:default"), vanillaZip);
        this.fontHd = FontUtils.fromVanillaFormat(new Identifier("minecraft:default"), hdPack, vanillaZip);
        this.fontUnsanded = FontUtils.fromVanillaFormat(new Identifier("minecraft:default"), unsPack, jsonPack);
        var path = FabricLoader.getInstance().getGameDir().resolve("fonts_export");
        Files.createDirectories(path);
        {
            var stream = new FileOutputStream(path.resolve("vanilla.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) this.font, stream);
            stream.close();
        }
        {
            var stream = new FileOutputStream(path.resolve("unsanded.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) this.fontUnsanded, stream);
            stream.close();
        }
        {
            var stream = new FileOutputStream(path.resolve("alt.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) FontUtils.fromVanillaFormat(new Identifier("minecraft:alt"), vanillaZip), stream);
            stream.close();
        }
        {
            var stream = new FileOutputStream(path.resolve("illageralt.mcaf").toFile());
            RawBitmapFontSerializer.write((BitmapFont) FontUtils.fromVanillaFormat(new Identifier("minecraft:illageralt"), vanillaZip), stream);
            stream.close();
        }
        vanillaZip.close();
        hdPack.close();
        unsPack.close();
        jsonPack.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
    } catch (Exception e) {
        e.printStackTrace();
    }
    ServerLifecycleEvents.SERVER_STARTED.register((s) -> {
        this.setCurrentRenderer(this.menuRenderer);
        this.renderers.add(new Pair<>("TaterDemo", new TaterDemoRenderer(this.tater, this.fontHd, this.logo)));
        this.renderers.add(new Pair<>("SimpleSurface", new SurfaceRenderer()));
        this.renderers.add(new Pair<>("Raycast", new RaycastRenderer(s)));
        if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
            this.renderers.add(new Pair<>("Client Framebuffer", new ClientRenderer()));
        }
        this.startUpdateThread();
    });
    ServerLifecycleEvents.SERVER_STOPPED.register((s) -> {
        this.setCurrentRenderer(this.menuRenderer);
        this.renderers.clear();
        this.activeRenderer = false;
    });
}
Also used : PacketSender(net.fabricmc.fabric.api.networking.v1.PacketSender) ServerPlayNetworkHandler(net.minecraft.server.network.ServerPlayNetworkHandler) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) MinecraftServer(net.minecraft.server.MinecraftServer) Identifier(net.minecraft.util.Identifier) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) BitmapFont(eu.pb4.mapcanvas.impl.font.BitmapFont)

Aggregations

BitmapFont (eu.pb4.mapcanvas.impl.font.BitmapFont)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 ZipFile (java.util.zip.ZipFile)1 PacketSender (net.fabricmc.fabric.api.networking.v1.PacketSender)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerPlayNetworkHandler (net.minecraft.server.network.ServerPlayNetworkHandler)1 Identifier (net.minecraft.util.Identifier)1