Jump to content

tjk918

Members
  • Posts

    0
  • Joined

  • Last visited

Everything posted by tjk918

  1. Im trying to get my gui to show up when a certain keybinding is pressed, however, i cant find out what method i need to do this. Ive been looking into this for a while, i cant find a 1.15 version of the player.getGui method. This is my code so far: public class KeyInputHandler { private static ClientPlayerEntity player = Minecraft.getInstance().player; @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { if (Bindings.openBackpack.isPressed()) { if(player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == ModItemList.backpack) { player.sendChatMessage("test"); player.openContainer((INamedContainerProvider) new ContainerBackpack(0, player.inventory)); } } } } Someone please point me in the right direction! the test message shows up by itself; but when the player.openContainer method is called, the game crashes. here are my other classes for the container and the screen. im pretty sure theyre also contributing to the problem (theyre not finished either). im pretty new to modding so im not quite sure how a lot of these specific classes and stuff work public class ContainerBackpack extends Container implements INamedContainerProvider/*idk if i need thiss*/{ private IItemHandler inv; public ContainerBackpack(int id, PlayerInventory inventory) { super(ModItemList.BACKPACK_CONTAINER, id); inv = new InvWrapper(inventory); layoutPlayerInvSlots(7, 47); } @Override public boolean canInteractWith(PlayerEntity playerIn) { return true; } public void addSlot(IItemHandler handler, int index, int x, int y) { } private int addSlotRange(IItemHandler handler, int index, int x, int y, int amount, int dx) { for (int i = 0; i < amount; i++) { addSlot(new SlotItemHandler(handler, index, x, y)); x += dx; index++; } return index; } private int addSlotBox(IItemHandler handler, int index, int x, int y, int hamount, int dx, int vamount, int dy) { for (int i = 0; i < vamount; i++) { index = addSlotRange(handler, index, x, y, hamount, dx); y += dy; } return index; } private void layoutPlayerInvSlots(int leftCol, int topRow) { addSlotBox(inv, 9, leftCol, topRow, 9, 18, 3, 18); addSlotRange(inv, 0, leftCol, topRow + 58, 9, 18); } @Override public Container createMenu(int arg0, PlayerInventory arg1, PlayerEntity arg2) { // TODO Auto-generated method stub return null; } @Override public ITextComponent getDisplayName() { // TODO Auto-generated method stub return null; } } public class GuiBackpack extends ContainerScreen<ContainerBackpack>{ private ResourceLocation GUI = new ResourceLocation(TjkBackpackMod.MODID, "textures/gui/backpack.png"); public GuiBackpack(ContainerBackpack screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); // TODO Auto-generated constructor stub } @Override public void render(int mouseX, int mouseY, float partialTicks) { this.renderBackground(); super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { this.font.drawString(this.title.getFormattedText(), 8.0f, 6.0f, 4210752); this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0f, (float)(this.ySize - 96 + 2), 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { RenderSystem.color4f(1.0f, 1.0f, 1.0f, 1.0f); this.minecraft.getTextureManager().bindTexture(GUI); int relX = (this.width - this.xSize) / 2; int relY = (this.height - this.ySize) / 2; this.blit(relX, relY, 0, 0, this.xSize, this.ySize); } } any help is appreciated. this is my first proper mod, so if anything looks wrong please point it out
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.