Search in sources :

Example 36 with TranslatableText

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

the class BlockMeterClient method onInitializeClient.

@Override
public void onInitializeClient() {
    final KeyBinding keyBinding = new KeyBinding("key.blockmeter.assign", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_M, "category.blockmeter.key");
    final KeyBinding keyBindingMenu = new KeyBinding("key.blockmeter.menu", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_LEFT_ALT, "category.blockmeter.key");
    KeyBindingHelper.registerKeyBinding(keyBinding);
    KeyBindingHelper.registerKeyBinding(keyBindingMenu);
    // This is ugly I know, but I did not find something better
    // (Issue in AutoConfig https://github.com/shedaniel/AutoConfig/issues/13)
    confMgr = (ConfigManager<ModConfig>) AutoConfig.register(ModConfig.class, Toml4jConfigSerializer::new);
    ClientTickEvents.START_CLIENT_TICK.register(e -> {
        if (keyBinding.wasPressed()) {
            if (Screen.hasShiftDown()) {
                if (undo())
                    e.player.sendMessage(new TranslatableText("blockmeter.clearLast"), true);
            } else if (Screen.hasControlDown()) {
                if (clear())
                    e.player.sendMessage(new TranslatableText("blockmeter.clearAll"), true);
            } else if (this.active) {
                disable();
                e.player.sendMessage(new TranslatableText("blockmeter.toggle.off", new Object[0]), true);
            } else {
                active = true;
                ItemStack itemStack = e.player.getMainHandStack();
                currentItem = itemStack.getItem();
                e.player.sendMessage(new TranslatableText("blockmeter.toggle.on", new Object[] { new TranslatableText(itemStack.getTranslationKey(), new Object[0]) }), true);
            }
        }
        if (keyBindingMenu.wasPressed() && active && MinecraftClient.getInstance().player.getMainHandStack().getItem() == this.currentItem) {
            MinecraftClient.getInstance().setScreen((Screen) this.quickMenu);
        }
        // Updates Selection preview
        if (this.active && this.boxes.size() > 0) {
            final ClientMeasureBox currentBox = getCurrentBox();
            if (currentBox != null) {
                final HitResult rayHit = e.player.raycast((double) e.interactionManager.getReachDistance(), 1.0f, false);
                if (rayHit.getType() == HitResult.Type.BLOCK) {
                    final BlockHitResult blockHitResult = (BlockHitResult) rayHit;
                    currentBox.setBlockEnd(new BlockPos(blockHitResult.getBlockPos()));
                }
            }
        }
    });
    UseBlockCallback.EVENT.register((playerEntity, world, hand, hitResult) -> this.onBlockMeterClick(playerEntity, hitResult));
}
Also used : Toml4jConfigSerializer(me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer) TranslatableText(net.minecraft.text.TranslatableText) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) KeyBinding(net.minecraft.client.option.KeyBinding) ClientMeasureBox(win.baruna.blockmeter.measurebox.ClientMeasureBox) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BlockHitResult(net.minecraft.util.hit.BlockHitResult)

Example 37 with TranslatableText

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

the class WaystoneBlockScreen method drawBackground.

@Override
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) {
    if (page == Page.WAYSTONES) {
        super.drawBackground(matrices, delta, mouseX, mouseY);
    } else {
        this.renderBackground(matrices);
        RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
        RenderSystem.setShaderTexture(0, CONFIG_TEXTURE);
        this.drawTexture(matrices, x, y, 0, 0, this.backgroundWidth, this.backgroundHeight);
        if (canEdit()) {
            this.drawTexture(matrices, x + 23, y + 103, 0, 125, 103, 13);
        }
        renderButtons(matrices, mouseX, mouseY);
        renderButtonText(matrices);
        String owner = ((WaystoneBlockScreenHandler) handler).getOwnerName();
        if (owner == null || "".equals(owner)) {
            owner = new TranslatableText("waystones.config.no_owner").getString();
        }
        this.textRenderer.draw(matrices, new TranslatableText("waystones.config.owner", owner), this.x + 10, this.y + 75, 0x161616);
        if (this.nameField.isVisible()) {
            this.nameField.render(matrices, mouseX, mouseY, delta);
        }
        renderButtonTooltips(matrices, mouseX, mouseY);
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText)

Example 38 with TranslatableText

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

the class LocalVoidItem method appendTooltip.

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
    super.appendTooltip(stack, world, tooltip, context);
    String name = null;
    NbtCompound tag = stack.getNbt();
    boolean invalid = false;
    if (tag == null || !tag.contains("waystone")) {
        invalid = true;
    } else {
        name = Waystones.WAYSTONE_STORAGE.getName(tag.getString("waystone"));
        if (name == null) {
            invalid = true;
        }
    }
    if (invalid) {
        tooltip.add(new TranslatableText("waystones.local_void.empty_tooltip"));
        return;
    }
    tooltip.add(new TranslatableText("waystones.local_void.tooltip", new LiteralText(name).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.local_void.tooltip.arg_color").getString())))));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) NbtCompound(net.minecraft.nbt.NbtCompound) LiteralText(net.minecraft.text.LiteralText)

Example 39 with TranslatableText

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

the class ScrollOfInfiniteKnowledgeItem method appendTooltip.

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
    super.appendTooltip(stack, world, tooltip, context);
    tooltip.add(new TranslatableText("waystones.scroll.infinite"));
    int count = -1;
    if (Waystones.WAYSTONE_STORAGE != null) {
        count = Waystones.WAYSTONE_STORAGE.getCount();
    } else if (world != null && world.isClient) {
        count = ClientStuff.getWaystoneCount();
    }
    if (count != -1) {
        tooltip.add(new TranslatableText("waystones.scroll.infinite_tooltip", new LiteralText(String.valueOf(count)).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.scroll.infinite_tooltip.arg_color").getString())))));
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) LiteralText(net.minecraft.text.LiteralText)

Example 40 with TranslatableText

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

the class WaystoneScrollItem method appendTooltip.

@Override
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) {
    super.appendTooltip(stack, world, tooltip, context);
    NbtCompound tag = stack.getNbt();
    if (tag == null || !tag.contains("waystones")) {
        return;
    }
    int size = tag.getList("waystones", 8).size();
    HashSet<String> waystones = null;
    if (Waystones.WAYSTONE_STORAGE != null) {
        waystones = Waystones.WAYSTONE_STORAGE.getAllHashes();
    } else if (world != null && world.isClient) {
        waystones = ClientStuff.getWaystoneHashes();
    }
    if (waystones != null) {
        tooltip.add(new TranslatableText("waystones.scroll.tooltip", new LiteralText(String.valueOf(size)).styled(style -> style.withColor(TextColor.parse(new TranslatableText("waystones.scroll.tooltip.arg_color").getString())))));
    }
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) NbtCompound(net.minecraft.nbt.NbtCompound) NbtString(net.minecraft.nbt.NbtString) LiteralText(net.minecraft.text.LiteralText)

Aggregations

TranslatableText (net.minecraft.text.TranslatableText)161 LiteralText (net.minecraft.text.LiteralText)30 Text (net.minecraft.text.Text)19 ItemStack (net.minecraft.item.ItemStack)16 ArrayList (java.util.ArrayList)15 ButtonWidget (net.minecraft.client.gui.widget.ButtonWidget)14 List (java.util.List)12 MinecraftClient (net.minecraft.client.MinecraftClient)12 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)12 SPEInterface (eu.pb4.armorstandeditor.helpers.SPEInterface)9 LivingEntity (net.minecraft.entity.LivingEntity)9 PlayerEntity (net.minecraft.entity.player.PlayerEntity)8 ListTag (net.minecraft.nbt.ListTag)8 Formatting (net.minecraft.util.Formatting)8 BlockPos (net.minecraft.util.math.BlockPos)8 Environment (net.fabricmc.api.Environment)7 AbstractButtonWidget (net.minecraft.client.gui.widget.AbstractButtonWidget)7 Entity (net.minecraft.entity.Entity)7 Collection (java.util.Collection)6 ArmorStandPreset (eu.pb4.armorstandeditor.config.ArmorStandPreset)5