commit
4e7e18e705
12 changed files with 430 additions and 8 deletions
|
@ -15,4 +15,5 @@ There is not much on the roadmap for the mod except to maintain the code for fut
|
||||||
The following is the possible roadmap:
|
The following is the possible roadmap:
|
||||||
|
|
||||||
1. Create a spigot plugin variant.
|
1. Create a spigot plugin variant.
|
||||||
2. Explore possibly making a quilt mod variant.
|
2. Explore possibly making a quilt mod variant.
|
||||||
|
3. Create a permission that a server owner can set to block this mod from functioning on the client.
|
13
build.gradle
13
build.gradle
|
@ -4,7 +4,7 @@ plugins {
|
||||||
id 'net.minecraftforge.gradle' version '5.1.+'
|
id 'net.minecraftforge.gradle' version '5.1.+'
|
||||||
}
|
}
|
||||||
|
|
||||||
version = '1.1.0'
|
version = "${myversion}"
|
||||||
group = 'dev.zontreck.mcmods' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
group = 'dev.zontreck.mcmods' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||||
archivesBaseName = 'WatchMyDurability'
|
archivesBaseName = 'WatchMyDurability'
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ minecraft {
|
||||||
//
|
//
|
||||||
// Use non-default mappings at your own risk. They may not always work.
|
// Use non-default mappings at your own risk. They may not always work.
|
||||||
// Simply re-run your setup task after changing the mappings to update your workspace.
|
// Simply re-run your setup task after changing the mappings to update your workspace.
|
||||||
mappings channel: 'official', version: '1.19.2'
|
mappings channel: 'official', version: "${mc_version}"
|
||||||
|
|
||||||
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.
|
// accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') // Currently, this location cannot be changed from the default.
|
||||||
|
|
||||||
|
@ -123,14 +123,21 @@ repositories {
|
||||||
// flatDir {
|
// flatDir {
|
||||||
// dir 'libs'
|
// dir 'libs'
|
||||||
// }
|
// }
|
||||||
|
maven {
|
||||||
|
name = "ZNI Creations"
|
||||||
|
url = "https://maven.zontreck.dev"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
// Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed
|
// Specify the version of Minecraft to use. If this is any group other than 'net.minecraft', it is assumed
|
||||||
// that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
|
// that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied.
|
||||||
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
|
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
|
||||||
minecraft 'net.minecraftforge:forge:1.19.2-43.1.1'
|
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
|
||||||
|
|
||||||
|
implementation fg.deobf("dev.zontreck:libzontreck:1.0.0.1:dev")
|
||||||
|
runtimeOnly fg.deobf("dev.zontreck:libzontreck:1.0.0.1")
|
||||||
|
compileOnly fg.deobf("dev.zontreck:libzontreck:1.0.0.1:dev")
|
||||||
// Real mod deobf dependency examples - these get remapped to your current mappings
|
// Real mod deobf dependency examples - these get remapped to your current mappings
|
||||||
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
|
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}:api") // Adds JEI API as a compile dependency
|
||||||
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
|
// runtimeOnly fg.deobf("mezz.jei:jei-${mc_version}:${jei_version}") // Adds the full JEI mod as a runtime dependency
|
||||||
|
|
|
@ -1,4 +1,8 @@
|
||||||
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
|
# Sets default memory used for gradle commands. Can be overridden by user or command line properties.
|
||||||
# This is required to provide enough memory for the Minecraft decompilation process.
|
# This is required to provide enough memory for the Minecraft decompilation process.
|
||||||
org.gradle.jvmargs=-Xmx3G
|
org.gradle.jvmargs=-Xmx3G
|
||||||
org.gradle.daemon=false
|
org.gradle.daemon=false
|
||||||
|
|
||||||
|
mc_version=1.19.2
|
||||||
|
forge_version=43.1.16
|
||||||
|
myversion = 1.1.1
|
|
@ -5,6 +5,9 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
|
import dev.zontreck.libzontreck.chat.ChatColor;
|
||||||
|
import dev.zontreck.libzontreck.chat.ChatColorFactory;
|
||||||
|
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
|
||||||
import dev.zontreck.mcmods.configs.WMDClientConfig;
|
import dev.zontreck.mcmods.configs.WMDClientConfig;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.core.NonNullList;
|
import net.minecraft.core.NonNullList;
|
||||||
|
@ -40,6 +43,25 @@ public class CheckInventory extends TimerTask
|
||||||
WatchMyDurability.LOGGER.warn("A error in the WatchMyDurability timer code has occurred. This could happen with hub worlds and the server transfers that occur. If this happened in another instance, please report this error to the developer, along with what you were doing.");
|
WatchMyDurability.LOGGER.warn("A error in the WatchMyDurability timer code has occurred. This could happen with hub worlds and the server transfers that occur. If this happened in another instance, please report this error to the developer, along with what you were doing.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Hijack this timer so we dont need to register yet another
|
||||||
|
if(!WMDClientConfig.EnableHealthAlert.get())return;
|
||||||
|
Health current = Health.of(Minecraft.getInstance().player);
|
||||||
|
if(WatchMyDurability.LastHealth == null)WatchMyDurability.LastHealth = current;
|
||||||
|
else{
|
||||||
|
if(current.identical(WatchMyDurability.LastHealth))return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Good to proceed
|
||||||
|
if(current.shouldGiveAlert())
|
||||||
|
{
|
||||||
|
|
||||||
|
Minecraft.getInstance().player.displayClientMessage(Component.literal(ChatColorFactory.MakeBuilder().set(ColorOptions.Dark_Red).set(ColorOptions.Bold).toString()+"You need to eat!"), false);
|
||||||
|
|
||||||
|
SoundEvent sv = SoundEvents.WARDEN_ROAR;
|
||||||
|
Soundify(sv);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void PushItems(String type, List<ItemStack> stack)
|
public void PushItems(String type, List<ItemStack> stack)
|
||||||
|
@ -84,7 +106,7 @@ public class CheckInventory extends TimerTask
|
||||||
String entryStr = WMDClientConfig.alertMessages.get().get(idx);
|
String entryStr = WMDClientConfig.alertMessages.get().get(idx);
|
||||||
|
|
||||||
if(percent <= entry){
|
if(percent <= entry){
|
||||||
String replaced = entryStr.replaceAll("!item!", is1.getDisplayName().getString());
|
String replaced = WatchMyDurability.WMDPrefix + ChatColor.DARK_RED + entryStr.replaceAll("!item!", is1.getDisplayName().getString());
|
||||||
WatchMyDurability.LOGGER.info("Enqueue alert for an item. Playing sound for item: "+is1.getDisplayName().getString());
|
WatchMyDurability.LOGGER.info("Enqueue alert for an item. Playing sound for item: "+is1.getDisplayName().getString());
|
||||||
|
|
||||||
SoundEvent theSound = SoundEvents.ITEM_BREAK;
|
SoundEvent theSound = SoundEvents.ITEM_BREAK;
|
||||||
|
|
36
src/main/java/dev/zontreck/mcmods/Health.java
Normal file
36
src/main/java/dev/zontreck/mcmods/Health.java
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
package dev.zontreck.mcmods;
|
||||||
|
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
|
||||||
|
public class Health {
|
||||||
|
|
||||||
|
public float maximum;
|
||||||
|
public float current;
|
||||||
|
|
||||||
|
public int asPercent()
|
||||||
|
{
|
||||||
|
return (int)Math.round(Math.abs((current * 100 / maximum)));
|
||||||
|
}
|
||||||
|
public Health lastHealthState;
|
||||||
|
|
||||||
|
|
||||||
|
public static Health of(Player player){
|
||||||
|
Health obj = new Health();
|
||||||
|
obj.current = player.getHealth();
|
||||||
|
obj.maximum = player.getMaxHealth();
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean shouldGiveAlert()
|
||||||
|
{
|
||||||
|
if(asPercent()<=50){
|
||||||
|
return true;
|
||||||
|
}else return false;
|
||||||
|
}
|
||||||
|
public boolean identical(Health other)
|
||||||
|
{
|
||||||
|
if(other.current == current && other.maximum == maximum)return true;
|
||||||
|
else return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,9 @@ public class ItemRegistry {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Health {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<String,Map<Integer, Item>> CachedItems;
|
public Map<String,Map<Integer, Item>> CachedItems;
|
||||||
public ItemRegistry()
|
public ItemRegistry()
|
||||||
|
|
|
@ -2,7 +2,10 @@ package dev.zontreck.mcmods;
|
||||||
|
|
||||||
import com.mojang.logging.LogUtils;
|
import com.mojang.logging.LogUtils;
|
||||||
|
|
||||||
|
import dev.zontreck.libzontreck.chat.ChatColorFactory;
|
||||||
|
import dev.zontreck.libzontreck.chat.ChatColor.ColorOptions;
|
||||||
import dev.zontreck.mcmods.configs.WMDClientConfig;
|
import dev.zontreck.mcmods.configs.WMDClientConfig;
|
||||||
|
import dev.zontreck.mcmods.gui.HeartsRenderer;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.User;
|
import net.minecraft.client.User;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
@ -34,17 +37,21 @@ public class WatchMyDurability
|
||||||
public static User CurrentUser = null; // This is initialized by the client
|
public static User CurrentUser = null; // This is initialized by the client
|
||||||
public static boolean isInGame = false; // This locks the timer thread
|
public static boolean isInGame = false; // This locks the timer thread
|
||||||
public static ItemRegistry REGISTRY;
|
public static ItemRegistry REGISTRY;
|
||||||
|
public static Health LastHealth;
|
||||||
|
public static String WMDPrefix;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public WatchMyDurability()
|
public WatchMyDurability()
|
||||||
{
|
{
|
||||||
|
WMDPrefix = ChatColorFactory.MakeBuilder().set(ColorOptions.Dark_Gray).toString() + "[" + ChatColorFactory.MakeBuilder().set(ColorOptions.Dark_Green) + "WMD" + ChatColorFactory.MakeBuilder().set(ColorOptions.Dark_Gray) + "]";
|
||||||
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
|
||||||
|
|
||||||
// Register the commonSetup method for modloading
|
// Register the commonSetup method for modloading
|
||||||
modEventBus.addListener(this::commonSetup);
|
modEventBus.addListener(this::commonSetup);
|
||||||
ModLoadingContext.get().registerConfig(Type.CLIENT, WMDClientConfig.SPEC, "watchmydurability-client.toml");
|
ModLoadingContext.get().registerConfig(Type.CLIENT, WMDClientConfig.SPEC, "watchmydurability-client.toml");
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register(new HeartsRenderer());
|
||||||
// Register ourselves for server and other game events we are interested in
|
// Register ourselves for server and other game events we are interested in
|
||||||
MinecraftForge.EVENT_BUS.register(this);
|
MinecraftForge.EVENT_BUS.register(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@ public class WMDClientConfig {
|
||||||
public static ForgeConfigSpec.ConfigValue<List<Integer>> alertPercents;
|
public static ForgeConfigSpec.ConfigValue<List<Integer>> alertPercents;
|
||||||
public static ForgeConfigSpec.ConfigValue<List<String>> alertMessages;
|
public static ForgeConfigSpec.ConfigValue<List<String>> alertMessages;
|
||||||
public static ForgeConfigSpec.ConfigValue<Integer> TimerVal;
|
public static ForgeConfigSpec.ConfigValue<Integer> TimerVal;
|
||||||
|
public static ForgeConfigSpec.ConfigValue<Boolean> EnableExtraHearts;
|
||||||
|
public static ForgeConfigSpec.ConfigValue<Boolean> EnableHealthAlert;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
List<Integer> alerts1 = new ArrayList<>();
|
List<Integer> alerts1 = new ArrayList<>();
|
||||||
alerts1.add(10);
|
alerts1.add(10);
|
||||||
|
@ -28,6 +31,12 @@ public class WMDClientConfig {
|
||||||
TimerVal = BUILDER.comment("How many seconds between timer ticks to check your inventory items?").define("Timer", 5);
|
TimerVal = BUILDER.comment("How many seconds between timer ticks to check your inventory items?").define("Timer", 5);
|
||||||
|
|
||||||
BUILDER.pop();
|
BUILDER.pop();
|
||||||
|
|
||||||
|
BUILDER.push("General");
|
||||||
|
EnableExtraHearts = BUILDER.comment("Whether to enable the extra hearts rendering").define("compress_hearts", false);
|
||||||
|
EnableHealthAlert = BUILDER.comment("The following was added for a friend. If you need reminders to eat in order to heal, turn the below option on").define("watchMyHunger", false);
|
||||||
|
|
||||||
|
|
||||||
SPEC=BUILDER.build();
|
SPEC=BUILDER.build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
333
src/main/java/dev/zontreck/mcmods/gui/HeartsRenderer.java
Normal file
333
src/main/java/dev/zontreck/mcmods/gui/HeartsRenderer.java
Normal file
|
@ -0,0 +1,333 @@
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
* DISCLAIMER: This code was taken from Mantle, and will be modified to fit the needs of this mod, such as adding more heat options. This code is subject to Mantle's license of MIT.
|
||||||
|
* Despite this code being taken from, and modified/updated to be modern, all textures are my own creation
|
||||||
|
* This disclaimer is here to give credit where credit is due. The author(s) of mantle have done a absolutely fantastic job. And if Mantle gets updated this shall be removed along with future plans of extra hearts and color options.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dev.zontreck.mcmods.gui;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
|
|
||||||
|
import dev.zontreck.mcmods.WatchMyDurability;
|
||||||
|
import dev.zontreck.mcmods.configs.WMDClientConfig;
|
||||||
|
import net.minecraft.Util;
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.gui.GuiComponent;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.util.Mth;
|
||||||
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
|
import net.minecraft.world.effect.MobEffects;
|
||||||
|
import net.minecraft.world.entity.Entity;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraftforge.client.event.RenderGuiOverlayEvent;
|
||||||
|
import net.minecraftforge.client.gui.overlay.ForgeGui;
|
||||||
|
import net.minecraftforge.client.gui.overlay.GuiOverlayManager;
|
||||||
|
import net.minecraftforge.client.gui.overlay.NamedGuiOverlay;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.eventbus.api.EventPriority;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class HeartsRenderer {
|
||||||
|
private static final ResourceLocation ICON_HEARTS = new ResourceLocation(WatchMyDurability.MODID,
|
||||||
|
"textures/gui/hearts.png");
|
||||||
|
private static final ResourceLocation ICON_ABSORB = new ResourceLocation(WatchMyDurability.MODID,
|
||||||
|
"textures/gui/absorb.png");
|
||||||
|
private static final ResourceLocation ICON_VANILLA = GuiComponent.GUI_ICONS_LOCATION;
|
||||||
|
|
||||||
|
private final Minecraft mc = Minecraft.getInstance();
|
||||||
|
|
||||||
|
private int playerHealth = 0;
|
||||||
|
private int lastPlayerHealth = 0;
|
||||||
|
private long healthUpdateCounter = 0;
|
||||||
|
private long lastSystemTime = 0;
|
||||||
|
private final Random rand = new Random();
|
||||||
|
|
||||||
|
private int regen;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws a texture to the screen
|
||||||
|
*
|
||||||
|
* @param matrixStack Matrix stack instance
|
||||||
|
* @param x X position
|
||||||
|
* @param y Y position
|
||||||
|
* @param textureX Texture X
|
||||||
|
* @param textureY Texture Y
|
||||||
|
* @param width Width to draw
|
||||||
|
* @param height Height to draw
|
||||||
|
*/
|
||||||
|
private void blit(PoseStack matrixStack, int x, int y, int textureX, int textureY, int width, int height) {
|
||||||
|
Minecraft.getInstance().gui.blit(matrixStack, x, y, textureX, textureY, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* HUD */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event listener
|
||||||
|
*
|
||||||
|
* @param event Event instance
|
||||||
|
*/
|
||||||
|
@SubscribeEvent(priority = EventPriority.LOW)
|
||||||
|
public void renderHealthbar(RenderGuiOverlayEvent.Pre event) {
|
||||||
|
NamedGuiOverlay ActualOverlay = GuiOverlayManager.findOverlay(new ResourceLocation("minecraft:player_health"));
|
||||||
|
|
||||||
|
if (ActualOverlay == null) {
|
||||||
|
if (GuiOverlayManager.getOverlays() == null) {
|
||||||
|
WatchMyDurability.LOGGER.info("Overlays non existent?!");
|
||||||
|
}
|
||||||
|
for (NamedGuiOverlay overlay : GuiOverlayManager.getOverlays()) {
|
||||||
|
// Next print
|
||||||
|
// LibZontreck.LOGGER.info("GUI OVERLAY: "+overlay.id().getPath());
|
||||||
|
|
||||||
|
if (overlay.id().getPath().equals("player_health")) {
|
||||||
|
ActualOverlay = overlay;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event.isCanceled() || !WMDClientConfig.EnableExtraHearts.get() || event.getOverlay() != ActualOverlay) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// ensure its visible
|
||||||
|
if (!(mc.gui instanceof ForgeGui gui) || mc.options.hideGui || !gui.shouldDrawSurvivalElements()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Entity renderViewEnity = this.mc.getCameraEntity();
|
||||||
|
if (!(renderViewEnity instanceof Player player)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gui.setupOverlayRenderState(true, false);
|
||||||
|
|
||||||
|
this.mc.getProfiler().push("health");
|
||||||
|
|
||||||
|
// extra setup stuff from us
|
||||||
|
int left_height = gui.leftHeight;
|
||||||
|
int width = this.mc.getWindow().getGuiScaledWidth();
|
||||||
|
int height = this.mc.getWindow().getGuiScaledHeight();
|
||||||
|
int updateCounter = this.mc.gui.getGuiTicks();
|
||||||
|
|
||||||
|
// start default forge/mc rendering
|
||||||
|
// changes are indicated by comment
|
||||||
|
|
||||||
|
int health = Mth.ceil(player.getHealth());
|
||||||
|
boolean highlight = this.healthUpdateCounter > (long) updateCounter
|
||||||
|
&& (this.healthUpdateCounter - (long) updateCounter) / 3L % 2L == 1L;
|
||||||
|
|
||||||
|
if (health < this.playerHealth && player.invulnerableTime > 0) {
|
||||||
|
this.lastSystemTime = Util.getMillis();
|
||||||
|
this.healthUpdateCounter = (updateCounter + 20);
|
||||||
|
} else if (health > this.playerHealth && player.invulnerableTime > 0) {
|
||||||
|
this.lastSystemTime = Util.getMillis();
|
||||||
|
this.healthUpdateCounter = (updateCounter + 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Util.getMillis() - this.lastSystemTime > 1000L) {
|
||||||
|
this.playerHealth = health;
|
||||||
|
this.lastPlayerHealth = health;
|
||||||
|
this.lastSystemTime = Util.getMillis();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.playerHealth = health;
|
||||||
|
int healthLast = this.lastPlayerHealth;
|
||||||
|
|
||||||
|
AttributeInstance attrMaxHealth = player.getAttribute(Attributes.MAX_HEALTH);
|
||||||
|
float healthMax = attrMaxHealth == null ? 0 : (float) attrMaxHealth.getValue();
|
||||||
|
float absorb = Mth.ceil(player.getAbsorptionAmount());
|
||||||
|
|
||||||
|
// CHANGE: simulate 10 hearts max if there's more, so vanilla only renders one
|
||||||
|
// row max
|
||||||
|
healthMax = Math.min(healthMax, 20f);
|
||||||
|
health = Math.min(health, 20);
|
||||||
|
absorb = Math.min(absorb, 20);
|
||||||
|
|
||||||
|
int healthRows = Mth.ceil((healthMax + absorb) / 2.0F / 10.0F);
|
||||||
|
int rowHeight = Math.max(10 - (healthRows - 2), 3);
|
||||||
|
|
||||||
|
this.rand.setSeed(updateCounter * 312871L);
|
||||||
|
|
||||||
|
int left = width / 2 - 91;
|
||||||
|
int top = height - left_height;
|
||||||
|
// change: these are unused below, unneeded? should these adjust the Forge
|
||||||
|
// variable?
|
||||||
|
// left_height += (healthRows * rowHeight);
|
||||||
|
// if (rowHeight != 10) left_height += 10 - rowHeight;
|
||||||
|
|
||||||
|
this.regen = -1;
|
||||||
|
if (player.hasEffect(MobEffects.REGENERATION)) {
|
||||||
|
this.regen = updateCounter % 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert this.mc.level != null;
|
||||||
|
final int TOP = 9 * (this.mc.level.getLevelData().isHardcore() ? 5 : 0);
|
||||||
|
final int BACKGROUND = (highlight ? 25 : 16);
|
||||||
|
int MARGIN = 16;
|
||||||
|
if (player.hasEffect(MobEffects.POISON))
|
||||||
|
MARGIN += 36;
|
||||||
|
else if (player.hasEffect(MobEffects.WITHER))
|
||||||
|
MARGIN += 72;
|
||||||
|
float absorbRemaining = absorb;
|
||||||
|
|
||||||
|
PoseStack matrixStack = event.getPoseStack();
|
||||||
|
for (int i = Mth.ceil((healthMax + absorb) / 2.0F) - 1; i >= 0; --i) {
|
||||||
|
int row = Mth.ceil((float) (i + 1) / 10.0F) - 1;
|
||||||
|
int x = left + i % 10 * 8;
|
||||||
|
int y = top - row * rowHeight;
|
||||||
|
|
||||||
|
if (health <= 4)
|
||||||
|
y += this.rand.nextInt(2);
|
||||||
|
if (i == this.regen)
|
||||||
|
y -= 2;
|
||||||
|
|
||||||
|
this.blit(matrixStack, x, y, BACKGROUND, TOP, 9, 9);
|
||||||
|
|
||||||
|
if (highlight) {
|
||||||
|
if (i * 2 + 1 < healthLast) {
|
||||||
|
this.blit(matrixStack, x, y, MARGIN + 54, TOP, 9, 9); // 6
|
||||||
|
} else if (i * 2 + 1 == healthLast) {
|
||||||
|
this.blit(matrixStack, x, y, MARGIN + 63, TOP, 9, 9); // 7
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (absorbRemaining > 0.0F) {
|
||||||
|
if (absorbRemaining == absorb && absorb % 2.0F == 1.0F) {
|
||||||
|
this.blit(matrixStack, x, y, MARGIN + 153, TOP, 9, 9); // 17
|
||||||
|
absorbRemaining -= 1.0F;
|
||||||
|
} else {
|
||||||
|
this.blit(matrixStack, x, y, MARGIN + 144, TOP, 9, 9); // 16
|
||||||
|
absorbRemaining -= 2.0F;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (i * 2 + 1 < health) {
|
||||||
|
this.blit(matrixStack, x, y, MARGIN + 36, TOP, 9, 9); // 4
|
||||||
|
} else if (i * 2 + 1 == health) {
|
||||||
|
this.blit(matrixStack, x, y, MARGIN + 45, TOP, 9, 9); // 5
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.renderExtraHearts(matrixStack, left, top, player);
|
||||||
|
this.renderExtraAbsorption(matrixStack, left, top - rowHeight, player);
|
||||||
|
|
||||||
|
RenderSystem.setShaderTexture(0, ICON_VANILLA);
|
||||||
|
gui.leftHeight += 10;
|
||||||
|
if (absorb > 0) {
|
||||||
|
gui.leftHeight += 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setCanceled(true);
|
||||||
|
RenderSystem.disableBlend();
|
||||||
|
this.mc.getProfiler().pop();
|
||||||
|
MinecraftForge.EVENT_BUS
|
||||||
|
.post(new RenderGuiOverlayEvent.Post(mc.getWindow(), matrixStack, event.getPartialTick(), ActualOverlay));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the texture from potion effects
|
||||||
|
*
|
||||||
|
* @param player Player instance
|
||||||
|
* @return Texture offset for potion effects
|
||||||
|
*/
|
||||||
|
private int getPotionOffset(Player player) {
|
||||||
|
int potionOffset = 0;
|
||||||
|
MobEffectInstance potion = player.getEffect(MobEffects.WITHER);
|
||||||
|
if (potion != null) {
|
||||||
|
potionOffset = 18;
|
||||||
|
}
|
||||||
|
potion = player.getEffect(MobEffects.POISON);
|
||||||
|
if (potion != null) {
|
||||||
|
potionOffset = 9;
|
||||||
|
}
|
||||||
|
assert this.mc.level != null;
|
||||||
|
if (this.mc.level.getLevelData().isHardcore()) {
|
||||||
|
potionOffset += 27;
|
||||||
|
}
|
||||||
|
return potionOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the health above 10 hearts
|
||||||
|
*
|
||||||
|
* @param matrixStack Matrix stack instance
|
||||||
|
* @param xBasePos Health bar top corner
|
||||||
|
* @param yBasePos Health bar top corner
|
||||||
|
* @param player Player instance
|
||||||
|
*/
|
||||||
|
private void renderExtraHearts(PoseStack matrixStack, int xBasePos, int yBasePos, Player player) {
|
||||||
|
int potionOffset = this.getPotionOffset(player);
|
||||||
|
|
||||||
|
// Extra hearts
|
||||||
|
RenderSystem.setShaderTexture(0, ICON_HEARTS);
|
||||||
|
int hp = Mth.ceil(player.getHealth());
|
||||||
|
this.renderCustomHearts(matrixStack, xBasePos, yBasePos, potionOffset, hp, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the absorption health above 10 hearts
|
||||||
|
*
|
||||||
|
* @param matrixStack Matrix stack instance
|
||||||
|
* @param xBasePos Health bar top corner
|
||||||
|
* @param yBasePos Health bar top corner
|
||||||
|
* @param player Player instance
|
||||||
|
*/
|
||||||
|
private void renderExtraAbsorption(PoseStack matrixStack, int xBasePos, int yBasePos, Player player) {
|
||||||
|
int potionOffset = this.getPotionOffset(player);
|
||||||
|
|
||||||
|
// Extra hearts
|
||||||
|
RenderSystem.setShaderTexture(0, ICON_ABSORB);
|
||||||
|
int absorb = Mth.ceil(player.getAbsorptionAmount());
|
||||||
|
this.renderCustomHearts(matrixStack, xBasePos, yBasePos, potionOffset, absorb, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the texture offset from the regen effect
|
||||||
|
*
|
||||||
|
* @param i Heart index
|
||||||
|
* @param offset Current offset
|
||||||
|
*/
|
||||||
|
private int getYRegenOffset(int i, int offset) {
|
||||||
|
return i + offset == this.regen ? -2 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared logic to render custom hearts
|
||||||
|
*
|
||||||
|
* @param matrixStack Matrix stack instance
|
||||||
|
* @param xBasePos Health bar top corner
|
||||||
|
* @param yBasePos Health bar top corner
|
||||||
|
* @param potionOffset Offset from the potion effect
|
||||||
|
* @param count Number to render
|
||||||
|
* @param absorb If true, render absorption hearts
|
||||||
|
*/
|
||||||
|
private void renderCustomHearts(PoseStack matrixStack, int xBasePos, int yBasePos, int potionOffset, int count,
|
||||||
|
boolean absorb) {
|
||||||
|
int regenOffset = absorb ? 10 : 0;
|
||||||
|
for (int iter = 0; iter < count / 20; iter++) {
|
||||||
|
int renderHearts = (count - 20 * (iter + 1)) / 2;
|
||||||
|
int heartIndex = iter % 11;
|
||||||
|
if (renderHearts > 10) {
|
||||||
|
renderHearts = 10;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < renderHearts; i++) {
|
||||||
|
int y = this.getYRegenOffset(i, regenOffset);
|
||||||
|
if (absorb) {
|
||||||
|
this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 0, 54, 9, 9);
|
||||||
|
}
|
||||||
|
this.blit(matrixStack, xBasePos + 8 * i, yBasePos + y, 18 * heartIndex, potionOffset, 9, 9);
|
||||||
|
}
|
||||||
|
if (count % 2 == 1 && renderHearts < 10) {
|
||||||
|
int y = this.getYRegenOffset(renderHearts, regenOffset);
|
||||||
|
if (absorb) {
|
||||||
|
this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 0, 54, 9, 9);
|
||||||
|
}
|
||||||
|
this.blit(matrixStack, xBasePos + 8 * renderHearts, yBasePos + y, 9 + 18 * heartIndex, potionOffset, 9, 9);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ modId="watchmydurability" #mandatory
|
||||||
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
# The version number of the mod - there's a few well known ${} variables useable here or just hardcode it
|
||||||
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
# ${file.jarVersion} will substitute the value of the Implementation-Version as read from the mod's JAR file metadata
|
||||||
# see the associated build.gradle script for how to populate this completely automatically during a build
|
# see the associated build.gradle script for how to populate this completely automatically during a build
|
||||||
version="${file.jarVersion}" #mandatory
|
version="1.1.1" #mandatory
|
||||||
# A display name for the mod
|
# A display name for the mod
|
||||||
displayName="Watch My Durability" #mandatory
|
displayName="Watch My Durability" #mandatory
|
||||||
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
|
# A URL to query for updates for this mod. See the JSON update specification https://mcforge.readthedocs.io/en/latest/gettingstarted/autoupdate/
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 4.7 KiB |
Binary file not shown.
After Width: | Height: | Size: 4.5 KiB |
Reference in a new issue