diff --git a/src/main/java/dev/zontreck/libzontreck/LibZontreck.java b/src/main/java/dev/zontreck/libzontreck/LibZontreck.java index 56b732d..6c69dff 100644 --- a/src/main/java/dev/zontreck/libzontreck/LibZontreck.java +++ b/src/main/java/dev/zontreck/libzontreck/LibZontreck.java @@ -86,6 +86,8 @@ public class LibZontreck { Bus.Reset(); + ModMenuTypes.REGISTRY.register(bus); + Bus.Register(CurrencyHelper.class, null); Bus.Register(Bank.class, null); } diff --git a/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java b/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java index 258b955..1a2bb2c 100644 --- a/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java +++ b/src/main/java/dev/zontreck/libzontreck/chestgui/ChestGUI.java @@ -1,17 +1,16 @@ package dev.zontreck.libzontreck.chestgui; import dev.zontreck.libzontreck.LibZontreck; +import dev.zontreck.libzontreck.events.OpenGUIEvent; import dev.zontreck.libzontreck.menus.ChestGUIMenu; -import dev.zontreck.libzontreck.networking.packets.ChestGUIOpenC2S; import dev.zontreck.libzontreck.util.ServerUtilities; import dev.zontreck.libzontreck.vectors.Vector2; import dev.zontreck.libzontreck.vectors.Vector2i; -import net.minecraft.nbt.CompoundTag; -import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.SimpleMenuProvider; import net.minecraft.world.item.Item; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.LogicalSide; import net.minecraftforge.items.ItemStackHandler; import net.minecraftforge.network.NetworkHooks; @@ -23,9 +22,9 @@ import java.util.UUID; public class ChestGUI { private ItemStackHandler container = new ItemStackHandler((9*3)); - private String MenuTitle; + private String MenuTitle = ""; private UUID player; - private List buttons = new ArrayList<>(); + public List buttons = new ArrayList<>(); private ResourceLocation id; public ChestGUI withButton(ChestGUIButton button) { @@ -60,7 +59,8 @@ public class ChestGUI { if(LibZontreck.CURRENT_SIDE == LogicalSide.SERVER) { - NetworkHooks.openScreen(ServerUtilities.getPlayerByID(player.toString()), new SimpleMenuProvider(ChestGUIMenu.getServerMenu(this), Component.literal(MenuTitle))); + MinecraftForge.EVENT_BUS.post(new OpenGUIEvent(id, player)); + NetworkHooks.openScreen(ServerUtilities.getPlayerByID(player.toString()), new SimpleMenuProvider(ChestGUIMenu.getServerMenu(this), Component.literal((MenuTitle != "") ? MenuTitle : "No Title"))); } } diff --git a/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java b/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java index 358be8b..c6d89c5 100644 --- a/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java +++ b/src/main/java/dev/zontreck/libzontreck/commands/CreditsCommand.java @@ -3,6 +3,7 @@ package dev.zontreck.libzontreck.commands; import com.mojang.brigadier.CommandDispatcher; +import dev.zontreck.libzontreck.LibZontreck; import dev.zontreck.libzontreck.chestgui.ChestGUI; import dev.zontreck.libzontreck.chestgui.ChestGUIButton; import dev.zontreck.libzontreck.util.heads.CreditsEntry; @@ -24,18 +25,21 @@ public class CreditsCommand { if(source.getEntity() instanceof Player) { // OK. - ChestGUI gui = ChestGUI.builder().withGUIId(new ResourceLocation("ariasmods", "credits-gui")).withPlayer(source.getEntity().getUUID()); + ChestGUI gui = ChestGUI.builder().withGUIId(new ResourceLocation("ariasmods", "creditsgui")).withPlayer(source.getEntity().getUUID()).withTitle("Aria's Mods - Credits"); - Vector2i pos = new Vector2i(); + int x = 0; + int y = 0; for(CreditsEntry entry : HeadCache.CREDITS) { - gui = gui.withButton(new ChestGUIButton(entry.compile(), ()->{}, pos)); + gui = gui.withButton(new ChestGUIButton(entry.compile(), ()->{}, new Vector2i(x,y))); - pos.y++; - if(pos.y>=9) + LibZontreck.LOGGER.info("Add gui button : " + entry.name); + + y++; + if(y>=9) { - pos.x++; - pos.y=0; + x++; + y=0; } } diff --git a/src/main/java/dev/zontreck/libzontreck/dynamicchest/ChestGUIReadOnlyStackHandler.java b/src/main/java/dev/zontreck/libzontreck/dynamicchest/ChestGUIReadOnlyStackHandler.java new file mode 100644 index 0000000..39ae504 --- /dev/null +++ b/src/main/java/dev/zontreck/libzontreck/dynamicchest/ChestGUIReadOnlyStackHandler.java @@ -0,0 +1,54 @@ +package dev.zontreck.libzontreck.dynamicchest; + +import dev.zontreck.libzontreck.LibZontreck; +import dev.zontreck.libzontreck.chestgui.ChestGUI; +import dev.zontreck.libzontreck.chestgui.ChestGUIButton; +import net.minecraft.world.item.ItemStack; +import net.minecraftforge.items.ItemStackHandler; +import org.jetbrains.annotations.NotNull; + +public class ChestGUIReadOnlyStackHandler extends ItemStackHandler +{ + private ChestGUI gui; + + public ChestGUIReadOnlyStackHandler(ChestGUI gui) + { + super((3*9)); + this.gui = gui; + + LibZontreck.LOGGER.info("Logical Side : " + LibZontreck.CURRENT_SIDE); + + if(gui!=null) + { + if(gui.buttons!=null) + { + LibZontreck.LOGGER.info("Generating chest gui button items"); + for(ChestGUIButton btn : gui.buttons) + { + setStackInSlot(btn.getSlotNum(), btn.buildIcon()); + } + } else LibZontreck.LOGGER.error("Gui Buttons list is null"); + } else LibZontreck.LOGGER.error("Gui is null!"); + } + + @Override + public int getSlots() { + return (3*9); + } + + @Override + public @NotNull ItemStack insertItem(int slot, @NotNull ItemStack stack, boolean simulate) { + return stack; + } + + @Override + public @NotNull ItemStack extractItem(int slot, int amount, boolean simulate) { + ChestGUIButton btn = gui.buttons.stream().filter(x->x.getSlotNum()==slot).findFirst().orElse(null); + + if(btn == null) return ItemStack.EMPTY; + + btn.clicked(); + + return ItemStack.EMPTY; + } +} diff --git a/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIMenu.java b/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIMenu.java index 09e6e93..c7b74dc 100644 --- a/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIMenu.java +++ b/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIMenu.java @@ -2,6 +2,7 @@ package dev.zontreck.libzontreck.menus; import dev.zontreck.libzontreck.chestgui.ChestGUI; import dev.zontreck.libzontreck.chestgui.ChestGUIButton; +import dev.zontreck.libzontreck.dynamicchest.ChestGUIReadOnlyStackHandler; import dev.zontreck.libzontreck.dynamicchest.ReadOnlyItemStackHandler; import dev.zontreck.libzontreck.types.ModMenuTypes; import dev.zontreck.libzontreck.vectors.Vector2i; @@ -20,6 +21,7 @@ import org.jetbrains.annotations.Nullable; public class ChestGUIMenu extends AbstractContainerMenu { public final ChestGUI gui; + public final ItemStackHandler slots; public ChestGUIMenu(int id, Inventory playerInv, FriendlyByteBuf buf) { @@ -32,7 +34,8 @@ public class ChestGUIMenu extends AbstractContainerMenu this.gui = gui; - if(gui == null)return; + slots = new ChestGUIReadOnlyStackHandler(gui); + int slotSize = 18; int startX = 15; @@ -42,12 +45,7 @@ public class ChestGUIMenu extends AbstractContainerMenu { for(int column=0;column<9;column++) { - Vector2i slot = new Vector2i(row, column); - ChestGUIButton btn = gui.getSlot(slot); - if(gui.hasSlot(slot)) - { - addSlot(new SlotItemHandler(new ReadOnlyItemStackHandler(btn.buildIconStack(), btn::clicked), row*9 + column, startX + column * slotSize, startY + row * slotSize)); - } + addSlot(new SlotItemHandler(slots, row*9 + column, startX + column * slotSize, startY + row * slotSize)); } } } diff --git a/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIScreen.java b/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIScreen.java index 4fe50b1..9ae9ee4 100644 --- a/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIScreen.java +++ b/src/main/java/dev/zontreck/libzontreck/menus/ChestGUIScreen.java @@ -29,6 +29,9 @@ public class ChestGUIScreen extends AbstractContainerScreen { this.imageWidth = 191; this.imageHeight = 82; + + this.titleLabelX = 32; + this.titleLabelY =5; } @Override @@ -58,6 +61,6 @@ public class ChestGUIScreen extends AbstractContainerScreen { @Override protected void renderLabels(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY) { - pGuiGraphics.drawString(font, title.getString(), 32, 5, 0x000000); + pGuiGraphics.drawString(this.font, this.title, this.titleLabelX, this.titleLabelY, 4210752, false); } } diff --git a/src/main/java/dev/zontreck/libzontreck/util/heads/CreditsEntry.java b/src/main/java/dev/zontreck/libzontreck/util/heads/CreditsEntry.java index 6a7e46f..e1946a6 100644 --- a/src/main/java/dev/zontreck/libzontreck/util/heads/CreditsEntry.java +++ b/src/main/java/dev/zontreck/libzontreck/util/heads/CreditsEntry.java @@ -29,13 +29,14 @@ public class CreditsEntry { ItemStack stack = player.getAsItem(); stack.setHoverName(Component.literal(name)); LoreContainer contain = new LoreContainer(stack); + contain.miscData.LoreData.clear(); LoreEntry entry = new LoreEntry(); - entry.text = ChatColor.doColors("!Dark_Purple!Role: "+role); + entry.text = ChatColor.doColors("!Dark_Purple!Role: "+role + "\n"); entry.bold=true; entry.italic=true; contain.miscData.LoreData.add(entry); entry = new LoreEntry(); - entry.text = ChatColor.doColors("!White!About: !Dark_Green!"+description); + entry.text = ChatColor.doColors("!White!About: !Dark_Green!"+description + "\n"); entry.italic=true; contain.miscData.LoreData.add(entry); diff --git a/src/main/java/dev/zontreck/libzontreck/util/heads/HeadCache.java b/src/main/java/dev/zontreck/libzontreck/util/heads/HeadCache.java index 6dc7702..7aaabdf 100644 --- a/src/main/java/dev/zontreck/libzontreck/util/heads/HeadCache.java +++ b/src/main/java/dev/zontreck/libzontreck/util/heads/HeadCache.java @@ -106,7 +106,7 @@ public class HeadCache creds.add( new CreditsEntry(HeadUtilities.cachedLookup("PossumTheWarrior"), "PossumTheWarrior", "Tester", "Poss has helped to test the mods from very early on")); creds.add( - new CreditsEntry(HeadUtilities.cachedLookup("GemMD"), "GemMD", "Adviser", "GemMD has provided advise on marketing and development decisions for various mods")); + new CreditsEntry(HeadUtilities.cachedLookup("GemMD"), "GemMD", "Adviser", "GemMD has provided advice on marketing and development decisions for various mods")); CREDITS = creds;