Jump to content

[Need really help] Change displayed GUI


JimiIT92

Recommended Posts

Ops, sorry, mu bad :( Anyway i got this right now (the only thing changed in this class is the check (if on client side)), all the rest was the same then before. The proxy variable used before was a common proxy instance, then all the gui related stuff was done in the client proxy (as you can see). Should i do this in the Common proxy instead?

public class BL
{
@SidedProxy(clientSide = "blaze.proxy.ClientProxy", serverSide = "blaze.proxy.CommonProxy")
public static CommonProxy proxy;
@Instance("blaze")
public static BL instance;
public static final String MODID = "blaze";
public static final String VERSION = "1.0";
public static SimpleNetworkWrapper network;

@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	network = NetworkRegistry.INSTANCE.newSimpleChannel("BL_Channel");
	network.registerMessage(NetworkMessage.Handler.class, NetworkMessage.class, 0, Side.SERVER);
}

@EventHandler
public void init(FMLInitializationEvent event)
{
	proxy.registerRenderThings();
}
}

 

CommonProxy class

public class CommonProxy{
public void registerRenderThings(RenderItem renderItem){

}
public int addArmor(String armorName)
{
	return 0;
}
}

 

ClientProxy class

public class ClientProxy extends CommonProxy {

	public void registerRenderThings(){

		BL.network.sendToServer(new NetworkMessage("craftingTable"));

		MinecraftForge.EVENT_BUS.register(new EventReceiver());
	}

	public int addArmor(String armorname) {
		return 0;
	}
}

 

EventReceiver class

public class EventReceiver
{
@SubscribeEvent
public void onEvent(GuiOpenEvent event)
{
	if(event.gui instanceof GuiCrafting)
	{	
		event.gui = new GUINewWorkbench(Minecraft.getMinecraft().thePlayer.inventory, Minecraft.getMinecraft().theWorld);
	}

}
}

 

As i said before, should i do some operations in the CommonProxy instead of ClientProxy?

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Are you still getting array out of bounds? Did you identify the array list that was violated? Did you find out why something used index 46 on a 46-element array? Maybe this array needs to get bigger when you add slots to the GUI.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

I was trying to figure out what happens when i click on one of the additional 4 slots, and this reminds to this discussion

http://www.minecraftforge.net/forum/index.php/topic,34172.0.html

The array list that goes out of bounds is the inventory slots

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

The error is occuring because he is only opening the gui client side.

The error is happening because he's poking one element beyond the end of his array. He knows what array it is, so he should be able to fix his code. Either extend the array or stop poking there (maybe he should poke a different array?). His course will depend on the purpose of the array, which he must analyze from its usage within vanilla code.

 

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

Done a quick test :) Overriding this function

    @Override
    public ItemStack slotClick(int slotId, int clickedButton, int mode, EntityPlayer playerIn)
    {
    	System.out.println(this.inventorySlots.size());
    	return super.slotClick(slotId, clickedButton, mode, playerIn);
    }

to see its behavior when i click it returns 50 as inventorySlots size (wich is correct) and then going into the vanilla method it takes the player inventory (wich printing out it's size returns 40). So i think i should "extend" the player inventory?

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

Your crash message definitely said that a 46 element array list had been violated. I think that's 36 slots of player inventory plus 9 slots of crafting area plus the one output slot. You should see how the vanilla code manages to combine those three things and then make it also combine the four armor slots.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

Link to comment
Share on other sites

This three things are handled by the container constructor, using the addSlotToContainer method. Infact in the constructor i have this

this.addSlotToContainer(new SlotCrafting(playerInventory.player, this.craftMatrix, this.craftResult, 0, 124, 35));
//ADDED THE CRAFTING RESULT SLOT (SLOT #0)
...
/**
* SLOT 0-8
* CRAFTING MATRIX
*/
        for (i = 0; i < 3; ++i)
        {
            for (j = 0; j < 3; ++j)
            {
                this.addSlotToContainer(new Slot(this.craftMatrix, j + i * 3, 30 + j * 18, 17 + i * 18));
            }
        }

        /**
         * SLOT 9-35
         * PLAYER INVENTORY
         */
        for (i = 0; i < 3; ++i)
        {
            for (j = 0; j < 9; ++j)
            {
                this.addSlotToContainer(new Slot(playerInventory, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
            }
        }

        /**
         * SLOT 36-44
         * HOTBAR
         */
        for (i = 0; i < 9; ++i)
        {
            this.addSlotToContainer(new Slot(playerInventory, i, 8 + i * 18, 142));
        }

        /**
         * 45-48
         * EXTRA ARMOR SLOTS
         */
        for(i = 0; i < 4; i++)
        {
        	final int k = i;
        	this.addSlotToContainer(new Slot(playerInventory, playerInventory.getSizeInventory() - 1 - i, 8 + 9 * 18, 64)
            {
                /**
                 * Returns the maximum stack size for a given slot (usually the same as getInventoryStackLimit(), but 1
                 * in the case of armor slots)
                 */
                public int getSlotStackLimit()
                {
                    return 1;
                }
                /**
                 * Check if the stack is a valid item for this slot. Always true beside for the armor slots.
                 */
                public boolean isItemValid(ItemStack stack)
                {
                    if (stack == null) return false;
                    return stack.getItem().isValidArmor(stack, k, playerInventory.player);
                }
                @SideOnly(Side.CLIENT)
                public String getSlotTexture()
                {
                    return ItemArmor.EMPTY_SLOT_NAMES[k];
                }
            });
        }

And if i print the whole inventory dimension for the container it returns 50 as expected :/ Also i've done another test. I've changed the position of the 4 slots under the crafting result slot (because the click mode taken when i click on that slot before was 4 (drop)), doing this stil gets the array out of bound but at least i can take and put items in that slots (but they drop from there when i close the GUI and also duplicates the original item)

Don't blame me if i always ask for your help. I just want to learn to be better :)

Link to comment
Share on other sites

I've uploaded all the mod code to a Github, so who want to help me can works better :) Here is the link

https://github.com/JimiIT92/NewGUI

Also with the actual code the behavior of the GUI itself is changed, here's what it does right now

https://www.youtube.com/watch?v=9Y0rU3I4rpE

 

I really really really need help with this :(

Don't blame me if i always ask for your help. I just want to learn to be better :)

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.