Posted May 4, 20223 yr I just finish getting my screen to load, and I am trying to have the code render buttons and the like (don't worry about the slots, I was just testing how they work). However, when the button is pressed, literally nothing happens. It is supposed to create a button for every item in the players inventory that has the tag "custombows.acceptable_heads". Here is the repo: https://github.com/bltstudios/custom_bows
May 4, 20223 yr Author 29 minutes ago, diesieben07 said: Where exactly do you think you are adding buttons to the screen as a result of pressing anothe rbutton? If you are asking about on screen: Next to the first button, which I believe shows up in the corner. If you are asking about in code: @Override protected void init() { super.init(); this.headButton = addRenderableWidget( new ImageButton(ArrowWorkstationBaseMenu.TE_HEAD_SLOT_X, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_Y, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_HEIGHT, 0, 0, 0, HEAD_BUTTON_TEX, btn -> { showHeads = true; showBinding = false; showShaft = false; showFeather = false; showInv = false; })); if(showHeads) { int x = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_X + ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH; int y = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_Y; int width = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH; int height = ArrowWorkstationBaseMenu.TE_HEAD_SLOT_HEIGHT; for (ItemStack a: getAllOfType(ACCEPTABLE_HEAD_TAGS, pInv)) { renderImageButton(x, y, width, height, 0,0,0, HEAD_BUTTON_TEX, a, 0); x += width; } } this.shaftButton = addRenderableWidget( new ImageButton(ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_X, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_Y, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_WIDTH, ArrowWorkstationBaseMenu.TE_HEAD_SLOT_HEIGHT, 0,0,0, SHAFT_BUTTON_TEX, btn -> { showShaft = true; showHeads = false; showBinding = false; showFeather = false; showInv = false; })); if(showShaft) { int x = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_X + ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_WIDTH; int y = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_Y; int width = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_WIDTH; int height = ArrowWorkstationBaseMenu.TE_SHAFT_SLOT_HEIGHT; for (ItemStack a: getAllOfType(ACCEPTABLE_SHAFT_TAGS, pInv)) { renderImageButton(x, y, width, height, 0,0,0, SHAFT_BUTTON_TEX, a, 1); x += width; } } } protected ImageButton renderImageButton(int x, int y, int width, int height, int startX, int startY, int textStartY, ResourceLocation resLoc, ItemStack itemSelection, int ind) { return addRenderableWidget(new ImageButton(x, y, width, height, startX, startY, textStartY, resLoc, btn -> { menu.blockEntity.itemHandler.setStackInSlot(ind, itemSelection); })); } protected NonNullList<ItemStack> getAllOfType(TagKey<Item> tagKey, Inventory pInv) { NonNullList<ItemStack> items = null; for (ItemStack a: pInv.items) { if(a.is(tagKey)) { items.add(a); } } return items; } In the ArrowWorkstationBaseScreen class
May 4, 20223 yr Author 1 minute ago, diesieben07 said: init runs when your screen is first opened, at which point all the fields are false and no buttons are added. init never runs again, so no buttons are ever added. So where can I run this code?
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.