Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,25 @@ version = project.mod_version
group = project.maven_group


repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/" }
}


dependencies {
//to change the versions see the gradle.properties file
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}"
modApi("me.shedaniel.cloth:cloth-config-fabric:${project.clothconfig_version}") {
exclude(group: "net.fabricmc.fabric-api")
}
include "me.shedaniel.cloth:cloth-config-fabric:${project.clothconfig_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

}

processResources {
Expand Down
6 changes: 5 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ minecraft_version=1.19
yarn_mappings=1.19+build.1
loader_version=0.14.6

#Fabric api
# Fabric api
fabric_version=0.55.2+1.19

# Mod Properties
mod_version = 1.19-fabric-1
maven_group = net.torocraft
archives_base_name = torohealth

# Third Party
modmenu_version = 4.0.0
clothconfig_version = 7.0.65
139 changes: 139 additions & 0 deletions src/main/java/net/torocraft/torohealth/ModConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package net.torocraft.torohealth;

import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;
import me.shedaniel.autoconfig.annotation.ConfigEntry;
import me.shedaniel.autoconfig.serializer.JanksonConfigSerializer;
import me.shedaniel.autoconfig.annotation.ConfigEntry.Gui.EnumHandler.EnumDisplayOption;


@Config(name = "torohealth")
public class ModConfig implements ConfigData {
@ConfigEntry.Gui.Excluded
public static ModConfig INSTANCE;

public static void init()
{
AutoConfig.register(ModConfig.class, JanksonConfigSerializer::new);
INSTANCE = AutoConfig.getConfigHolder(ModConfig.class).getConfig();
INSTANCE.postLoad();
}

@ConfigEntry.Gui.CollapsibleObject
public HudOptions hudOptions = new HudOptions();
public static class HudOptions {
@ConfigEntry.Gui.Tooltip
public boolean showEntity = true;

@ConfigEntry.Gui.Tooltip
public boolean showBar = true;

@ConfigEntry.Gui.Tooltip
public boolean showSkin = true;

@ConfigEntry.Gui.Tooltip
public boolean onlyWhenHurt = false;

@ConfigEntry.Gui.Tooltip
@ConfigEntry.Gui.EnumHandler(option = EnumDisplayOption.BUTTON)
public AnchorPoint anchorPoint = AnchorPoint.TOP_LEFT;

@ConfigEntry.Gui.Tooltip
public int hudHideDelay = 20;

@ConfigEntry.Gui.Tooltip
public float hudDistance = 60f;

@ConfigEntry.Gui.Tooltip
public int hudXPosition = 4;

@ConfigEntry.Gui.Tooltip
public int hudYPosition = 4;

@ConfigEntry.Gui.Tooltip
public float hudScale = 1f;
}


@ConfigEntry.Gui.CollapsibleObject
public ParticleOptions particleOptions = new ParticleOptions();
public static class ParticleOptions {
@ConfigEntry.Gui.Tooltip
public boolean show = true;

@ConfigEntry.Gui.Tooltip
public float particleDistance = 60f;

@ConfigEntry.Gui.Excluded
public transient float particleDistanceSquared = 0;

@ConfigEntry.Gui.Tooltip
@ConfigEntry.ColorPicker
public int damageColor = 0xff0000;
@ConfigEntry.Gui.Tooltip
@ConfigEntry.ColorPicker
public int healColor = 0x00ff00;
}


@ConfigEntry.Gui.CollapsibleObject
public InWorldBarOptions inWorldBarOptions = new InWorldBarOptions();
public static class InWorldBarOptions {
@ConfigEntry.Gui.Tooltip
@ConfigEntry.Gui.EnumHandler(option = EnumDisplayOption.BUTTON)
public InWorldBarVisibilityMode inWorldBarVisibilityMode = InWorldBarVisibilityMode.NONE;

@ConfigEntry.Gui.Tooltip
public boolean onlyWhenLookingAt = false;

@ConfigEntry.Gui.Tooltip
public boolean onlyWhenHurt = false;

@ConfigEntry.Gui.Tooltip
public float inWorldBarDistance = 60f;
}

@ConfigEntry.Gui.CollapsibleObject
public BarOptions barOptions = new BarOptions();
public static class BarOptions {
@ConfigEntry.Gui.Tooltip
@ConfigEntry.Gui.EnumHandler(option = EnumDisplayOption.BUTTON)
public HealthChangeType healthChangeType= HealthChangeType.LAST;

@ConfigEntry.Gui.Tooltip
@ConfigEntry.ColorPicker
public int friendColor = 0x00ff00;

@ConfigEntry.Gui.Tooltip
@ConfigEntry.ColorPicker
public int friendColorSecondary = 0x008000;

@ConfigEntry.Gui.Tooltip
@ConfigEntry.ColorPicker
public int foeColor = 0xff0000;

@ConfigEntry.Gui.Tooltip
@ConfigEntry.ColorPicker
public int foeColorSecondary = 0x800000;
}


public enum AnchorPoint {
TOP_LEFT, TOP_CENTER, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT
}

public enum InWorldBarVisibilityMode {
NONE, WHEN_HOLDING_WEAPON, ALWAYS
}

public enum HealthChangeType {
NONE, LAST, CUMULATIVE
}


public void postLoad() {
// Recalculate dependent field
particleOptions.particleDistanceSquared = particleOptions.particleDistance * particleOptions.particleDistance;
}
}
26 changes: 20 additions & 6 deletions src/main/java/net/torocraft/torohealth/ToroHealth.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
package net.torocraft.torohealth;

import java.util.Random;

import net.minecraft.util.ActionResult;
import net.fabricmc.api.ModInitializer;
import net.torocraft.torohealth.config.Config;
import net.torocraft.torohealth.config.loader.ConfigLoader;
import net.torocraft.torohealth.display.Hud;
import net.torocraft.torohealth.util.RayTrace;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.ConfigHolder;

public class ToroHealth implements ModInitializer {

public static final String MODID = "torohealth";


public static Config CONFIG = new Config();
public static ModConfig CONFIG;
public static Hud HUD = new Hud();
public static RayTrace RAYTRACE = new RayTrace();
public static boolean IS_HOLDING_WEAPON = false;
public static Random RAND = new Random();

private static ConfigLoader<Config> CONFIG_LOADER = new ConfigLoader<>(new Config(),
ToroHealth.MODID + ".json", config -> ToroHealth.CONFIG = config);

@Override
public void onInitialize() {
CONFIG_LOADER.load();
ModConfig.init();

ConfigHolder<ModConfig> holder =
AutoConfig.getConfigHolder(ModConfig.class);

holder.registerSaveListener((h, c) -> {
c.postLoad();
return ActionResult.SUCCESS;
});

holder.registerLoadListener((h, c) -> {
c.postLoad();
return ActionResult.SUCCESS;
});
CONFIG = ModConfig.INSTANCE;
}
}
2 changes: 1 addition & 1 deletion src/main/java/net/torocraft/torohealth/bars/BarState.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private void handleHealthChange() {

lastDmgDelay = HEALTH_INDICATOR_DELAY * 2;
lastHealth = health;
if (ToroHealth.CONFIG.particle.show) {
if (ToroHealth.CONFIG.particleOptions.show) {
BarStates.PARTICLES.add(new BarParticle(entity, lastDmg));
}
}
Expand Down
33 changes: 14 additions & 19 deletions src/main/java/net/torocraft/torohealth/bars/HealthBarRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.math.Vec3f;
import net.torocraft.torohealth.ToroHealth;
import net.torocraft.torohealth.config.Config;
import net.torocraft.torohealth.config.Config.InWorld;
import net.torocraft.torohealth.config.Config.Mode;
import net.torocraft.torohealth.ModConfig.HealthChangeType;
import net.torocraft.torohealth.ModConfig.InWorldBarVisibilityMode;
import net.torocraft.torohealth.util.EntityUtil;
import net.torocraft.torohealth.util.EntityUtil.Relation;
import org.lwjgl.opengl.GL11;
Expand All @@ -31,10 +30,6 @@ public class HealthBarRenderer {
private static final int DARK_GRAY = 0x808080;
private static final float FULL_SIZE = 40;

private static InWorld getConfig() {
return ToroHealth.CONFIG.inWorld;
}

private static final List<LivingEntity> renderedEntities = new ArrayList<>();

public static void prepareRenderInWorld(LivingEntity entity) {
Expand All @@ -44,25 +39,25 @@ public static void prepareRenderInWorld(LivingEntity entity) {
return;
}

if (entity.distanceTo(client.getCameraEntity()) > ToroHealth.CONFIG.inWorld.distance) {
if (entity.distanceTo(client.getCameraEntity()) > ToroHealth.CONFIG.inWorldBarOptions.inWorldBarDistance) {
return;
}

BarStates.getState(entity);

if (Mode.WHEN_HOLDING_WEAPON.equals(getConfig().mode) && !ToroHealth.IS_HOLDING_WEAPON) {
if (InWorldBarVisibilityMode.WHEN_HOLDING_WEAPON.equals(ToroHealth.CONFIG.inWorldBarOptions.inWorldBarVisibilityMode) && !ToroHealth.IS_HOLDING_WEAPON) {
return;
}

if (Mode.NONE.equals(getConfig().mode)) {
if (InWorldBarVisibilityMode.NONE.equals(ToroHealth.CONFIG.inWorldBarOptions.inWorldBarVisibilityMode)) {
return;
}

if (ToroHealth.CONFIG.inWorld.onlyWhenLookingAt && ToroHealth.HUD.getEntity() != entity) {
if (ToroHealth.CONFIG.inWorldBarOptions.onlyWhenLookingAt && ToroHealth.HUD.getEntity() != entity) {
return;
}

if (ToroHealth.CONFIG.inWorld.onlyWhenHurt && entity.getHealth() >= entity.getMaxHealth()) {
if (ToroHealth.CONFIG.inWorldBarOptions.onlyWhenHurt && entity.getHealth() >= entity.getMaxHealth()) {
return;
}

Expand Down Expand Up @@ -129,10 +124,10 @@ public static void render(MatrixStack matrix, LivingEntity entity, double x, dou

Relation relation = EntityUtil.determineRelation(entity);

int color = relation.equals(Relation.FRIEND) ? ToroHealth.CONFIG.bar.friendColor
: ToroHealth.CONFIG.bar.foeColor;
int color2 = relation.equals(Relation.FRIEND) ? ToroHealth.CONFIG.bar.friendColorSecondary
: ToroHealth.CONFIG.bar.foeColorSecondary;
int color = relation.equals(Relation.FRIEND) ? ToroHealth.CONFIG.barOptions.friendColor
: ToroHealth.CONFIG.barOptions.foeColor;
int color2 = relation.equals(Relation.FRIEND) ? ToroHealth.CONFIG.barOptions.friendColorSecondary
: ToroHealth.CONFIG.barOptions.foeColorSecondary;

BarState state = BarStates.getState(entity);

Expand All @@ -146,9 +141,9 @@ public static void render(MatrixStack matrix, LivingEntity entity, double x, dou
drawBar(m4f, x, y, width, percent, color, zOffset, inWorld);

if (!inWorld) {
if (ToroHealth.CONFIG.bar.damageNumberType.equals(Config.NumberType.CUMULATIVE)) {
if (ToroHealth.CONFIG.barOptions.healthChangeType.equals(HealthChangeType.CUMULATIVE)) {
drawDamageNumber(matrix, state.lastDmgCumulative, x, y, width);
} else if (ToroHealth.CONFIG.bar.damageNumberType.equals(Config.NumberType.LAST)) {
} else if (ToroHealth.CONFIG.barOptions.healthChangeType.equals(HealthChangeType.LAST)) {
drawDamageNumber(matrix, state.lastDmg, x, y, width);
}
}
Expand All @@ -163,7 +158,7 @@ public static void drawDamageNumber(MatrixStack matrix, int dmg, double x, doubl
String s = Integer.toString(i);
MinecraftClient minecraft = MinecraftClient.getInstance();
int sw = minecraft.textRenderer.getWidth(s);
int color = dmg < 0 ? ToroHealth.CONFIG.particle.healColor : ToroHealth.CONFIG.particle.damageColor;
int color = dmg < 0 ? ToroHealth.CONFIG.particleOptions.healColor : ToroHealth.CONFIG.particleOptions.damageColor;
minecraft.textRenderer.draw(matrix, s, (int) (x + (width / 2) - sw), (int) y + 5, color);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void renderParticles(MatrixStack matrix, Camera camera) {

private static void renderParticle(MatrixStack matrix, BarParticle particle, Camera camera) {
double distanceSquared = camera.getPos().squaredDistanceTo(particle.x, particle.y, particle.z);
if (distanceSquared > ToroHealth.CONFIG.particle.distanceSquared) {
if (distanceSquared > ToroHealth.CONFIG.particleOptions.particleDistanceSquared) {
return;
}

Expand Down
Loading