Search in sources :

Example 86 with Text

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

the class WaystoneScrollItem method use.

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) {
    ItemStack stack = user.getStackInHand(hand);
    NbtCompound tag = stack.getNbt();
    if (tag == null || !tag.contains("waystones")) {
        return TypedActionResult.fail(stack);
    }
    NbtList list = tag.getList("waystones", 8);
    int learned = 0;
    HashSet<String> toLearn = new HashSet<>();
    for (int i = 0; i < list.size(); ++i) {
        String hash = list.getString(i);
        if (Waystones.WAYSTONE_STORAGE != null && Waystones.WAYSTONE_STORAGE.containsHash(hash) && !((PlayerEntityMixinAccess) user).hasDiscoveredWaystone(hash)) {
            var waystone = Waystones.WAYSTONE_STORAGE.getWaystoneEntity(hash);
            if (waystone.getOwner() == null) {
                waystone.setOwner(user);
            }
            toLearn.add(hash);
            ++learned;
        }
    }
    Text text;
    if (learned > 0) {
        if (learned > 1) {
            text = new TranslatableText("waystones.learned.multiple", new LiteralText(String.valueOf(learned)).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.learned.multiple.arg_color").getString()))));
        } else {
            text = new TranslatableText("waystones.learned.single");
        }
        ((PlayerEntityMixinAccess) user).discoverWaystones(toLearn);
        if (!user.isCreative()) {
            stack.decrement(1);
        }
    } else {
        text = new TranslatableText("waystones.learned.none");
        stack.setNbt(null);
    }
    if (!world.isClient) {
        user.sendMessage(text, false);
    }
    if (stack.isEmpty()) {
        user.setStackInHand(hand, ItemStack.EMPTY);
    }
    stack = user.getStackInHand(hand);
    return TypedActionResult.success(stack, world.isClient());
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) PlayerEntityMixinAccess(wraith.waystones.access.PlayerEntityMixinAccess) NbtCompound(net.minecraft.nbt.NbtCompound) NbtList(net.minecraft.nbt.NbtList) LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) NbtString(net.minecraft.nbt.NbtString) ItemStack(net.minecraft.item.ItemStack) HashSet(java.util.HashSet) LiteralText(net.minecraft.text.LiteralText)

Example 87 with Text

use of net.minecraft.text.Text in project BleachHack by BleachDrinker420.

the class CmdCustomSign method onCommand.

@Override
public void onCommand(String alias, String[] args) {
    if (args.length == 0) {
        throw new CmdSyntaxException();
    }
    NoRender noRender = ModuleManager.getModule(NoRender.class);
    if (args[0].equalsIgnoreCase("list")) {
        String s = "Sign Text:";
        for (Text text : noRender.signText) {
            s += "\n\u00a77" + text.getString();
        }
        BleachLogger.info(s);
        return;
    }
    String arg = args[0].toLowerCase(Locale.ENGLISH);
    boolean all = arg.equals("all");
    Text text = new LiteralText(String.join(" ", Arrays.asList(args).subList(1, args.length)));
    boolean[] linesToChange = new boolean[] { arg.equals("line1") || all, arg.equals("line2") || all, arg.equals("line3") || all, arg.equals("line4") || all };
    JsonArray json = new JsonArray();
    for (int i = 0; i < 4; i++) {
        if (linesToChange[i]) {
            noRender.signText[i] = text;
            json.add(noRender.signText[i].getString());
        }
    }
    BleachFileHelper.saveMiscSetting("customSignText", json);
    BleachLogger.info("Changed sign text!");
}
Also used : JsonArray(com.google.gson.JsonArray) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) NoRender(org.bleachhack.module.mods.NoRender) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) LiteralText(net.minecraft.text.LiteralText)

Example 88 with Text

use of net.minecraft.text.Text in project BleachHack by BleachDrinker420.

the class CmdNBT method onCommand.

@Override
public void onCommand(String alias, String[] args) throws Exception {
    if (args.length == 0) {
        throw new CmdSyntaxException();
    }
    if (args[0].equalsIgnoreCase("get")) {
        if (args.length != 2) {
            throw new CmdSyntaxException();
        }
        NbtCompound nbt = getNbt(args[1]);
        if (nbt != null) {
            String stringNbt = NbtHelper.toPrettyPrintedString(nbt);
            Text copy = new LiteralText("\u00a7e\u00a7l<COPY>").styled(s -> s.withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stringNbt)).withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new LiteralText("Copy the nbt of this item to your clipboard"))));
            BleachLogger.info(new LiteralText("\u00a76\u00a7lNBT: ").append(copy).append("\u00a76\n" + stringNbt));
        }
    } else if (args[0].equalsIgnoreCase("copy")) {
        if (args.length != 2) {
            throw new CmdSyntaxException();
        }
        NbtCompound nbt = getNbt(args[1]);
        if (nbt != null) {
            mc.keyboard.setClipboard(nbt.toString());
            BleachLogger.info("\u00a76Copied\n\u00a7f" + NbtHelper.toPrettyPrintedString(nbt) + "\n\u00a76to clipboard.");
        }
    } else if (args[0].equalsIgnoreCase("set")) {
        if (!mc.interactionManager.getCurrentGameMode().isCreative()) {
            BleachLogger.error("You must be in creative mode to set NBT!");
            return;
        }
        if (args.length < 2) {
            throw new CmdSyntaxException();
        }
        ItemStack item = mc.player.getMainHandStack();
        item.setNbt(StringNbtReader.parse(StringUtils.join(ArrayUtils.subarray(args, 1, args.length), ' ')));
        BleachLogger.info("\u00a76Set NBT of " + item.getItem().getName().getString() + " to\n" + BleachJsonHelper.formatJson(item.getNbt().toString()));
    } else if (args[0].equalsIgnoreCase("wipe")) {
        if (!mc.interactionManager.getCurrentGameMode().isCreative()) {
            BleachLogger.error("You must be in creative mode to wipe NBT!");
            return;
        }
        mc.player.getMainHandStack().setNbt(new NbtCompound());
    } else {
        throw new CmdSyntaxException();
    }
}
Also used : HoverEvent(net.minecraft.text.HoverEvent) CmdSyntaxException(org.bleachhack.command.exception.CmdSyntaxException) NbtCompound(net.minecraft.nbt.NbtCompound) ClickEvent(net.minecraft.text.ClickEvent) LiteralText(net.minecraft.text.LiteralText) Text(net.minecraft.text.Text) ItemStack(net.minecraft.item.ItemStack) LiteralText(net.minecraft.text.LiteralText)

Example 89 with Text

use of net.minecraft.text.Text in project Moonfix by Kingdom-of-Moon.

the class InputEntry method render.

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
    // text
    TextRenderer textRenderer = client.textRenderer;
    int posY = y + entryHeight / 2;
    if (this.field.isFocused() && this.inputType == ConfigManager.InputType.HEX_COLOR) {
        Text text = new LiteralText("").append(this.title).append(" (").append(this.field.getText()).append(")");
        textRenderer.draw(matrices, text, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
    } else {
        textRenderer.draw(matrices, this.title, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
    }
    // reset button
    this.reset.x = x + 260;
    this.reset.y = y;
    this.reset.active = !this.config.configValue.equals(this.config.defaultValue + "");
    this.reset.render(matrices, mouseX, mouseY, tickDelta);
    // text field
    this.field.y = y + 2;
    // focused size
    int extraWidth = 0;
    if (this.field.isFocused() && !field.getText().isBlank())
        extraWidth = MathHelper.clamp(textRenderer.getWidth(field.getText()) - 50, 0, 177);
    // set size
    this.field.setWidth(76 + extraWidth);
    this.field.x = x + 177 - extraWidth;
    // set text color
    int color = 0xFFFFFF;
    if (!this.config.configValue.equals(this.initValue + ""))
        if (this.inputType == ConfigManager.InputType.HEX_COLOR)
            color = hexToInt(this.field.getText());
        else
            color = ConfigManager.ACCENT_COLOR.apply(Style.EMPTY).getColor().getRgb();
    if (!inputType.validator.test(field.getText())) {
        color = 0xFF5555;
    }
    this.field.setEditableColor(color);
    // render
    this.field.render(matrices, mouseX, mouseY, tickDelta);
}
Also used : LiteralText(net.minecraft.text.LiteralText) TranslatableText(net.minecraft.text.TranslatableText) Text(net.minecraft.text.Text) TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText)

Example 90 with Text

use of net.minecraft.text.Text in project Moonfix by Kingdom-of-Moon.

the class SignBlockEntityRendererMixin method renderModel.

// sign scaling
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/model/ModelPart;render(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;II)V", shift = At.Shift.BEFORE), method = "render(Lnet/minecraft/block/entity/SignBlockEntity;FLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;II)V", locals = LocalCapture.CAPTURE_FAILHARD)
private void renderModel(SignBlockEntity signBlockEntity, float f, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i, int j, CallbackInfo ci, BlockState blockState, float g, SignType signType, SignBlockEntityRenderer.SignModel signModel, SpriteIdentifier h, VertexConsumer vertexConsumer) {
    if (!(boolean) Config.SIGN_SCALE.value)
        return;
    // text len
    float max = 90;
    OrderedText[] texts = signBlockEntity.updateSign(MinecraftClient.getInstance().shouldFilterText(), Text::asOrderedText);
    for (OrderedText text : texts) max = Math.max(this.textRenderer.getWidth(text), max);
    max = (max + 6) / 96f;
    if (max <= 1.01f)
        return;
    // stick
    boolean wasStickVisible = signModel.stick.visible;
    signModel.stick.visible = false;
    // scale
    matrixStack.push();
    matrixStack.scale(max, 1.01f, 1.01f);
    // render
    signModel.root.render(matrixStack, vertexConsumer, i, j);
    matrixStack.pop();
    signModel.stick.visible = wasStickVisible;
}
Also used : OrderedText(net.minecraft.text.OrderedText) OrderedText(net.minecraft.text.OrderedText) Text(net.minecraft.text.Text) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Text (net.minecraft.text.Text)108 LiteralText (net.minecraft.text.LiteralText)70 TranslatableText (net.minecraft.text.TranslatableText)35 Inject (org.spongepowered.asm.mixin.injection.Inject)14 ArrayList (java.util.ArrayList)13 ItemStack (net.minecraft.item.ItemStack)12 MinecraftClient (net.minecraft.client.MinecraftClient)11 MutableText (net.minecraft.text.MutableText)10 Formatting (net.minecraft.util.Formatting)10 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)9 List (java.util.List)7 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)6 HoverEvent (net.minecraft.text.HoverEvent)6 TextColor (net.minecraft.text.TextColor)6 Mixin (org.spongepowered.asm.mixin.Mixin)6 At (org.spongepowered.asm.mixin.injection.At)6 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)5 Redirect (org.spongepowered.asm.mixin.injection.Redirect)5 JsonObject (com.google.gson.JsonObject)4 GameProfile (com.mojang.authlib.GameProfile)4