Add a basic config gui to WMD when the jar is on the server

This commit is contained in:
zontreck 2024-01-10 03:31:48 -07:00
parent 131cd673f8
commit bf2d5c83d9
16 changed files with 488 additions and 22 deletions

View file

@ -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

View file

@ -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 : : : :");
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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());
}
}

View file

@ -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<CommandSourceStack> 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;
}
}

View file

@ -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<List<Integer>> alertPercents;
public static ForgeConfigSpec.ConfigValue<List<String>> alertMessages;
public static ForgeConfigSpec.ConfigValue<Integer> TimerVal;
public static ForgeConfigSpec.ConfigValue<Boolean> EnableExtraHearts;
public static ForgeConfigSpec.ConfigValue<Boolean> EnableHealthAlert;
public static ForgeConfigSpec.ConfigValue<Boolean> EnableHungerAlert;
public static ForgeConfigSpec.ConfigValue<Boolean> EnableToolWatcher;
public static ForgeConfigSpec.ConfigValue<String> WMD_PREFIX;
static{
List<Integer> 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();
}
}

View file

@ -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());
}
}

View file

@ -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 <MSG> void sendToServer(MSG message){
channel.sendToServer(message);
}
public static <MSG> void sendToPlayer(MSG message, ServerPlayer player)
{
channel.send(PacketDistributor.PLAYER.with(()->player), message);
}
public static <MSG> void sendToAll(MSG message)
{
channel.send(PacketDistributor.ALL.noArg(), message);
}
}

View file

@ -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<NetworkEvent.Context> 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();
}
});
}
}

View file

@ -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<NetworkEvent.Context> supplier)
{
NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(()->{
WMDClientConfig.deserialize(tag);
});
}
}

View file

@ -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<NetworkEvent.Context> supplier)
{
NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(()->{
ClientConfigResponse reply = new ClientConfigResponse(Minecraft.getInstance().player.getUUID());
ModMessages.sendToServer(reply);
});
}
}

View file

@ -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<NetworkEvent.Context> 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();
});
}
}

View file

@ -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<NetworkEvent.Context> 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()));
}
}

View file

@ -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);
}
}