diff --git a/src/main/java/dev/zontreck/mcmods/CheckHealth.java b/src/main/java/dev/zontreck/mcmods/CheckHealth.java new file mode 100644 index 0000000..b8a8156 --- /dev/null +++ b/src/main/java/dev/zontreck/mcmods/CheckHealth.java @@ -0,0 +1,49 @@ +package dev.zontreck.mcmods; + +import dev.zontreck.ariaslib.terminal.Task; +import dev.zontreck.libzontreck.chat.ChatColor; +import dev.zontreck.mcmods.configs.WMDClientConfig; +import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; + +public class CheckHealth extends Task +{ + private static CheckHealth inst = new CheckHealth(); + public static CheckHealth getInstance() + { + return inst; + } + public CheckHealth() { + super("CheckHealth", true); + } + + @Override + public void run() { + + + // 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()) + { + String Msg = ChatColor.doColors("!Dark_Red!!bold!You need to eat!"); + Component chat = Component.literal(Msg); + Minecraft.getInstance().player.displayClientMessage(chat, false); + + SoundEvent sv = SoundEvents.WARDEN_ROAR; // It sounds like a growling stomach + WatchMyDurability.Soundify(sv); + } + + WatchMyDurability.LastHealth=current; + } +} diff --git a/src/main/java/dev/zontreck/mcmods/CheckHunger.java b/src/main/java/dev/zontreck/mcmods/CheckHunger.java new file mode 100644 index 0000000..bb072ed --- /dev/null +++ b/src/main/java/dev/zontreck/mcmods/CheckHunger.java @@ -0,0 +1,40 @@ +package dev.zontreck.mcmods; + +import dev.zontreck.ariaslib.terminal.Task; +import dev.zontreck.libzontreck.chat.ChatColor; +import dev.zontreck.mcmods.configs.WMDClientConfig; +import net.minecraft.client.Minecraft; +import net.minecraft.network.chat.Component; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; + +public class CheckHunger extends Task +{ + public CheckHunger() + { + super("CheckHunger", true); + } + + @Override + public void run() { + if(!WMDClientConfig.EnableHungerAlert.get()) return; + + Hunger current = Hunger.of(Minecraft.getInstance().player); + + if(current.identical()) return; + if(current.shouldGiveAlert()) + { + + String Msg = ChatColor.doColors("!Dark_Red!!bold!You need to eat!"); + Component chat = Component.literal(Msg); + Minecraft.getInstance().player.displayClientMessage(chat, false); + + SoundEvent sv = SoundEvents.WARDEN_ROAR; // It sounds like a growling stomach + WatchMyDurability.Soundify(sv); + } + + WatchMyDurability.LastHunger = current; + + + } +} diff --git a/src/main/java/dev/zontreck/mcmods/CheckInventory.java b/src/main/java/dev/zontreck/mcmods/CheckInventory.java index 4651199..2974f57 100644 --- a/src/main/java/dev/zontreck/mcmods/CheckInventory.java +++ b/src/main/java/dev/zontreck/mcmods/CheckInventory.java @@ -58,27 +58,6 @@ public class CheckInventory extends Task { } - // 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()) - { - String Msg = ChatColor.doColors("!Dark_Red!!bold!You need to eat!"); - Component chat = Component.literal(Msg); - Minecraft.getInstance().player.displayClientMessage(chat, false); - - SoundEvent sv = SoundEvents.WARDEN_ROAR; // It sounds like a growling stomach - Soundify(sv); - } - - WatchMyDurability.LastHealth=current; - } public void PushItems(String type, List stack) @@ -99,12 +78,6 @@ public class CheckInventory extends Task { ItemRegistry.register(type,items); } - public void Soundify(SoundEvent sound) - { - //WatchMyDurability.LOGGER.info("PLAY ALERT SOUND"); - Minecraft.getInstance().player.playSound(sound, 1.0f, 1.0f); - } - public void checkList(String type, NonNullList stacks){ Integer slotNum = 0; //boolean ret=false; @@ -127,7 +100,7 @@ public class CheckInventory extends Task { WatchMyDurability.LOGGER.info("Enqueue alert for an item. Playing sound for item: "+is1.getDisplayName().getString()); SoundEvent theSound = SoundEvents.ITEM_BREAK; - Soundify(theSound); + WatchMyDurability.Soundify(theSound); diff --git a/src/main/java/dev/zontreck/mcmods/Hunger.java b/src/main/java/dev/zontreck/mcmods/Hunger.java new file mode 100644 index 0000000..2b0f7cb --- /dev/null +++ b/src/main/java/dev/zontreck/mcmods/Hunger.java @@ -0,0 +1,27 @@ +package dev.zontreck.mcmods; + +import net.minecraft.world.entity.player.Player; + +public class Hunger +{ + public boolean needsToEat; + + public static Hunger of(Player player) + { + Hunger hunger = new Hunger(); + hunger.needsToEat = player.getFoodData().needsFood(); + return hunger; + } + + public boolean shouldGiveAlert() + { + if(needsToEat && !WatchMyDurability.LastHunger.needsToEat) return true; + else return false; + } + + public boolean identical() + { + if(needsToEat == WatchMyDurability.LastHunger.needsToEat) return true; + return false; + } +} diff --git a/src/main/java/dev/zontreck/mcmods/WatchMyDurability.java b/src/main/java/dev/zontreck/mcmods/WatchMyDurability.java index 8f73259..94108d3 100644 --- a/src/main/java/dev/zontreck/mcmods/WatchMyDurability.java +++ b/src/main/java/dev/zontreck/mcmods/WatchMyDurability.java @@ -7,6 +7,7 @@ import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.mcmods.configs.WMDClientConfig; import net.minecraft.client.Minecraft; import net.minecraft.client.User; +import net.minecraft.sounds.SoundEvent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.eventbus.api.IEventBus; @@ -39,6 +40,7 @@ public class WatchMyDurability public static boolean isInGame = false; // This locks the timer thread public static ItemRegistry REGISTRY; public static Health LastHealth; + public static Hunger LastHunger; public static String WMDPrefix; @@ -64,6 +66,12 @@ public class WatchMyDurability //LOGGER.info("HELLO FROM COMMON SETUP"); } + + public static void Soundify(SoundEvent sound) + { + //WatchMyDurability.LOGGER.info("PLAY ALERT SOUND"); + Minecraft.getInstance().player.playSound(sound, 1.0f, 1.0f); + } // You can use SubscribeEvent and let the Event Bus discover methods to call @SubscribeEvent public void onServerStarting(ServerStartingEvent event) @@ -96,6 +104,7 @@ public class WatchMyDurability ItemRegistry.Initialize(); } + } @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) @@ -111,6 +120,7 @@ public class WatchMyDurability DelayedExecutorService.start(); DelayedExecutorService.getInstance().schedule(CheckInventory.getInstance(), WMDClientConfig.TimerVal.get()); + DelayedExecutorService.getInstance().schedule(CheckHealth.getInstance(), WMDClientConfig.TimerVal.get()); } @SubscribeEvent diff --git a/src/main/java/dev/zontreck/mcmods/configs/WMDClientConfig.java b/src/main/java/dev/zontreck/mcmods/configs/WMDClientConfig.java index 0235027..f12611a 100644 --- a/src/main/java/dev/zontreck/mcmods/configs/WMDClientConfig.java +++ b/src/main/java/dev/zontreck/mcmods/configs/WMDClientConfig.java @@ -14,6 +14,7 @@ public class WMDClientConfig { public static ForgeConfigSpec.ConfigValue TimerVal; //public static ForgeConfigSpec.ConfigValue EnableExtraHearts; public static ForgeConfigSpec.ConfigValue EnableHealthAlert; + public static ForgeConfigSpec.ConfigValue EnableHungerAlert; static{ List alerts1 = new ArrayList<>(); @@ -34,8 +35,8 @@ public class WMDClientConfig { 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); - + 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("watchMyHealth", false); + EnableHungerAlert = BUILDER.comment("This is a newer setting to watch your hunger status instead of your hunger to alert when you need to eat").define("watchMyHunger", true); SPEC=BUILDER.build(); }