mirror of
https://github.com/lukasabbe/SimpleTransportHud.git
synced 2026-04-30 10:50:53 +00:00
Fixed license
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package com.lukasabbe.simplehud;
|
||||
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Constants {
|
||||
public final static String MOD_ID = "simplehud";
|
||||
//Config
|
||||
public final static Identifier ConfigIdentifier = Identifier.fromNamespaceAndPath(MOD_ID, "config");
|
||||
//Hud:s
|
||||
public final static Identifier ElytraHudIdentifier = Identifier.fromNamespaceAndPath(MOD_ID, "elytra_hud");
|
||||
|
||||
public final static List<Identifier> HudIdentifiers = Arrays.asList(ElytraHudIdentifier);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.lukasabbe.simplehud;
|
||||
|
||||
import com.lukasabbe.simplehud.config.Config;
|
||||
import com.lukasabbe.simplehud.huds.ElytraHud;
|
||||
import com.lukasabbe.simplehud.huds.SimpleHud;
|
||||
import net.fabricmc.api.ClientModInitializer;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SimpleHudMod implements ClientModInitializer {
|
||||
|
||||
public static List<SimpleHud> HUD_LIST = Arrays.asList(
|
||||
new ElytraHud()
|
||||
);
|
||||
|
||||
public static Config configInstance = null;
|
||||
|
||||
@Override
|
||||
public void onInitializeClient() {
|
||||
Config.HANDLER.load();
|
||||
configInstance = Config.HANDLER.instance();
|
||||
HUD_LIST.forEach(simpleHud -> HudElementRegistry.addFirst(simpleHud.getIdentifier(), simpleHud::render));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.lukasabbe.simplehud.config;
|
||||
|
||||
import com.lukasabbe.simplehud.Constants;
|
||||
import dev.isxander.yacl3.config.v2.api.ConfigClassHandler;
|
||||
import dev.isxander.yacl3.config.v2.api.SerialEntry;
|
||||
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
|
||||
import dev.isxander.yacl3.platform.YACLPlatform;
|
||||
|
||||
import java.util.IdentityHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Config {
|
||||
public static ConfigClassHandler<Config> HANDLER = ConfigClassHandler
|
||||
.createBuilder(Config.class)
|
||||
.id(Constants.ConfigIdentifier)
|
||||
.serializer(config -> GsonConfigSerializerBuilder
|
||||
.create(config)
|
||||
.setPath(YACLPlatform.getConfigDir().resolve("simple_hud_config.json5"))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
@SerialEntry
|
||||
public Map<String, Boolean> HudActivatedList = getActiveHuds();
|
||||
|
||||
@SerialEntry
|
||||
public HudPosition hudPosition = HudPosition.CENTER;
|
||||
|
||||
@SerialEntry
|
||||
public boolean ignoreSafeArea = false;
|
||||
|
||||
private Map<String, Boolean> getActiveHuds() {
|
||||
Map<String, Boolean> activatedHuds = new IdentityHashMap<>();
|
||||
for(var simpleHudIdentifier : Constants.HudIdentifiers){
|
||||
activatedHuds.put(simpleHudIdentifier.toShortString(), true);
|
||||
}
|
||||
return activatedHuds;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.lukasabbe.simplehud.config;
|
||||
|
||||
import dev.isxander.yacl3.api.NameableEnum;
|
||||
import net.minecraft.network.chat.Component;
|
||||
|
||||
public enum HudPosition implements NameableEnum {
|
||||
CENTER,
|
||||
TOP_LEFT,
|
||||
TOP_RIGHT,
|
||||
BOTTOM_LEFT,
|
||||
BOTTOM_RIGHT;
|
||||
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.lukasabbe.simplehud.huds;
|
||||
|
||||
import com.lukasabbe.simplehud.Constants;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public class ElytraHud implements SimpleHud {
|
||||
@Override
|
||||
public void render(GuiGraphics graphics, DeltaTracker tracker) {
|
||||
if(!isHudActivated()) return;
|
||||
//if(!ElytraTools.isFlying()) return;
|
||||
if(client.noRender) return;
|
||||
|
||||
renderBackPlate(graphics);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getIdentifier() {
|
||||
return Constants.ElytraHudIdentifier;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.lukasabbe.simplehud.huds;
|
||||
|
||||
import com.lukasabbe.simplehud.Constants;
|
||||
import com.lukasabbe.simplehud.SimpleHudMod;
|
||||
import com.lukasabbe.simplehud.config.HudPosition;
|
||||
import net.minecraft.client.DeltaTracker;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.renderer.RenderPipelines;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
public interface SimpleHud {
|
||||
Minecraft client = Minecraft.getInstance();
|
||||
Identifier backPlateAsset = Identifier.fromNamespaceAndPath(Constants.MOD_ID, "textures/backplate.png");
|
||||
|
||||
|
||||
void render(GuiGraphics graphics, DeltaTracker tracker);
|
||||
|
||||
Identifier getIdentifier();
|
||||
|
||||
default boolean isHudActivated(){
|
||||
return SimpleHudMod.configInstance.HudActivatedList.get(getIdentifier().toShortString());
|
||||
}
|
||||
|
||||
default void renderBackPlate(GuiGraphics graphics){
|
||||
int screenWidth = client.getWindow().getGuiScaledWidth();
|
||||
int screenHeight = client.getWindow().getGuiScaledHeight();
|
||||
|
||||
//Creates pos for HUD based on config
|
||||
int[] pos = calculateHudPosition(screenWidth, screenHeight, SimpleHudMod.configInstance.hudPosition);
|
||||
int x = pos[0];
|
||||
int y = pos[1];
|
||||
int centeredX = 50;
|
||||
int centeredY = 60;
|
||||
|
||||
int backPlateCornerX = 0;
|
||||
int backPlateCornerY = 0;
|
||||
int backPlateWidth = 100;
|
||||
int backPlateHeight = 35;
|
||||
|
||||
//Render Backplate
|
||||
graphics.blit(
|
||||
RenderPipelines.GUI_TEXTURED,
|
||||
backPlateAsset,
|
||||
x - centeredX, y - centeredY,
|
||||
backPlateCornerX, backPlateCornerY,
|
||||
backPlateWidth, backPlateHeight,
|
||||
backPlateWidth, backPlateHeight
|
||||
);
|
||||
}
|
||||
// Thanks gen1nya for making the HUD pos system
|
||||
default int[] calculateHudPosition(int screenWidth, int screenHeight, HudPosition position){
|
||||
final int padding = 10;
|
||||
final int hudHalfWidth = 50;
|
||||
final int hudHeight = 36;
|
||||
|
||||
if(SimpleHudMod.configInstance.ignoreSafeArea){
|
||||
return switch (position){
|
||||
case TOP_LEFT -> new int[]{hudHalfWidth + padding, 60 + padding};
|
||||
case TOP_RIGHT -> new int[]{screenWidth - hudHalfWidth - padding, 60 + padding};
|
||||
case BOTTOM_LEFT -> new int[]{hudHalfWidth + padding, screenHeight - padding * 2 + hudHeight};
|
||||
case BOTTOM_RIGHT -> new int[]{screenWidth - hudHalfWidth - padding, screenHeight - padding * 2 + hudHeight};
|
||||
default -> new int[]{screenWidth / 2, screenHeight - 25}; // CENTER
|
||||
};
|
||||
}
|
||||
return switch (position) {
|
||||
case TOP_LEFT -> new int[]{hudHalfWidth + padding, 70 + padding};
|
||||
case TOP_RIGHT -> new int[]{screenWidth - hudHalfWidth - padding, 70 + padding};
|
||||
case BOTTOM_LEFT -> new int[]{hudHalfWidth + padding, screenHeight - 25};
|
||||
case BOTTOM_RIGHT -> new int[]{screenWidth - hudHalfWidth - padding, screenHeight - 25};
|
||||
default -> new int[]{screenWidth / 2, screenHeight - 25}; // CENTER
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.lukasabbe.simplehud.tools;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
|
||||
public class ElytraTools {
|
||||
private static final LocalPlayer player = Minecraft.getInstance().player;
|
||||
public static boolean isFlying(){
|
||||
if(player == null) return false;
|
||||
return player.isFallFlying();
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Binary file not shown.
|
After Width: | Height: | Size: 490 B |
@@ -0,0 +1,25 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"id": "simplehud",
|
||||
"version": "${version}",
|
||||
"name": "SimpleHud",
|
||||
"description": "",
|
||||
"authors": [],
|
||||
"contact": {},
|
||||
"license": "MIT",
|
||||
"icon": "assets/simplehud/icon.png",
|
||||
"environment": "*",
|
||||
"entrypoints": {
|
||||
"client": [
|
||||
"com.lukasabbe.simplehud.SimpleHudMod"
|
||||
]
|
||||
},
|
||||
"mixins": [
|
||||
"simplehud.mixins.json"
|
||||
],
|
||||
"depends": {
|
||||
"fabricloader": ">=${loader_version}",
|
||||
"fabric-api": "*",
|
||||
"minecraft": "${minecraft_version}"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"required": true,
|
||||
"minVersion": "0.8",
|
||||
"package": "com.lukasabbe.simplehud.mixin",
|
||||
"compatibilityLevel": "JAVA_21",
|
||||
"mixins": [
|
||||
],
|
||||
"client": [
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
},
|
||||
"overwrites": {
|
||||
"requireAnnotations": true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user