mirror of
https://github.com/Shiewk/Widgets.git
synced 2026-04-28 11:34:17 +02:00
Add Biome widget
This commit is contained in:
@@ -67,5 +67,6 @@ public class WidgetsModClient implements ClientModInitializer {
|
|||||||
WidgetManager.register(new KeyStrokesWidget(Identifier.of(WidgetsMod.MOD_ID, "keystrokes")));
|
WidgetManager.register(new KeyStrokesWidget(Identifier.of(WidgetsMod.MOD_ID, "keystrokes")));
|
||||||
WidgetManager.register(new PlainTextWidget(Identifier.of(WidgetsMod.MOD_ID, "plaintext")));
|
WidgetManager.register(new PlainTextWidget(Identifier.of(WidgetsMod.MOD_ID, "plaintext")));
|
||||||
WidgetManager.register(new TPSWidget(Identifier.of(WidgetsMod.MOD_ID, "tps")));
|
WidgetManager.register(new TPSWidget(Identifier.of(WidgetsMod.MOD_ID, "tps")));
|
||||||
|
WidgetManager.register(new BiomeWidget(Identifier.of(WidgetsMod.MOD_ID, "biome")));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package de.shiewk.widgets.widgets;
|
||||||
|
|
||||||
|
import de.shiewk.widgets.WidgetSettings;
|
||||||
|
import de.shiewk.widgets.widgets.settings.ToggleWidgetSetting;
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
|
import net.minecraft.client.world.ClientWorld;
|
||||||
|
import net.minecraft.registry.entry.RegistryEntry;
|
||||||
|
import net.minecraft.text.Text;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.world.biome.Biome;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BiomeWidget extends BasicTextWidget {
|
||||||
|
|
||||||
|
public BiomeWidget(Identifier id) {
|
||||||
|
super(id, List.of(
|
||||||
|
new ToggleWidgetSetting("show_label", Text.translatable("widgets.widgets.biome.showLabel"), true)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private long tickCounter = 0;
|
||||||
|
private boolean showLabel = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tickWidget() {
|
||||||
|
if (++tickCounter % 20 == 0){
|
||||||
|
MinecraftClient client = MinecraftClient.getInstance();
|
||||||
|
ClientPlayerEntity player = client.player;
|
||||||
|
ClientWorld world = client.world;
|
||||||
|
if (world != null && player != null){
|
||||||
|
RegistryEntry<Biome> biome = world.getBiome(player.getBlockPos());
|
||||||
|
String text = biome.getKeyOrValue().map(
|
||||||
|
(biomeKey) -> {
|
||||||
|
if (showLabel){
|
||||||
|
return Text.translatable("widgets.widgets.biome.label", Text.translatable(biomeKey.getValue().toTranslationKey("biome"))).getString();
|
||||||
|
} else {
|
||||||
|
return Text.translatable(biomeKey.getValue().toTranslationKey("biome")).getString();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
(b) -> "[unregistered " + b + "]"
|
||||||
|
);
|
||||||
|
this.renderText = Text.literal(text);
|
||||||
|
} else {
|
||||||
|
if (showLabel){
|
||||||
|
this.renderText = Text.translatable("widgets.widgets.biome.label", "?");
|
||||||
|
} else {
|
||||||
|
this.renderText = Text.literal("?");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getName() {
|
||||||
|
return Text.translatable("widgets.widgets.biome");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Text getDescription() {
|
||||||
|
return Text.translatable("widgets.widgets.biome.description");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSettingsChanged(WidgetSettings settings) {
|
||||||
|
super.onSettingsChanged(settings);
|
||||||
|
this.showLabel = ((ToggleWidgetSetting) settings.optionById("show_label")).getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -92,5 +92,9 @@
|
|||||||
"widgets.widgets.tps.dynamicColor": "Farbe dynamisch anzeigen",
|
"widgets.widgets.tps.dynamicColor": "Farbe dynamisch anzeigen",
|
||||||
"widgets.widgets.tps": "TPS",
|
"widgets.widgets.tps": "TPS",
|
||||||
"widgets.widgets.tps.description": "Zeigt die TPS im Einzelspielermodus an oder schätzt die TPS im Mehrspielermodus",
|
"widgets.widgets.tps.description": "Zeigt die TPS im Einzelspielermodus an oder schätzt die TPS im Mehrspielermodus",
|
||||||
"widgets.widgets.tps.showLabel": "Beschriftung anzeigen"
|
"widgets.widgets.tps.showLabel": "Beschriftung anzeigen",
|
||||||
|
"widgets.widgets.biome.showLabel": "Beschriftung anzeigen",
|
||||||
|
"widgets.widgets.biome.label": "Biom: %s",
|
||||||
|
"widgets.widgets.biome": "Biom",
|
||||||
|
"widgets.widgets.biome.description": "Zeigt das Biom an, in dem du dich befindest."
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,5 +92,9 @@
|
|||||||
"widgets.widgets.tps.dynamicColor": "Dynamic Color",
|
"widgets.widgets.tps.dynamicColor": "Dynamic Color",
|
||||||
"widgets.widgets.tps": "TPS",
|
"widgets.widgets.tps": "TPS",
|
||||||
"widgets.widgets.tps.description": "Shows the current TPS when in singleplayer or estimates server TPS when in multiplayer",
|
"widgets.widgets.tps.description": "Shows the current TPS when in singleplayer or estimates server TPS when in multiplayer",
|
||||||
"widgets.widgets.tps.showLabel": "Show label"
|
"widgets.widgets.tps.showLabel": "Show label",
|
||||||
|
"widgets.widgets.biome.showLabel": "Show label",
|
||||||
|
"widgets.widgets.biome.label": "Biome: %s",
|
||||||
|
"widgets.widgets.biome": "Biome",
|
||||||
|
"widgets.widgets.biome.description": "Shows the biome you're currently in."
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user