Get the menu working, button click broken
This commit is contained in:
parent
848b6f495b
commit
01a6f1ddc7
8 changed files with 86 additions and 24 deletions
|
@ -86,6 +86,8 @@ public class LibZontreck {
|
|||
|
||||
Bus.Reset();
|
||||
|
||||
ModMenuTypes.REGISTRY.register(bus);
|
||||
|
||||
Bus.Register(CurrencyHelper.class, null);
|
||||
Bus.Register(Bank.class, null);
|
||||
}
|
||||
|
|
|
@ -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<ChestGUIButton> buttons = new ArrayList<>();
|
||||
public List<ChestGUIButton> 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")));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,9 @@ public class ChestGUIScreen extends AbstractContainerScreen<ChestGUIMenu> {
|
|||
|
||||
this.imageWidth = 191;
|
||||
this.imageHeight = 82;
|
||||
|
||||
this.titleLabelX = 32;
|
||||
this.titleLabelY =5;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,6 +61,6 @@ public class ChestGUIScreen extends AbstractContainerScreen<ChestGUIMenu> {
|
|||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Reference in a new issue