Noam Wolf
Noam Wolf

Reputation: 1

I try to create minecraft fabric mod 1.20.1 that if I click " ` " its print in the chat the biomes that I were there

I try to create minecraft fabric mod 1.20.1 that if I click " ` " its print in the chat the biomes that I were there

here my code:

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.Text.literal;
import net.minecraft.util.Identifier;
import org.lwjgl.glfw.GLFW;

public class Biome implements ClientModInitializer {

    private static final KeyBinding KEY_BINDING = KeyBindingHelper.registerKeyBinding(new KeyBinding(
            "key.yourmod.showbiome",
            GLFW.GLFW_KEY_GRAVE_ACCENT,
            "category.yourmod"
    ));

    @Override
    public void onInitializeClient() {
        // Register the key press event listener
        KeyBindingHelper.registerKeyBinding(KEY_BINDING);
    }

    public static void onKeyPressed() {
        if (KEY_BINDING.wasPressed()) {
            MinecraftClient client = MinecraftClient.getInstance();
            ClientPlayerEntity player = client.player;

            if (player != null && player.world != null) {
                String biomeName = player.world.getBiome(player.getBlockPos()).getTranslationKey();
                player.sendMessage(new LiteralText("You are in the biome: " + biomeName), false);
            }
        }
    }
}


here my error:

error: package net.minecraft.Text does not exist import net.minecraft.Text.literal;

plzz help mee with that :) I have tryed to fix it but it hadnt work :(

Upvotes: 0

Views: 1654

Answers (2)

CodeAssault
CodeAssault

Reputation: 3

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.text.Text;
import org.lwjgl.glfw.GLFW;

public class Biome implements ClientModInitializer {

    private static final KeyBinding KEY_BINDING = KeyBindingHelper.registerKeyBinding(new KeyBinding(
            "key.yourmod.showbiome",
            GLFW.GLFW_KEY_GRAVE_ACCENT,
            "category.yourmod"
    ));

    @Override
    public void onInitializeClient() {
        // Register the key press event listener
        KeyBindingHelper.registerKeyBinding(KEY_BINDING);
    }

    public static void onKeyPressed() {
        if (KEY_BINDING.wasPressed()) {
            MinecraftClient client = MinecraftClient.getInstance();
            ClientPlayerEntity player = client.player;

            if (player != null && player.getWorld() != null) {
                String biomeName = String.valueOf(player.getWorld().getBiome(player.getBlockPos()).getKey());
                player.sendMessage(Text.literal("You are in the biome: " + biomeName), false);
            }
        }
    }
}

I have updated the code to use player.getWorld(). This should fix your bug.

Upvotes: 0

CodeAssault
CodeAssault

Reputation: 3

The reason your getting the error is because new LiteralText is not a thing in 1.20.1 fabric modding I had the same issue instead change it to this

player.sendMessage(Text.literal("You are in the biome: " + biomeName), false);

and make sure import net.minecraft.text.Text; is imported

this should fix your error

Upvotes: 0

Related Questions