mirror of
https://github.com/lukasabbe/SimpleTransportHud.git
synced 2026-04-30 10:50:53 +00:00
Add a few config options
This commit is contained in:
@@ -6,6 +6,7 @@ import com.lukasabbe.simplehud.huds.ElytraHud;
|
||||
import com.lukasabbe.simplehud.huds.MinecartHud;
|
||||
import com.lukasabbe.simplehud.huds.SimpleHud;
|
||||
import com.lukasabbe.simplehud.tools.ElytraTools;
|
||||
import com.lukasabbe.simplehud.tools.EntityTools;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
|
||||
@@ -32,6 +33,7 @@ public class SimpleHudMod implements ClientModInitializer {
|
||||
(guiGraphics, deltaTracker) -> renderScaled(guiGraphics, deltaTracker, simpleHud))
|
||||
);
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> ElytraTools.tickElytraTools());
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> EntityTools.tickEntityTools());
|
||||
}
|
||||
|
||||
public static void renderScaled(GuiGraphics graphics, DeltaTracker tracker, SimpleHud simpleHud){
|
||||
|
||||
@@ -47,6 +47,14 @@ public class Config {
|
||||
@SerialEntry
|
||||
public SpeedEnum speedEnumMinecart = SpeedEnum.kmh;
|
||||
|
||||
//Display speed
|
||||
@SerialEntry
|
||||
public int elytraHudDelay = 2;
|
||||
@SerialEntry
|
||||
public int boatHudDelay = 0;
|
||||
@SerialEntry
|
||||
public int minecartHudDelay = 0;
|
||||
|
||||
private Map<String, Boolean> getActiveHuds() {
|
||||
Map<String, Boolean> activatedHuds = new IdentityHashMap<>();
|
||||
for(var simpleHudIdentifier : Constants.HudIdentifiers){
|
||||
|
||||
@@ -6,7 +6,6 @@ import dev.isxander.yacl3.api.*;
|
||||
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder;
|
||||
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder;
|
||||
import dev.isxander.yacl3.gui.controllers.cycling.EnumController;
|
||||
import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
@@ -60,6 +59,13 @@ public class ModMenu implements ModMenuApi {
|
||||
.binding(HudPosition.CENTER, () -> instance.hudPositionElytra, newVal -> instance.hudPositionElytra = newVal)
|
||||
.customController(opt -> new EnumController<>(opt, HudPosition.class))
|
||||
.build())
|
||||
.option(Option
|
||||
.<Integer>createBuilder()
|
||||
.name(Component.translatable("simple_hud.config.category.elytra_options.option.delay_hud.name"))
|
||||
.description(OptionDescription.of(Component.translatable("simple_hud.config.category.elytra_options.option.delay_hud.description")))
|
||||
.binding(2, () -> instance.elytraHudDelay, newVal -> instance.elytraHudDelay = newVal)
|
||||
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(0, 30).step(1))
|
||||
.build())
|
||||
.build())
|
||||
.category(ConfigCategory
|
||||
.createBuilder()
|
||||
@@ -78,6 +84,38 @@ public class ModMenu implements ModMenuApi {
|
||||
.binding(HudPosition.CENTER, () -> instance.hudPositionBoat, newVal -> instance.hudPositionBoat = newVal)
|
||||
.customController(opt -> new EnumController<>(opt, HudPosition.class))
|
||||
.build())
|
||||
.option(Option
|
||||
.<Integer>createBuilder()
|
||||
.name(Component.translatable("simple_hud.config.category.elytra_options.option.delay_hud.name"))
|
||||
.description(OptionDescription.of(Component.translatable("simple_hud.config.category.elytra_options.option.delay_hud.description")))
|
||||
.binding(2, () -> instance.boatHudDelay, newVal -> instance.boatHudDelay = newVal)
|
||||
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(0, 30).step(1))
|
||||
.build())
|
||||
.build())
|
||||
.category(ConfigCategory
|
||||
.createBuilder()
|
||||
.name(Component.translatable("simple_hud.config.category.minecart_hud.name"))
|
||||
.option(Option
|
||||
.<SpeedEnum>createBuilder()
|
||||
.name(Component.translatable("simple_hud.config.category.elytra_options.option.speed_enum.name"))
|
||||
.description(OptionDescription.of(Component.translatable("simple_hud.config.category.elytra_options.option.speed_enum.description")))
|
||||
.binding(SpeedEnum.kmh, () -> instance.speedEnumMinecart, newVal -> instance.speedEnumMinecart = newVal)
|
||||
.customController(opt -> new EnumController<>(opt, SpeedEnum.class))
|
||||
.build())
|
||||
.option(Option
|
||||
.<HudPosition>createBuilder()
|
||||
.name(Component.translatable("simple_hud.config.category.elytra_options.option.hud_position.name"))
|
||||
.description(OptionDescription.of(Component.translatable("simple_hud.config.category.elytra_options.option.hud_position.description")))
|
||||
.binding(HudPosition.CENTER, () -> instance.hudPositionMinecart, newVal -> instance.hudPositionMinecart = newVal)
|
||||
.customController(opt -> new EnumController<>(opt, HudPosition.class))
|
||||
.build())
|
||||
.option(Option
|
||||
.<Integer>createBuilder()
|
||||
.name(Component.translatable("simple_hud.config.category.elytra_options.option.delay_hud.name"))
|
||||
.description(OptionDescription.of(Component.translatable("simple_hud.config.category.elytra_options.option.delay_hud.description")))
|
||||
.binding(2, () -> instance.minecartHudDelay, newVal -> instance.minecartHudDelay = newVal)
|
||||
.controller(opt -> IntegerSliderControllerBuilder.create(opt).range(0, 30).step(1))
|
||||
.build())
|
||||
.build())
|
||||
.save(() -> Config.HANDLER.save())
|
||||
.build().generateScreen(parent);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.lukasabbe.simplehud.huds;
|
||||
import com.lukasabbe.simplehud.Constants;
|
||||
import com.lukasabbe.simplehud.config.Config;
|
||||
import com.lukasabbe.simplehud.config.HudPosition;
|
||||
import com.lukasabbe.simplehud.tools.ElytraTools;
|
||||
import com.lukasabbe.simplehud.tools.EntityTools;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
@@ -19,6 +20,8 @@ public class BoatHud implements SimpleHud {
|
||||
if(client.noRender) return;
|
||||
if(!EntityTools.isRidingEntity(Boat.class)) return;
|
||||
if(client.player == null) return;
|
||||
if(EntityTools.getTime() < Config.HANDLER.instance().boatHudDelay) return;
|
||||
|
||||
|
||||
int[] pos = getCornerPos();
|
||||
int x = pos[0];
|
||||
|
||||
@@ -20,6 +20,7 @@ public class ElytraHud implements SimpleHud {
|
||||
if(!ElytraTools.isFlying()) return;
|
||||
if(client.noRender) return;
|
||||
if(client.player == null) return;
|
||||
if(ElytraTools.getTime() < Config.HANDLER.instance().elytraHudDelay) return;
|
||||
|
||||
int[] pos = getCornerPos();
|
||||
int x = pos[0];
|
||||
|
||||
@@ -18,6 +18,7 @@ public class MinecartHud implements SimpleHud {
|
||||
if(client.noRender) return;
|
||||
if(!EntityTools.isRidingEntity(Minecart.class)) return;
|
||||
if(client.player == null) return;
|
||||
if(EntityTools.getTime() < Config.HANDLER.instance().minecartHudDelay) return;
|
||||
|
||||
int[] pos = getCornerPos();
|
||||
int x = pos[0];
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.lukasabbe.simplehud.huds;
|
||||
|
||||
import com.lukasabbe.simplehud.Constants;
|
||||
import com.lukasabbe.simplehud.SimpleHudMod;
|
||||
import com.lukasabbe.simplehud.config.Config;
|
||||
import com.lukasabbe.simplehud.config.HudPosition;
|
||||
import com.lukasabbe.simplehud.config.SpeedEnum;
|
||||
@@ -34,7 +33,7 @@ public interface SimpleHud {
|
||||
HudPosition getHudPosition();
|
||||
|
||||
default boolean isHudActivated(){
|
||||
return Config.HANDLER.instance().HudActivatedList.get(getIdentifier().toShortString());
|
||||
return Config.HANDLER.instance().HudActivatedList.get(getIdentifier().toShortString());
|
||||
}
|
||||
|
||||
default void renderBackPlate(GuiGraphics graphics){
|
||||
|
||||
@@ -12,8 +12,19 @@ public class ElytraTools {
|
||||
|
||||
private static double speed = 0;
|
||||
|
||||
private static long ticks = 0;
|
||||
|
||||
public static void tickElytraTools(){
|
||||
calculateSpeed();
|
||||
if(!isFlying()){
|
||||
ticks = 0;
|
||||
}else{
|
||||
ticks++;
|
||||
}
|
||||
}
|
||||
|
||||
public static long getTime(){
|
||||
return (ticks / 20);
|
||||
}
|
||||
|
||||
public static void calculateSpeed(){
|
||||
|
||||
@@ -6,6 +6,21 @@ import net.minecraft.util.Mth;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
public class EntityTools {
|
||||
|
||||
private static long ticks = 0;
|
||||
|
||||
public static void tickEntityTools(){
|
||||
if(!isRidingEntity()){
|
||||
ticks = 0;
|
||||
}else{
|
||||
ticks++;
|
||||
}
|
||||
}
|
||||
|
||||
public static long getTime(){
|
||||
return (ticks / 20);
|
||||
}
|
||||
|
||||
public static boolean isRidingEntity(Class<?> entityType){
|
||||
var player = getLocalPlayer();
|
||||
if(player == null) return false;
|
||||
|
||||
@@ -27,5 +27,8 @@
|
||||
"simple_hud.config.category.general.option.safe_area.name": "Ignore Safe Area",
|
||||
"simple_hud.config.category.general.option.safe_area.description": "Move HUD to screen edges, ignoring GUI safe area margins",
|
||||
"simple_hud.config.category.elytra_options.option.hud_position.name": "HUD Position",
|
||||
"simple_hud.config.category.elytra_options.option.hud_position.description": "Change the position of the HUD on screen"
|
||||
"simple_hud.config.category.elytra_options.option.hud_position.description": "Change the position of the HUD on screen",
|
||||
"simple_hud.config.category.elytra_options.option.delay_hud.name": "Delay HUD displaying",
|
||||
"simple_hud.config.category.elytra_options.option.delay_hud.description": "Change the time it takes for the HUD to appear",
|
||||
"simple_hud.config.category.minecart_hud.name": "Minecart HUD options"
|
||||
}
|
||||
Reference in New Issue
Block a user