Update ChestGUI to new LibZontreck API

This commit is contained in:
zontreck 2024-01-15 00:56:27 -07:00
parent dbd34125f8
commit 68aac66094
2 changed files with 35 additions and 32 deletions

View file

@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false org.gradle.daemon=false
libzontreck=1.10.011024.0312 libzontreck=1.10.011524.0045
## Environment Properties ## 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. # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=GPLv3 mod_license=GPLv3
# The mod version. See https://semver.org/ # The mod version. See https://semver.org/
mod_version=1.2.011024.0346 mod_version=1.2.011524.0055
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # 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. # This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html # See https://maven.apache.org/guides/mini/guide-naming-conventions.html

View file

@ -5,6 +5,7 @@ import dev.zontreck.libzontreck.chestgui.ChestGUI;
import dev.zontreck.libzontreck.chestgui.ChestGUIButton; import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier; import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
import dev.zontreck.libzontreck.items.ModItems; import dev.zontreck.libzontreck.items.ModItems;
import dev.zontreck.libzontreck.lore.LoreContainer;
import dev.zontreck.libzontreck.lore.LoreEntry; import dev.zontreck.libzontreck.lore.LoreEntry;
import dev.zontreck.libzontreck.util.ServerUtilities; import dev.zontreck.libzontreck.util.ServerUtilities;
import dev.zontreck.libzontreck.vectors.Vector2i; import dev.zontreck.libzontreck.vectors.Vector2i;
@ -17,7 +18,6 @@ import dev.zontreck.wmd.networking.packets.s2c.S2CResetConfig;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component; import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items; import net.minecraft.world.item.Items;
@ -26,31 +26,26 @@ import net.minecraftforge.network.NetworkEvent;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
public class ClientConfigResponse public class ClientConfigResponse {
{
public CompoundTag tag; public CompoundTag tag;
public UUID id; public UUID id;
public ClientConfigResponse(FriendlyByteBuf buf) public ClientConfigResponse(FriendlyByteBuf buf) {
{
tag = buf.readAnySizeNbt(); tag = buf.readAnySizeNbt();
id = buf.readUUID(); id = buf.readUUID();
} }
public ClientConfigResponse(UUID playerID) public ClientConfigResponse(UUID playerID) {
{
tag = WMDClientConfig.serialize(); tag = WMDClientConfig.serialize();
id = playerID; id = playerID;
} }
public void toBytes(FriendlyByteBuf buf) public void toBytes(FriendlyByteBuf buf) {
{
buf.writeNbt(tag); buf.writeNbt(tag);
buf.writeUUID(id); buf.writeUUID(id);
} }
public void handle(Supplier<NetworkEvent.Context> supplier) public void handle(Supplier<NetworkEvent.Context> supplier) {
{
NetworkEvent.Context ctx = supplier.get(); NetworkEvent.Context ctx = supplier.get();
ctx.enqueueWork(() -> { ctx.enqueueWork(() -> {
@ -59,6 +54,7 @@ public class ClientConfigResponse
boolean enableHunger = tag.getBoolean("watchMyHunger"); boolean enableHunger = tag.getBoolean("watchMyHunger");
boolean enableDurability = tag.getBoolean("watchDurability"); boolean enableDurability = tag.getBoolean("watchDurability");
ServerPlayer player = ServerUtilities.getPlayerByID(id.toString()); ServerPlayer player = ServerUtilities.getPlayerByID(id.toString());
try { try {
@ -66,14 +62,17 @@ public class ClientConfigResponse
ItemStack wtd = new ItemStack(Items.DIAMOND_PICKAXE, 1); ItemStack wtd = new ItemStack(Items.DIAMOND_PICKAXE, 1);
wtd.setHoverName(Component.literal("Watch Tool Durability")); wtd.setHoverName(Component.literal("Watch Tool Durability"));
prompt.withButton(new ChestGUIButton(wtd, ()-> { prompt.withButton(new ChestGUIButton(wtd, (stack, container, lore) -> {
tag.putBoolean("watchDurability", !enableDurability); var wd = !tag.getBoolean("watchDurability");
tag.putBoolean("watchDurability", wd);
ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player); ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player);
prompt.close();
ModMessages.sendToPlayer(new RequestClientConfig(), player); lore.miscData.loreData.get(0).text = ChatColor.doColors("!Dark_Green!Status: " + (wd ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"));
lore.commitLore();
}, new Vector2i(0, 0)) }, new Vector2i(0, 0))
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableDurability ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build()) .withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableDurability ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build())
@ -82,30 +81,35 @@ public class ClientConfigResponse
ItemStack wmhunger = new ItemStack(Items.APPLE, 1); ItemStack wmhunger = new ItemStack(Items.APPLE, 1);
wmhunger.setHoverName(Component.literal("Watch My Hunger")); wmhunger.setHoverName(Component.literal("Watch My Hunger"));
prompt.withButton(new ChestGUIButton(wmhunger, ()->{ prompt.withButton(new ChestGUIButton(wmhunger, (stack, container, lore) -> {
tag.putBoolean("watchMyHunger", !enableHunger); var eh = !tag.getBoolean("watchMyHunger");
tag.putBoolean("watchMyHunger", eh);
ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player); ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player);
prompt.close(); lore.miscData.loreData.get(0).text = ChatColor.doColors("!Dark_Green!Status: " + (eh ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"));
ModMessages.sendToPlayer(new RequestClientConfig(), player); lore.commitLore();
}, new Vector2i(0, 1)) }, new Vector2i(0, 1))
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableHunger ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build()) .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); ItemStack wmhealth = new ItemStack(Items.PUFFERFISH, 1);
wmhealth.setHoverName(Component.literal("Watch My Health")); wmhealth.setHoverName(Component.literal("Watch My Health"));
prompt.withButton(new ChestGUIButton(wmhealth, ()->{ prompt.withButton(new ChestGUIButton(wmhealth, (stack, container, lore) -> {
tag.putBoolean("watchMyHealth", !enableHealth); var eh = !tag.getBoolean("watchMyHealth");
tag.putBoolean("watchMyHealth", eh);
ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player); ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player);
prompt.close();
ModMessages.sendToPlayer(new RequestClientConfig(), player); lore.miscData.loreData.get(0).text = ChatColor.doColors("!Dark_Green!Status: " + (eh ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"));
lore.commitLore();
}, new Vector2i(0, 2)) }, new Vector2i(0, 2))
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableHealth ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build()) .withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableHealth ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build())
); );
prompt.withButton(new ChestGUIButton(ModItems.CHESTGUI_RESET.get(), "Reset", ()->{ prompt.withButton(new ChestGUIButton(ModItems.CHESTGUI_RESET.get(), "Reset", (stack, container, lore) -> {
ModMessages.sendToPlayer(new S2CResetConfig(), ServerUtilities.getPlayerByID(id.toString())); ModMessages.sendToPlayer(new S2CResetConfig(), ServerUtilities.getPlayerByID(id.toString()));
prompt.close(); prompt.close();
@ -116,8 +120,7 @@ public class ClientConfigResponse
prompt.hasReset = false; prompt.hasReset = false;
prompt.open(); prompt.open();
}catch(Exception e) } catch (Exception e) {
{
WatchMyDurability.LOGGER.error(e.getMessage()); WatchMyDurability.LOGGER.error(e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }