Update ChestGUI to new LibZontreck API
This commit is contained in:
parent
dbd34125f8
commit
68aac66094
2 changed files with 35 additions and 32 deletions
|
@ -3,7 +3,7 @@
|
|||
org.gradle.jvmargs=-Xmx3G
|
||||
org.gradle.daemon=false
|
||||
|
||||
libzontreck=1.10.011024.0312
|
||||
libzontreck=1.10.011524.0045
|
||||
|
||||
## 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.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.
|
||||
# This should match the base package used for the mod sources.
|
||||
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
|
||||
|
|
|
@ -5,6 +5,7 @@ import dev.zontreck.libzontreck.chestgui.ChestGUI;
|
|||
import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUIIdentifier;
|
||||
import dev.zontreck.libzontreck.items.ModItems;
|
||||
import dev.zontreck.libzontreck.lore.LoreContainer;
|
||||
import dev.zontreck.libzontreck.lore.LoreEntry;
|
||||
import dev.zontreck.libzontreck.util.ServerUtilities;
|
||||
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.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;
|
||||
|
@ -26,39 +26,35 @@ import net.minecraftforge.network.NetworkEvent;
|
|||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class ClientConfigResponse
|
||||
{
|
||||
public class ClientConfigResponse {
|
||||
public CompoundTag tag;
|
||||
public UUID id;
|
||||
|
||||
public ClientConfigResponse(FriendlyByteBuf buf)
|
||||
{
|
||||
public ClientConfigResponse(FriendlyByteBuf buf) {
|
||||
tag = buf.readAnySizeNbt();
|
||||
id = buf.readUUID();
|
||||
}
|
||||
|
||||
public ClientConfigResponse(UUID playerID)
|
||||
{
|
||||
public ClientConfigResponse(UUID playerID) {
|
||||
tag = WMDClientConfig.serialize();
|
||||
id = playerID;
|
||||
}
|
||||
|
||||
public void toBytes(FriendlyByteBuf buf)
|
||||
{
|
||||
public void toBytes(FriendlyByteBuf buf) {
|
||||
buf.writeNbt(tag);
|
||||
buf.writeUUID(id);
|
||||
}
|
||||
|
||||
public void handle(Supplier<NetworkEvent.Context> supplier)
|
||||
{
|
||||
public void handle(Supplier<NetworkEvent.Context> supplier) {
|
||||
NetworkEvent.Context ctx = supplier.get();
|
||||
|
||||
ctx.enqueueWork(()->{
|
||||
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 {
|
||||
|
@ -66,15 +62,18 @@ public class ClientConfigResponse
|
|||
ItemStack wtd = new ItemStack(Items.DIAMOND_PICKAXE, 1);
|
||||
wtd.setHoverName(Component.literal("Watch Tool Durability"));
|
||||
|
||||
prompt.withButton(new ChestGUIButton(wtd, ()-> {
|
||||
tag.putBoolean("watchDurability", !enableDurability);
|
||||
prompt.withButton(new ChestGUIButton(wtd, (stack, container, lore) -> {
|
||||
var wd = !tag.getBoolean("watchDurability");
|
||||
tag.putBoolean("watchDurability", wd);
|
||||
|
||||
ModMessages.sendToPlayer(new PushClientConfigUpdate(tag), player);
|
||||
|
||||
prompt.close();
|
||||
|
||||
ModMessages.sendToPlayer(new RequestClientConfig(), player);
|
||||
}, new Vector2i(0,0))
|
||||
lore.miscData.loreData.get(0).text = ChatColor.doColors("!Dark_Green!Status: " + (wd ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"));
|
||||
lore.commitLore();
|
||||
|
||||
|
||||
}, new Vector2i(0, 0))
|
||||
.withInfo(new LoreEntry.Builder().text(ChatColor.doColors("!Dark_Green!Status: " + (enableDurability ? "!Dark_Green!Enabled" : "!Dark_Red!Disabled"))).build())
|
||||
|
||||
);
|
||||
|
@ -82,42 +81,46 @@ public class ClientConfigResponse
|
|||
ItemStack wmhunger = new ItemStack(Items.APPLE, 1);
|
||||
wmhunger.setHoverName(Component.literal("Watch My Hunger"));
|
||||
|
||||
prompt.withButton(new ChestGUIButton(wmhunger, ()->{
|
||||
tag.putBoolean("watchMyHunger", !enableHunger);
|
||||
prompt.withButton(new ChestGUIButton(wmhunger, (stack, container, lore) -> {
|
||||
var eh = !tag.getBoolean("watchMyHunger");
|
||||
tag.putBoolean("watchMyHunger", eh);
|
||||
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, 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);
|
||||
prompt.withButton(new ChestGUIButton(wmhealth, (stack, container, lore) -> {
|
||||
var eh = !tag.getBoolean("watchMyHealth");
|
||||
tag.putBoolean("watchMyHealth", eh);
|
||||
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))
|
||||
.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()));
|
||||
|
||||
prompt.close();
|
||||
|
||||
ModMessages.sendToPlayer(new RequestClientConfig(), player);
|
||||
|
||||
}, new Vector2i(2,4)));
|
||||
}, new Vector2i(2, 4)));
|
||||
|
||||
prompt.hasReset=false;
|
||||
prompt.hasReset = false;
|
||||
prompt.open();
|
||||
}catch(Exception e)
|
||||
{
|
||||
} catch (Exception e) {
|
||||
WatchMyDurability.LOGGER.error(e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
Reference in a new issue