Initial implementation of chest gui
This commit is contained in:
parent
a8048391a0
commit
409f6d407b
6 changed files with 130 additions and 4 deletions
|
@ -13,7 +13,10 @@ import dev.zontreck.eventsbus.Bus;
|
|||
import dev.zontreck.libzontreck.chestgui.ChestGUIRegistry;
|
||||
import dev.zontreck.libzontreck.currency.Bank;
|
||||
import dev.zontreck.libzontreck.currency.CurrencyHelper;
|
||||
import dev.zontreck.libzontreck.menus.ChestGUIScreen;
|
||||
import dev.zontreck.libzontreck.types.ModMenuTypes;
|
||||
import dev.zontreck.libzontreck.networking.NetworkEvents;
|
||||
import net.minecraft.client.gui.screens.MenuScreens;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
|
@ -127,7 +130,7 @@ public class LibZontreck {
|
|||
LibZontreck.ALIVE = false; // Prevents loops on the client that are meant for server tick processing
|
||||
|
||||
|
||||
//MenuScreens.register(ModMenuTypes.CHESTGUI.get(), ChestGuiScreen::new);
|
||||
MenuScreens.register(ModMenuTypes.CHEST_GUI_MENU.get(), ChestGUIScreen::new);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package dev.zontreck.libzontreck.menus;
|
||||
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUI;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUIButton;
|
||||
import dev.zontreck.libzontreck.types.ModMenuTypes;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuConstructor;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ChestGUIMenu extends AbstractContainerMenu
|
||||
{
|
||||
private ChestGUI gui;
|
||||
|
||||
public ChestGUIMenu(int id, Inventory playerInv, FriendlyByteBuf buf)
|
||||
{
|
||||
this(id, playerInv, new ItemStackHandler(3*9), BlockPos.ZERO, playerInv.player, null);
|
||||
}
|
||||
|
||||
public ChestGUIMenu(int id, Inventory playerInv, ItemStackHandler inv, BlockPos position, Player player, ChestGUI gui)
|
||||
{
|
||||
super(ModMenuTypes.CHEST_GUI_MENU.get(), id);
|
||||
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack quickMoveStack(Player player, int i) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stillValid(Player player) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static MenuConstructor getServerMenu(ItemStackHandler inventory)
|
||||
{
|
||||
return (id, playerInv, player) -> new ChestGUIMenu(id, playerInv, inventory, BlockPos.ZERO, player, null);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package dev.zontreck.libzontreck.menus;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.chestgui.ChestGUI;
|
||||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
|
||||
public class ChestGUIScreen extends AbstractContainerScreen<ChestGUIMenu> {
|
||||
public final Player player;
|
||||
public final ChestGUIMenu menu;
|
||||
private static final ResourceLocation TEXTURE = new ResourceLocation(LibZontreck.MOD_ID, "textures/gui/chest_gui.png");
|
||||
|
||||
|
||||
public ChestGUIScreen(ChestGUIMenu menu, Inventory playerInv, Component comp)
|
||||
{
|
||||
super(menu, playerInv, comp);
|
||||
|
||||
this.menu = menu;
|
||||
this.player = playerInv.player;
|
||||
|
||||
this.leftPos = 0;
|
||||
this.topPos=0;
|
||||
|
||||
this.imageWidth = 191;
|
||||
this.imageHeight = 82;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||
this.renderBackground(pGuiGraphics);
|
||||
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
|
||||
this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void init() {
|
||||
super.init();
|
||||
|
||||
this.inventoryLabelX = 32;
|
||||
this.inventoryLabelY = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderBg(GuiGraphics guiGraphics, float v, int i, int i1) {
|
||||
renderBackground(guiGraphics);
|
||||
RenderSystem.setShader(GameRenderer::getPositionTexShader);
|
||||
RenderSystem.setShaderColor(1,1,1,1);
|
||||
RenderSystem.setShaderTexture(0, TEXTURE);
|
||||
|
||||
guiGraphics.blit(TEXTURE, this.leftPos, this.topPos, 0, 0, imageWidth, imageHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void renderLabels(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY) {
|
||||
pGuiGraphics.drawString(font, title.getString(), 32, 5, 0x000000);
|
||||
}
|
||||
}
|
|
@ -1,16 +1,29 @@
|
|||
package dev.zontreck.libzontreck.types;
|
||||
|
||||
import dev.zontreck.libzontreck.LibZontreck;
|
||||
import dev.zontreck.libzontreck.menus.ChestGUIMenu;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.inventory.MenuType;
|
||||
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||
import net.minecraftforge.eventbus.api.IEventBus;
|
||||
import net.minecraftforge.network.IContainerFactory;
|
||||
import net.minecraftforge.registries.DeferredRegister;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
import net.minecraftforge.registries.RegistryObject;
|
||||
|
||||
public class ModMenuTypes {
|
||||
public static DeferredRegister<MenuType<?>> REGISTER = DeferredRegister.create(ForgeRegistries.MENU_TYPES, LibZontreck.MOD_ID);
|
||||
public class ModMenuTypes
|
||||
{
|
||||
public static DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.MENU_TYPES, LibZontreck.MOD_ID);
|
||||
|
||||
public static RegistryObject<MenuType<ChestGUIMenu>> CHEST_GUI_MENU = registerMenuType(ChestGUIMenu::new, "chestgui");
|
||||
|
||||
private static <T extends AbstractContainerMenu> RegistryObject<MenuType<T>> registerMenuType(IContainerFactory<T> factory, String name)
|
||||
{
|
||||
return REGISTRY.register(name, ()-> IForgeMenuType.create(factory));
|
||||
}
|
||||
|
||||
public static void register(IEventBus bus)
|
||||
{
|
||||
REGISTER.register(bus);
|
||||
REGISTRY.register(bus);
|
||||
}
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 62 KiB |
Binary file not shown.
Reference in a new issue