Jump to content

Crafting Display


drok0920

Recommended Posts

I am currently using this:

 

list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone_slab, 1));
            list.add(new ItemStack(Blocks.stone, 1));

  And

 

int offsetx = 0;
    	int offsety = 0;
    	int count = 0;
        for (ItemStack stack : list) {
        	if(count <= 9) {
                itemRender.renderItemIntoGUI(fontRendererObj, this.mc.getTextureManager(), stack, x + offsetx, y + offsety);
                offsetx = offsetx + 26;
                count++;
                System.out.println(count);
                
                if(count == 3) {
                	offsetx = 0;
                	offsety = offsety + 26;
                }
                
                if(count == 6) {
                	offsetx = 0;
                	offsety = offsety + 26;
                }
        	}
        }

 

But setting any of the Blocks.stone to blocks.air crashes it.

Link to comment
Share on other sites

Sorry that was only a snip it of code heres all of it:

 

package com.drok0920.alchemy.gui;

import java.util.LinkedList;
import java.util.List;







import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiLabel;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.util.ResourceLocation;







import org.lwjgl.opengl.GL11;

import com.drok0920.alchemy.Alchemy;
import com.drok0920.alchemy.block.BlockManager;
import com.drok0920.alchemy.item.ItemManager;

public class GUIAlchemistsGuide extends GuiScreen {

        public static final int GUI_ID = 20;
        
        private static int PAGE_ID = 0;

        private static final int CLOSE_BUTTON_ID = 0;
        private static final int NEXT_BUTTON_ID = 1;
        private static final int PREVIOUS_BUTTON_ID = 2;
       
        private ResourceLocation backgroundTexture;
        
        private List<ItemStack> list = new LinkedList();
       
        public GUIAlchemistsGuide() {  
                backgroundTexture = new ResourceLocation(Alchemy.MODID,"textures/gui/alchemistsGuide_Crafting.png");
        }
       
        @Override
        public void initGui() {
                super.initGui();
                PAGE_ID = 0;
                GuiButton closeButton = new GuiButton(CLOSE_BUTTON_ID, (width / 2) - 25, 256 - 27, 50, 20, "Close");
                buttonList.add(closeButton);
                
                GuiButton nextButton = new GuiButton(NEXT_BUTTON_ID, (width / 2) + 50, 256 - 27, 50, 20, "Next");
                buttonList.add(nextButton);
                
                GuiButton previousButton = new GuiButton(PREVIOUS_BUTTON_ID, (width / 2) - 100, 256 - 27, 50, 20, "Previous");
                buttonList.add(previousButton);
        }
       
    @Override
    public boolean doesGuiPauseGame() {
        return false;
    }
   
    @Override
    protected void actionPerformed(GuiButton button) {
    	if(button.id == CLOSE_BUTTON_ID) {
            this.mc.displayGuiScreen((GuiScreen)null);
            return;
    	} else if(button.id == NEXT_BUTTON_ID) {
    		if (PAGE_ID != 10) {
    			this.PAGE_ID++;
    			System.out.println(PAGE_ID);
    		}
          	return;
    	} else if(button.id == PREVIOUS_BUTTON_ID) {
    		if (PAGE_ID != 0) {
    			this.PAGE_ID--;
    		}
          	return;
    	}
    	
    }
   
    /**
     * Draws the screen and all the components in it.
     */
    public void drawScreen(int p_73863_1_, int p_73863_2_, float p_73863_3_)
    {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(backgroundTexture);
        this.drawTexturedModalRect( (this.width - 256) / 2, 0, 0, 0, 256, 256);
        if(PAGE_ID == 0) {
        	
        } 
        if(PAGE_ID == 1) {
        	list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone, 1));
            
            list.add(new ItemStack(Blocks.stone, 1));
            list.add(new ItemStack(Blocks.stone_slab, 1));
            list.add(new ItemStack(Blocks.stone, 1));
        }
        for (int k = 0; k < this.buttonList.size(); ++k)
        {
                ((GuiButton)this.buttonList.get(k)).drawButton(this.mc, p_73863_1_, p_73863_2_);
        }

        for (int k = 0; k < this.labelList.size(); ++k)
        {
            ((GuiLabel)this.labelList.get(k)).func_146159_a(this.mc, p_73863_1_, p_73863_2_);
        }
        drawShapelessCrafting((this.width - 69) / 2, 174 - 26, list);
        list.clear();
    }

    protected void drawShapelessCrafting(int x, int y, List<ItemStack> stacks) {
       
    	int offsetx = 0;
    	int offsety = 0;
    	int count = 0;
        for (ItemStack stack : list) {
        	if(count <= 9) {
                itemRender.renderItemIntoGUI(fontRendererObj, this.mc.getTextureManager(), stack, x + offsetx, y + offsety);
                offsetx = offsetx + 26;
                count++;
                System.out.println(count);
                
                if(count == 3) {
                	offsetx = 0;
                	offsety = offsety + 26;
                }
                
                if(count == 6) {
                	offsetx = 0;
                	offsety = offsety + 26;
                }
        	}
        }
    }
       
}

 

And in the end looks like this: http://s1308.photobucket.com/user/Taco_Does_MC/media/Capture_zpsf13fef6b.jpg.html

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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