Search in sources :

Example 26 with LiteralText

use of net.minecraft.text.LiteralText in project dynmap by webbukkit.

the class FabricServer method broadcastMessage.

@Override
public void broadcastMessage(String msg) {
    Text component = new LiteralText(msg);
    server.getPlayerManager().broadcast(component, MessageType.SYSTEM, Util.NIL_UUID);
    Log.info(stripChatColor(msg));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

Example 27 with LiteralText

use of net.minecraft.text.LiteralText in project BlockMeter by ModProg.

the class ClientMeasureBox method drawText.

/**
 * Draws a text with orientation and position
 *
 * @param stack
 * @param x
 * @param y
 * @param z
 * @param yaw
 * @param pitch
 * @param text
 * @param playerPos
 */
private void drawText(final MatrixStack stack, final double x, final double y, final double z, final float yaw, final float pitch, final String text, final Vec3d playerPos) {
    @SuppressWarnings("resource") final TextRenderer textRenderer = MinecraftClient.getInstance().textRenderer;
    final LiteralText literalText = new LiteralText(text);
    float size = 0.03f;
    final int constDist = 10;
    if (AutoConfig.getConfigHolder(ModConfig.class).getConfig().minimalLabelSize) {
        final float dist = (float) Math.sqrt((x - playerPos.x) * (x - playerPos.x) + (y - playerPos.y) * (y - playerPos.y) + (z - playerPos.z) * (z - playerPos.z));
        if (dist > constDist)
            size = dist * size / constDist;
    }
    stack.push();
    stack.translate(x, y + 0.15, z);
    stack.multiply(Vec3f.POSITIVE_Y.getDegreesQuaternion(180.0F - yaw));
    stack.multiply(Vec3f.POSITIVE_X.getDegreesQuaternion(-pitch));
    stack.scale(size, -size, 0.001f);
    final int width = textRenderer.getWidth(literalText);
    stack.translate((-width / 2), 0.0, 0.0);
    final Matrix4f model = stack.peek().getPositionMatrix();
    final BufferBuilder buffer = Tessellator.getInstance().getBuffer();
    int textColor = color.getSignColor();
    final ModConfig conf = BlockMeterClient.getConfigManager().getConfig();
    if (conf.backgroundForLabels) {
        final float[] colors = this.color.getColorComponents();
        buffer.begin(DrawMode.QUADS, VertexFormats.POSITION_COLOR);
        buffer.vertex(model, -1, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, -1, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, width, 8, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        buffer.vertex(model, width, -1, 0).color(colors[0], colors[1], colors[2], 0.8f).next();
        Tessellator.getInstance().draw();
        float[] components = color.getColorComponents();
        float luminance = (0.299f * components[0] + 0.587f * components[1] + 0.114f * components[2]);
        textColor = luminance < 0.4f ? DyeColor.WHITE.getSignColor() : DyeColor.BLACK.getSignColor();
    }
    final VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(buffer);
    textRenderer.draw(literalText, 0.0f, 0.0f, textColor, // shadow
    !conf.backgroundForLabels, // matrix
    model, // draw buffer
    immediate, // seeThrough
    true, // backgroundColor => underlineColor,
    0, // light
    15728880);
    immediate.draw();
    stack.pop();
}
Also used : Matrix4f(net.minecraft.util.math.Matrix4f) BufferBuilder(net.minecraft.client.render.BufferBuilder) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText) ModConfig(win.baruna.blockmeter.ModConfig) VertexConsumerProvider(net.minecraft.client.render.VertexConsumerProvider)

Example 28 with LiteralText

use of net.minecraft.text.LiteralText in project FabricWaystones by LordDeatHunter.

the class WaystonesEventManager method registerEvents.

public static void registerEvents() {
    ServerLifecycleEvents.SERVER_STARTED.register((server) -> {
        if (Waystones.WAYSTONE_STORAGE == null) {
            Waystones.WAYSTONE_STORAGE = new WaystoneStorage(server);
        }
    });
    ServerLifecycleEvents.SERVER_STOPPED.register((server) -> {
        Waystones.WAYSTONE_STORAGE.loadOrSaveWaystones(true);
        Waystones.WAYSTONE_STORAGE = null;
    });
    ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        ServerPlayNetworking.send(handler.player, Utils.ID("waystone_config_update"), data);
        Waystones.WAYSTONE_STORAGE.sendToPlayer(handler.player);
        Waystones.WAYSTONE_STORAGE.sendCompatData(handler.player);
    });
    ServerLifecycleEvents.SERVER_STARTING.register(WaystonesWorldgen::registerVanillaVillageWorldgen);
    ServerPlayerEvents.AFTER_RESPAWN.register((oldPlayer, newPlayer, alive) -> ((PlayerEntityMixinAccess) newPlayer).syncData());
    CommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(CommandManager.literal("waystones").then(CommandManager.literal("reload").requires(source -> source.hasPermissionLevel(1)).executes(context -> {
        Config.getInstance().loadConfig();
        PacketByteBuf data = PacketByteBufs.create();
        data.writeNbt(Config.getInstance().toNbtCompound());
        for (ServerPlayerEntity player : context.getSource().getServer().getPlayerManager().getPlayerList()) {
            ServerPlayNetworking.send(player, Utils.ID("waystone_config_update"), data);
        }
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player != null) {
            player.sendMessage(new LiteralText("§6[§eWaystones§6] §3has successfully reloaded!"), false);
        }
        return 1;
    })).then(CommandManager.literal("display").executes(context -> {
        ServerPlayerEntity player = context.getSource().getPlayer();
        if (player == null) {
            return 1;
        }
        Config.getInstance().print(player);
        return 1;
    }))));
}
Also used : LiteralText(net.minecraft.text.LiteralText) Waystones(wraith.waystones.Waystones) PlayerEntityMixinAccess(wraith.waystones.access.PlayerEntityMixinAccess) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ServerPlayerEvents(net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents) CommandRegistrationCallback(net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback) ServerPlayNetworking(net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerLifecycleEvents(net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents) PacketByteBufs(net.fabricmc.fabric.api.networking.v1.PacketByteBufs) CommandManager(net.minecraft.server.command.CommandManager) PacketByteBuf(net.minecraft.network.PacketByteBuf) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LiteralText(net.minecraft.text.LiteralText)

Example 29 with LiteralText

use of net.minecraft.text.LiteralText in project FabricWaystones by LordDeatHunter.

the class WaystoneBlockScreen method init.

@Override
protected void init() {
    super.init();
    this.nameField = new TextFieldWidget(this.textRenderer, this.x + 28, this.y + 106, 93, 10, new LiteralText("")) {

        @Override
        public boolean mouseClicked(double mouseX, double mouseY, int button) {
            boolean bl = mouseX >= (double) this.x && mouseX < (double) (this.x + this.width) && mouseY >= (double) this.y && mouseY < (double) (this.y + this.height);
            if (bl && button == 1) {
                this.setText("");
            }
            return super.mouseClicked(mouseX, mouseY, button);
        }

        @Override
        public boolean isVisible() {
            return canEdit() && page == Page.CONFIG;
        }

        @Override
        public boolean changeFocus(boolean lookForwards) {
            return isVisible() && super.changeFocus(lookForwards);
        }

        @Override
        public boolean isMouseOver(double mouseX, double mouseY) {
            return isVisible() && mouseX >= (double) this.x && mouseX < (double) (this.x + this.width) && mouseY >= (double) this.y && mouseY < (double) (this.y + this.height);
        }
    };
    this.nameField.setMaxLength(16);
    this.nameField.setEditableColor(0xFFFFFF);
    this.nameField.setDrawsBackground(false);
    this.nameField.setFocusUnlocked(true);
    String waystone = Waystones.WAYSTONE_STORAGE.getName(((WaystoneBlockScreenHandler) handler).getWaystone());
    this.nameField.setText(waystone == null ? "" : waystone);
    this.nameField.setChangedListener((s) -> {
        boolean settable = !((WaystoneBlockScreenHandler) handler).getName().equals(s);
        ToggleableButton button = ((ToggleableButton) buttons.get(4));
        if (button.isToggled() == settable) {
            button.toggle();
        }
    });
    this.addDrawableChild(this.nameField);
}
Also used : TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) LiteralText(net.minecraft.text.LiteralText)

Example 30 with LiteralText

use of net.minecraft.text.LiteralText in project FabricWaystones by LordDeatHunter.

the class Config method print.

public void print(ServerPlayerEntity player) {
    var q = new LinkedList<JsonObject>();
    q.add(toJson(configData));
    while (!q.isEmpty()) {
        var current = q.poll();
        for (var entry : current.entrySet()) {
            var key = entry.getKey();
            var value = entry.getValue();
            if (value.isJsonObject()) {
                q.add(value.getAsJsonObject());
                continue;
            }
            player.sendMessage(new LiteralText("§6[§e" + key + "§6] §3 " + value), false);
        }
    }
}
Also used : LinkedList(java.util.LinkedList) LiteralText(net.minecraft.text.LiteralText)

Aggregations

LiteralText (net.minecraft.text.LiteralText)249 Text (net.minecraft.text.Text)63 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)51 ItemStack (net.minecraft.item.ItemStack)37 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)34 TranslatableText (net.minecraft.text.TranslatableText)32 MutableText (net.minecraft.text.MutableText)28 BaseText (net.minecraft.text.BaseText)26 NbtCompound (net.minecraft.nbt.NbtCompound)24 HoverEvent (net.minecraft.text.HoverEvent)24 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)23 Screen (net.minecraft.client.gui.screen.Screen)21 ClickEvent (net.minecraft.text.ClickEvent)20 MatrixStack (net.minecraft.client.util.math.MatrixStack)19 Formatting (net.minecraft.util.Formatting)19 Items (net.minecraft.item.Items)18 Inject (org.spongepowered.asm.mixin.injection.Inject)18 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)17 List (java.util.List)16 Identifier (net.minecraft.util.Identifier)15