diff --git a/gradle.properties b/gradle.properties index 5acae1d..8a18026 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -libzontreck=1.10.010924.1444 +libzontreck=1.10.011024.0312 ## Environment Properties @@ -49,7 +49,7 @@ mod_name=WatchMyDurability # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1.2.010924.1451 +mod_version=1.2.011024.0208 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/wmd/WatchMyDurability.java b/src/main/java/dev/zontreck/wmd/WatchMyDurability.java index 07c8b6c..1707751 100644 --- a/src/main/java/dev/zontreck/wmd/WatchMyDurability.java +++ b/src/main/java/dev/zontreck/wmd/WatchMyDurability.java @@ -7,13 +7,15 @@ import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.wmd.checkers.CheckHealth; import dev.zontreck.wmd.checkers.CheckHunger; import dev.zontreck.wmd.checkers.CheckInventory; +import dev.zontreck.wmd.commands.ModCommands; import dev.zontreck.wmd.configs.WMDClientConfig; +import dev.zontreck.wmd.networking.ModMessages; import dev.zontreck.wmd.types.Health; import dev.zontreck.wmd.types.Hunger; import dev.zontreck.wmd.types.ItemRegistry; import net.minecraft.client.Minecraft; import net.minecraft.client.User; -import net.minecraft.sounds.SoundEvent; +import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -45,13 +47,12 @@ public class WatchMyDurability public static ItemRegistry REGISTRY; public static Health LastHealth; public static Hunger LastHunger; - public static String WMDPrefix; + public static boolean WMD_SERVER_AVAILABLE =false; public WatchMyDurability() { - WatchMyDurability.WMDPrefix = ChatColor.doColors("!Dark_Gray![!Bold!!Dark_Green!WMD!Reset!!Dark_Gray!]!reset!"); IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); @@ -61,20 +62,17 @@ public class WatchMyDurability // Register ourselves for server and other game events we are interested in MinecraftForge.EVENT_BUS.register(this); + MinecraftForge.EVENT_BUS.register(new ModCommands()); } private void commonSetup(final FMLCommonSetupEvent event) { // Some common setup code //LOGGER.info("HELLO FROM COMMON SETUP"); + ModMessages.register(); } - 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) @@ -84,7 +82,7 @@ public class WatchMyDurability } // You can use EventBusSubscriber to automatically register all static methods in the class annotated with @SubscribeEvent - @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD) + @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public static class ClientModEvents { static Timer time = new Timer(); @@ -92,7 +90,7 @@ public class WatchMyDurability @SubscribeEvent public static void onClientSetup(FMLClientSetupEvent event) { - LOGGER.info(WMDPrefix+": : : CLIENT SETUP : : :"); + LOGGER.info(": : : CLIENT SETUP : : :"); // Some client setup code //LOGGER.info("HELLO FROM CLIENT SETUP"); //LOGGER.info("MINECRAFT NAME >> {}", Minecraft.getInstance().getUser().getName()); @@ -110,7 +108,7 @@ public class WatchMyDurability } - @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE) + @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT) public static class ClientEvents { @@ -118,7 +116,7 @@ public class WatchMyDurability public static void onJoin(ClientPlayerNetworkEvent.LoggingIn event){ // Joined //LOGGER.info("PLAYER LOGGED IN"); - LOGGER.info(WMDPrefix+": : : PLAYER LOGGED IN : : :"); + LOGGER.info(": : : PLAYER LOGGED IN : : :"); WatchMyDurability.isInGame=true; DelayedExecutorService.start(); @@ -130,15 +128,16 @@ public class WatchMyDurability @SubscribeEvent public static void onLeave(ClientPlayerNetworkEvent.LoggingOut event){ //LOGGER.info("PLAYER LOGGED OUT"); - LOGGER.info(WMDPrefix+": : : PLAYER LOGGED OUT : : :"); + LOGGER.info(": : : PLAYER LOGGED OUT : : :"); WatchMyDurability.isInGame=false; + WatchMyDurability.WMD_SERVER_AVAILABLE=false; DelayedExecutorService.stop(); } @SubscribeEvent public static void onClone(ClientPlayerNetworkEvent.Clone event) { - LOGGER.info(WMDPrefix+": : : : PLAYER RESPAWNED OR MOVED TO A NEW WORLD : : : :"); + LOGGER.info(": : : : PLAYER RESPAWNED OR MOVED TO A NEW WORLD : : : :"); } } diff --git a/src/main/java/dev/zontreck/wmd/checkers/CheckHealth.java b/src/main/java/dev/zontreck/wmd/checkers/CheckHealth.java index 590246a..3578a62 100644 --- a/src/main/java/dev/zontreck/wmd/checkers/CheckHealth.java +++ b/src/main/java/dev/zontreck/wmd/checkers/CheckHealth.java @@ -5,6 +5,7 @@ import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.wmd.types.Health; import dev.zontreck.wmd.WatchMyDurability; import dev.zontreck.wmd.configs.WMDClientConfig; +import dev.zontreck.wmd.utils.client.Helpers; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundEvent; @@ -43,7 +44,7 @@ public class CheckHealth extends Task Minecraft.getInstance().player.displayClientMessage(chat, false); SoundEvent sv = SoundEvents.WARDEN_ROAR; // It sounds like a growling stomach - WatchMyDurability.Soundify(sv); + Helpers.Soundify(sv); } WatchMyDurability.LastHealth=current; diff --git a/src/main/java/dev/zontreck/wmd/checkers/CheckHunger.java b/src/main/java/dev/zontreck/wmd/checkers/CheckHunger.java index c43557f..58e2654 100644 --- a/src/main/java/dev/zontreck/wmd/checkers/CheckHunger.java +++ b/src/main/java/dev/zontreck/wmd/checkers/CheckHunger.java @@ -5,6 +5,7 @@ import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.wmd.types.Hunger; import dev.zontreck.wmd.WatchMyDurability; import dev.zontreck.wmd.configs.WMDClientConfig; +import dev.zontreck.wmd.utils.client.Helpers; import net.minecraft.client.Minecraft; import net.minecraft.network.chat.Component; import net.minecraft.sounds.SoundEvent; @@ -39,7 +40,7 @@ public class CheckHunger extends Task Minecraft.getInstance().player.displayClientMessage(chat, false); SoundEvent sv = SoundEvents.WARDEN_ROAR; // It sounds like a growling stomach - WatchMyDurability.Soundify(sv); + Helpers.Soundify(sv); } WatchMyDurability.LastHunger = current; diff --git a/src/main/java/dev/zontreck/wmd/checkers/CheckInventory.java b/src/main/java/dev/zontreck/wmd/checkers/CheckInventory.java index e5703f7..fbb112a 100644 --- a/src/main/java/dev/zontreck/wmd/checkers/CheckInventory.java +++ b/src/main/java/dev/zontreck/wmd/checkers/CheckInventory.java @@ -7,9 +7,11 @@ import java.util.Map; import dev.zontreck.ariaslib.terminal.Task; import dev.zontreck.libzontreck.chat.ChatColor; import dev.zontreck.libzontreck.chat.HoverTip; +import dev.zontreck.libzontreck.util.ChatHelpers; import dev.zontreck.wmd.types.ItemRegistry; import dev.zontreck.wmd.WatchMyDurability; import dev.zontreck.wmd.configs.WMDClientConfig; +import dev.zontreck.wmd.utils.client.Helpers; import net.minecraft.client.Minecraft; import net.minecraft.core.NonNullList; import net.minecraft.network.chat.Component; @@ -34,6 +36,7 @@ public class CheckInventory extends Task { @Override public void run() { + if(!WMDClientConfig.EnableToolWatcher.get()) return; try { if(!WatchMyDurability.isInGame)return; @@ -95,11 +98,11 @@ public class CheckInventory extends Task { String entryStr = WMDClientConfig.alertMessages.get().get(idx); if(percent <= entry){ - String replaced = WatchMyDurability.WMDPrefix + ChatColor.DARK_RED + entryStr.replaceAll("!item!", is1.getDisplayName().getString()); + String replaced = ChatColor.doColors(WMDClientConfig.WMD_PREFIX.get()) + ChatColor.DARK_RED + entryStr.replaceAll("!item!", is1.getDisplayName().getString()); WatchMyDurability.LOGGER.info("Enqueue alert for an item. Playing sound for item: "+is1.getDisplayName().getString()); SoundEvent theSound = SoundEvents.ITEM_BREAK; - WatchMyDurability.Soundify(theSound); + Helpers.Soundify(theSound); diff --git a/src/main/java/dev/zontreck/wmd/commands/ModCommands.java b/src/main/java/dev/zontreck/wmd/commands/ModCommands.java new file mode 100644 index 0000000..8541f01 --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/commands/ModCommands.java @@ -0,0 +1,14 @@ +package dev.zontreck.wmd.commands; + +import dev.zontreck.wmd.commands.impl.SettingsCommand; +import net.minecraftforge.event.RegisterCommandsEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class ModCommands +{ + @SubscribeEvent + public void register(final RegisterCommandsEvent event) + { + SettingsCommand.register(event.getDispatcher()); + } +} diff --git a/src/main/java/dev/zontreck/wmd/commands/impl/SettingsCommand.java b/src/main/java/dev/zontreck/wmd/commands/impl/SettingsCommand.java new file mode 100644 index 0000000..c52215d --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/commands/impl/SettingsCommand.java @@ -0,0 +1,21 @@ +package dev.zontreck.wmd.commands.impl; + +import com.mojang.brigadier.CommandDispatcher; +import dev.zontreck.wmd.networking.ModMessages; +import dev.zontreck.wmd.networking.packets.s2c.RequestClientConfig; +import net.minecraft.commands.CommandSourceStack; +import net.minecraft.commands.Commands; + +public class SettingsCommand +{ + public static void register(CommandDispatcher dispatcher) + { + dispatcher.register(Commands.literal("wmdsettings").executes(c->settingsPrompt(c.getSource()))); + } + + public static int settingsPrompt(CommandSourceStack sender) + { + ModMessages.sendToPlayer(new RequestClientConfig(), sender.getPlayer()); + return 0; + } +} diff --git a/src/main/java/dev/zontreck/wmd/configs/WMDClientConfig.java b/src/main/java/dev/zontreck/wmd/configs/WMDClientConfig.java index 980092e..7c27ba3 100644 --- a/src/main/java/dev/zontreck/wmd/configs/WMDClientConfig.java +++ b/src/main/java/dev/zontreck/wmd/configs/WMDClientConfig.java @@ -3,6 +3,7 @@ package dev.zontreck.wmd.configs; import java.util.ArrayList; import java.util.List; +import net.minecraft.nbt.CompoundTag; import net.minecraftforge.common.ForgeConfigSpec; public class WMDClientConfig { @@ -12,9 +13,12 @@ public class WMDClientConfig { public static ForgeConfigSpec.ConfigValue> alertPercents; public static ForgeConfigSpec.ConfigValue> alertMessages; public static ForgeConfigSpec.ConfigValue TimerVal; - public static ForgeConfigSpec.ConfigValue EnableExtraHearts; public static ForgeConfigSpec.ConfigValue EnableHealthAlert; public static ForgeConfigSpec.ConfigValue EnableHungerAlert; + public static ForgeConfigSpec.ConfigValue EnableToolWatcher; + + + public static ForgeConfigSpec.ConfigValue WMD_PREFIX; static{ List alerts1 = new ArrayList<>(); @@ -35,8 +39,40 @@ public class WMDClientConfig { BUILDER.push("General"); 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); + 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", false); + EnableToolWatcher = BUILDER.comment("Enable watching tool durability").define("watchDurability", true); + BUILDER.pop(); + + + BUILDER.push("Messages"); + + WMD_PREFIX = BUILDER.comment("The prefix string for WMD").define("prefix", "!Dark_Gray![!Bold!!Dark_Green!WMD!Reset!!Dark_Gray!]!Reset!"); SPEC=BUILDER.build(); } + + public static CompoundTag serialize() + { + CompoundTag ret = new CompoundTag(); + + ret.putBoolean("watchMyHealth", EnableHealthAlert.get()); + ret.putBoolean("watchMyHunger", EnableHungerAlert.get()); + ret.putBoolean("watchDurability", EnableToolWatcher.get()); + + + + return ret; + } + + public static void deserialize(CompoundTag tag) + { + EnableHealthAlert.set(tag.getBoolean("watchMyHealth")); + EnableHealthAlert.save(); + + EnableHungerAlert.set(tag.getBoolean("watchMyHunger")); + EnableHungerAlert.save(); + + EnableToolWatcher.set(tag.getBoolean("watchDurability")); + EnableToolWatcher.save(); + } } diff --git a/src/main/java/dev/zontreck/wmd/events/EventHandler.java b/src/main/java/dev/zontreck/wmd/events/EventHandler.java new file mode 100644 index 0000000..a304a75 --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/events/EventHandler.java @@ -0,0 +1,17 @@ +package dev.zontreck.wmd.events; + +import dev.zontreck.libzontreck.LibZontreck; +import dev.zontreck.wmd.WatchMyDurability; +import dev.zontreck.wmd.networking.packets.s2c.WMDServerAvailable; +import net.minecraftforge.event.entity.player.PlayerEvent; +import net.minecraftforge.eventbus.api.SubscribeEvent; + +public class EventHandler +{ + @SubscribeEvent + public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) + { + WMDServerAvailable avail = new WMDServerAvailable(); + avail.send(event.getEntity().getUUID()); + } +} diff --git a/src/main/java/dev/zontreck/wmd/networking/ModMessages.java b/src/main/java/dev/zontreck/wmd/networking/ModMessages.java new file mode 100644 index 0000000..727b396 --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/networking/ModMessages.java @@ -0,0 +1,76 @@ +package dev.zontreck.wmd.networking; + +import dev.zontreck.wmd.WatchMyDurability; +import dev.zontreck.wmd.networking.packets.c2s.ClientConfigResponse; +import dev.zontreck.wmd.networking.packets.s2c.*; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraftforge.network.NetworkDirection; +import net.minecraftforge.network.NetworkRegistry; +import net.minecraftforge.network.PacketDistributor; +import net.minecraftforge.network.simple.SimpleChannel; + +public class ModMessages +{ + private static SimpleChannel channel; + private static int PACKET_ID = 0; + private static int id() + { + return PACKET_ID++; + } + + public static void register() + { + SimpleChannel net = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(WatchMyDurability.MODID, "messages")) + .networkProtocolVersion(()->"1.0") + .clientAcceptedVersions(s->true) + .serverAcceptedVersions(s->true) + .simpleChannel(); + channel = net; + + net.messageBuilder(WMDServerAvailable.class, id(), NetworkDirection.PLAY_TO_CLIENT) + .encoder(WMDServerAvailable::toBytes) + .decoder(WMDServerAvailable::new) + .consumerMainThread(WMDServerAvailable::handle) + .add(); + + net.messageBuilder(S2CResetConfig.class, id(), NetworkDirection.PLAY_TO_CLIENT) + .encoder(S2CResetConfig::toBytes) + .decoder(S2CResetConfig::new) + .consumerMainThread(S2CResetConfig::handle) + .add(); + + net.messageBuilder(RequestClientConfig.class, id(), NetworkDirection.PLAY_TO_CLIENT) + .encoder(RequestClientConfig::toBytes) + .decoder(RequestClientConfig::new) + .consumerMainThread(RequestClientConfig::handle) + .add(); + + net.messageBuilder(ClientConfigResponse.class, id(), NetworkDirection.PLAY_TO_SERVER) + .encoder(ClientConfigResponse::toBytes) + .decoder(ClientConfigResponse::new) + .consumerMainThread(ClientConfigResponse::handle) + .add(); + + net.messageBuilder(PushClientConfigUpdate.class, id(), NetworkDirection.PLAY_TO_CLIENT) + .encoder(PushClientConfigUpdate::toBytes) + .decoder(PushClientConfigUpdate::new) + .consumerMainThread(PushClientConfigUpdate::handle) + .add(); + } + + + public static void sendToServer(MSG message){ + channel.sendToServer(message); + } + + public static void sendToPlayer(MSG message, ServerPlayer player) + { + channel.send(PacketDistributor.PLAYER.with(()->player), message); + } + + public static void sendToAll(MSG message) + { + channel.send(PacketDistributor.ALL.noArg(), message); + } +} diff --git a/src/main/java/dev/zontreck/wmd/networking/packets/c2s/ClientConfigResponse.java b/src/main/java/dev/zontreck/wmd/networking/packets/c2s/ClientConfigResponse.java new file mode 100644 index 0000000..9354f18 --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/networking/packets/c2s/ClientConfigResponse.java @@ -0,0 +1,126 @@ +package dev.zontreck.wmd.networking.packets.c2s; + +import dev.zontreck.libzontreck.chat.ChatColor; +import dev.zontreck.libzontreck.chestgui.ChestGUI; +import dev.zontreck.libzontreck.chestgui.ChestGUIButton; +import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier; +import dev.zontreck.libzontreck.lore.LoreEntry; +import dev.zontreck.libzontreck.util.ServerUtilities; +import dev.zontreck.libzontreck.vectors.Vector2i; +import dev.zontreck.wmd.WatchMyDurability; +import dev.zontreck.wmd.configs.WMDClientConfig; +import dev.zontreck.wmd.networking.ModMessages; +import dev.zontreck.wmd.networking.packets.s2c.PushClientConfigUpdate; +import dev.zontreck.wmd.networking.packets.s2c.RequestClientConfig; +import dev.zontreck.wmd.networking.packets.s2c.S2CResetConfig; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraftforge.network.NetworkEvent; + +import java.util.UUID; +import java.util.function.Supplier; + +public class ClientConfigResponse +{ + public CompoundTag tag; + public UUID id; + + public ClientConfigResponse(FriendlyByteBuf buf) + { + tag = buf.readAnySizeNbt(); + id = buf.readUUID(); + } + + public ClientConfigResponse(UUID playerID) + { + tag = WMDClientConfig.serialize(); + id = playerID; + } + + public void toBytes(FriendlyByteBuf buf) + { + buf.writeNbt(tag); + buf.writeUUID(id); + } + + public void handle(Supplier supplier) + { + NetworkEvent.Context ctx = supplier.get(); + + ctx.enqueueWork(()->{ + // Open config editor for player + boolean enableHealth = tag.getBoolean("watchMyHealth"); + boolean enableHunger = tag.getBoolean("watchMyHunger"); + boolean enableDurability = tag.getBoolean("watchDurability"); + + ServerPlayer player = ServerUtilities.getPlayerByID(id.toString()); + + try { + ChestGUI prompt = ChestGUI.builder().withGUIId(new ChestGUIIdentifier("wmdsettings")).withPlayer(player.getUUID()).withTitle("WMD Settings"); + ItemStack wtd = new ItemStack(Items.DIAMOND_PICKAXE, 1); + wtd.setHoverName(Component.literal("Watch Tool Durability")); + + prompt.withButton(new ChestGUIButton(wtd, ()-> { + tag.putBoolean("watchDurability", !enableDurability); + + ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player); + + prompt.close(); + + ModMessages.sendToPlayer(new RequestClientConfig(), player); + }, new Vector2i(0,0)) + .withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableDurability ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build()) + + ); + + ItemStack wmhunger = new ItemStack(Items.APPLE, 1); + wmhunger.setHoverName(Component.literal("Watch My Hunger")); + + prompt.withButton(new ChestGUIButton(wmhunger, ()->{ + tag.putBoolean("watchMyHunger", !enableHunger); + ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player); + + prompt.close(); + ModMessages.sendToPlayer(new RequestClientConfig(), player); + }, new Vector2i(0, 1)) + .withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableHunger ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build()) + ); + ItemStack wmhealth = new ItemStack(Items.PUFFERFISH, 1); + wmhealth.setHoverName(Component.literal("Watch My Health")); + + prompt.withButton(new ChestGUIButton(wmhealth, ()->{ + tag.putBoolean("watchMyHealth", !enableHealth); + ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player); + + prompt.close(); + + ModMessages.sendToPlayer(new RequestClientConfig(), player); + }, new Vector2i(0, 2)) + .withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableHealth ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build()) + ); + + prompt.withReset(()->{ + ModMessages.sendToPlayer(new S2CResetConfig(), ServerUtilities.getPlayerByID(id.toString())); + + prompt.close(); + + ModMessages.sendToPlayer(new RequestClientConfig(), player); + }); + + + prompt.updateUtilityButtons(); + prompt.open(); + }catch(Exception e) + { + WatchMyDurability.LOGGER.error(e.getMessage()); + e.printStackTrace(); + } + + }); + } +} diff --git a/src/main/java/dev/zontreck/wmd/networking/packets/s2c/PushClientConfigUpdate.java b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/PushClientConfigUpdate.java new file mode 100644 index 0000000..3550b7c --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/PushClientConfigUpdate.java @@ -0,0 +1,36 @@ +package dev.zontreck.wmd.networking.packets.s2c; + +import dev.zontreck.wmd.configs.WMDClientConfig; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public class PushClientConfigUpdate +{ + public CompoundTag tag; + public PushClientConfigUpdate(FriendlyByteBuf buf) + { + tag = buf.readAnySizeNbt(); + } + + public PushClientConfigUpdate(CompoundTag tag) + { + this.tag=tag; + } + + public void toBytes(FriendlyByteBuf buf) + { + buf.writeNbt(tag); + } + + public void handle(Supplier supplier) + { + NetworkEvent.Context ctx = supplier.get(); + + ctx.enqueueWork(()->{ + WMDClientConfig.deserialize(tag); + }); + } +} diff --git a/src/main/java/dev/zontreck/wmd/networking/packets/s2c/RequestClientConfig.java b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/RequestClientConfig.java new file mode 100644 index 0000000..414dc0e --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/RequestClientConfig.java @@ -0,0 +1,35 @@ +package dev.zontreck.wmd.networking.packets.s2c; + +import dev.zontreck.wmd.networking.ModMessages; +import dev.zontreck.wmd.networking.packets.c2s.ClientConfigResponse; +import net.minecraft.client.Minecraft; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public class RequestClientConfig +{ + public RequestClientConfig(FriendlyByteBuf buf) + { + + } + + public RequestClientConfig(){ + + } + + public void toBytes(FriendlyByteBuf buf){ + + } + + public void handle(Supplier supplier) + { + NetworkEvent.Context ctx = supplier.get(); + + ctx.enqueueWork(()->{ + ClientConfigResponse reply = new ClientConfigResponse(Minecraft.getInstance().player.getUUID()); + ModMessages.sendToServer(reply); + }); + } +} diff --git a/src/main/java/dev/zontreck/wmd/networking/packets/s2c/S2CResetConfig.java b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/S2CResetConfig.java new file mode 100644 index 0000000..6186ae4 --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/S2CResetConfig.java @@ -0,0 +1,45 @@ +package dev.zontreck.wmd.networking.packets.s2c; + +import dev.zontreck.wmd.configs.WMDClientConfig; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; + +import java.util.function.Supplier; + +public class S2CResetConfig +{ + public S2CResetConfig(FriendlyByteBuf buf) + { + + } + + public S2CResetConfig() + { + + } + + public void toBytes(FriendlyByteBuf buf) + { + } + + public void handle(Supplier supplier) + { + NetworkEvent.Context ctx = supplier.get(); + + ctx.enqueueWork(()-> + { + + WMDClientConfig.WMD_PREFIX.set(WMDClientConfig.WMD_PREFIX.getDefault()); + WMDClientConfig.WMD_PREFIX.save(); + + WMDClientConfig.EnableHealthAlert.set(WMDClientConfig.EnableHealthAlert.getDefault()); + WMDClientConfig.EnableHealthAlert.save(); + + WMDClientConfig.EnableHungerAlert.set(WMDClientConfig.EnableHungerAlert.getDefault()); + WMDClientConfig.EnableHealthAlert.save(); + + WMDClientConfig.EnableToolWatcher.set(WMDClientConfig.EnableToolWatcher.getDefault()); + WMDClientConfig.EnableToolWatcher.save(); + }); + } +} diff --git a/src/main/java/dev/zontreck/wmd/networking/packets/s2c/WMDServerAvailable.java b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/WMDServerAvailable.java new file mode 100644 index 0000000..22ed6ac --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/networking/packets/s2c/WMDServerAvailable.java @@ -0,0 +1,42 @@ +package dev.zontreck.wmd.networking.packets.s2c; + +import dev.zontreck.libzontreck.util.ServerUtilities; +import dev.zontreck.wmd.WatchMyDurability; +import dev.zontreck.wmd.networking.ModMessages; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; + +import java.util.UUID; +import java.util.function.Supplier; + +public class WMDServerAvailable +{ + public WMDServerAvailable(FriendlyByteBuf buf) + { + + } + + public WMDServerAvailable() + { + + } + + public void toBytes(FriendlyByteBuf buf) + { + + } + + public void handle(Supplier supplier) + { + NetworkEvent.Context ctx = supplier.get(); + + ctx.enqueueWork(()->{ + WatchMyDurability.WMD_SERVER_AVAILABLE =true; + }); + } + + public void send(UUID ID) + { + ModMessages.sendToPlayer(this, ServerUtilities.getPlayerByID(ID.toString())); + } +} diff --git a/src/main/java/dev/zontreck/wmd/utils/client/Helpers.java b/src/main/java/dev/zontreck/wmd/utils/client/Helpers.java new file mode 100644 index 0000000..6ae95c9 --- /dev/null +++ b/src/main/java/dev/zontreck/wmd/utils/client/Helpers.java @@ -0,0 +1,14 @@ +package dev.zontreck.wmd.utils.client; + +import net.minecraft.client.Minecraft; +import net.minecraft.sounds.SoundEvent; + +public class Helpers +{ + + public static void Soundify(SoundEvent sound) + { + //WatchMyDurability.LOGGER.info("PLAY ALERT SOUND"); + Minecraft.getInstance().player.playSound(sound, 1.0f, 1.0f); + } +}