MC Modding
Please register and join the community!

[1.8.1]Adding your block to the creative GUI with no base files edited.

View previous topic View next topic Go down

[1.8.1]Adding your block to the creative GUI with no base files edited.

Post by msw1 on Tue Nov 01, 2011 12:34 am

This is a very easy thing to do.

So first, go to your mod_ file and add this to your constructor:

Code:
ModLoader.SetInGUIHook(this, true, true);
ModLOader.SetInGameHook(this, true, true);

There! Now you can use ModLoader's OnTickInGUI and OnTickInGame method.

Now add this OUTSIDE your constructor.

Code:
 

    @Override
    public boolean OnTickInGame(float f, Minecraft minecraft)
    {
        if(minecraft.currentScreen == null)
        {
            lastGuiOpen = null;
        }
        return true;
    }



  @Override
    public boolean OnTickInGUI(float f, Minecraft minecraft, GuiScreen guiscreen)
    {
        if((guiscreen instanceof GuiContainerCreative) && !(lastGuiOpen instanceof GuiContainerCreative) && !minecraft.theWorld.multiplayerWorld)
        {
            Container container = ((GuiContainer)guiscreen).inventorySlots;
            List list = ((ContainerCreative)container).itemList;
            for(int i = 0; i <= 1; i++)
            {
                list.add(new ItemStack(blockName, 1, i));
            }
        }
        return true;
    }

private static GuiScreen lastGuiOpen;

Where blockName is a block you made. If you have questions post comments!

If you don't know what this is its the spawning GUI in creative mode.

If you want to add more then one, it would be like this:

Code:
  @Override
    public boolean OnTickInGUI(float f, Minecraft minecraft, GuiScreen guiscreen)
    {
        if((guiscreen instanceof GuiContainerCreative) && !(lastGuiOpen instanceof GuiContainerCreative) && !minecraft.theWorld.multiplayerWorld)
        {
            Container container = ((GuiContainer)guiscreen).inventorySlots;
            List list = ((ContainerCreative)container).itemList;
            for(int i = 0; i <= 5; i++)
            {
                list.add(new ItemStack(blockName, 1, i));
                list.add(new ItemStack(blockName2, 1, i));
            }
        }
        lastGuiOpen = guiscreen;
        return true;
    }

private static GuiScreen lastGuiOpen;


Last edited by msw1 on Thu Nov 10, 2011 9:12 am; edited 3 times in total

msw1
Member

Posts : 8
Join date : 2011-11-01

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by groxmapper on Tue Nov 01, 2011 12:34 pm

This is great for SSP, but what about SMP? Does this work there?

EDIT: It doesn't know what "lastGUIOpen" is, so I'm assuming you defined it.
avatar
groxmapper
Member

Posts : 27
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by msw1 on Tue Nov 01, 2011 4:37 pm

Ah I'm an idiot. Forgot a step!

*EDIT* Updated tut.

msw1
Member

Posts : 8
Join date : 2011-11-01

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by msw1 on Tue Nov 01, 2011 4:43 pm

And yes it should work for SMP. Just turn it from

Code:
minecraft.theWorld.multiplayerWorld

to

Code:
minecraft.theWorld.singleplayerWorld

In the SMP version.

If your wondering why on earth you'd even set this, it's because you wouldn't want someone coming on a server with your mod installed so they can spawn stuff when they aren't even OP, would you?

msw1
Member

Posts : 8
Join date : 2011-11-01

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by groxmapper on Tue Nov 01, 2011 10:27 pm

msw1 wrote:And yes it should work for SMP. Just turn it from

Code:
minecraft.theWorld.multiplayerWorld

to

Code:
minecraft.theWorld.singleplayerWorld

In the SMP version.

If your wondering why on earth you'd even set this, it's because you wouldn't want someone coming on a server with your mod installed so they can spawn stuff when they aren't even OP, would you?

problem is, minecraft has no instance in MP. IE:

Code:
public boolean OnTickInGUI(float f, Minecraft minecraft, GuiScreen guiscreen)

In this line it calls "Minecraft minecraft" as an arguement. But Minecraft.java doesn't exist on a server, it's replaced by MinecraftServer, and modloader nor modloadermp change this, so what do I use for Minecraft?

EDIT: lastGuiOpen is never defined by anything, so what is it defined as?
avatar
groxmapper
Member

Posts : 27
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by msw1 on Wed Nov 02, 2011 12:17 am

lastGuiOpen is GuiScreen.java.

I'm not sure with the SMP thing...

My only idea is to make a custom class that extends BaseModMp and just copy all of the code with OnTickInGUI in BaseMod.java and ModLoader.java into this but replace Minecraft with MinecraftServer. Then in your mod_ file you'd use [ClassName].SetInGUIHook(this, true, true) instead of ModLoader.SetInGUIHook, [obviously you'd define it in the SMP file.] Then make your mod_ file extend this. Don't worry. You still have all of BaseModMp functions and BaseMod functions. Your new class extends BaseModMp which extends BaseMod.

You'd have to do the same for the client. You might have to use ModLoaderMP send packet/receive packet functions. Sorry if this isn't helpful.

msw1
Member

Posts : 8
Join date : 2011-11-01

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by groxmapper on Wed Nov 02, 2011 12:55 am

msw1 wrote:lastGuiOpen is GuiScreen.java.

I'm not sure with the SMP thing...

My only idea is to make a custom class that extends BaseModMp and just copy all of the code with OnTickInGUI in BaseMod.java and ModLoader.java into this but replace Minecraft with MinecraftServer. Then in your mod_ file you'd use [ClassName].SetInGUIHook(this, true, true) instead of ModLoader.SetInGUIHook, [obviously you'd define it in the SMP file.] Then make your mod_ file extend this. Don't worry. You still have all of BaseModMp functions and BaseMod functions. Your new class extends BaseModMp which extends BaseMod.

You'd have to do the same for the client. You might have to use ModLoaderMP send packet/receive packet functions. Sorry if this isn't helpful.

I mean, what is defining lastGuiOpen as the last gui open? None of the code sets it to this.

Also, ModLoaderMp has a "getMincraftServerInstance" like how ModLoader has "getMinecraftInstance" so that may work.
avatar
groxmapper
Member

Posts : 27
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by msw1 on Wed Nov 02, 2011 4:24 pm

I know. I haven't tested without it. Maybe it would work.

And the problem with that, is that ModLoaderMP does not have a every tick method for the game/guis

msw1
Member

Posts : 8
Join date : 2011-11-01

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by groxmapper on Thu Nov 03, 2011 2:09 am

msw1 wrote:I know. I haven't tested without it. Maybe it would work.

And the problem with that, is that ModLoaderMP does not have a every tick method for the game/guis

Actually modloaderMp comes with a serverside Modloader and OnTickInGame is edited to use MinecraftServer instead of Minecraft but IDK how to make a serverside "ontickingui" using that...
avatar
groxmapper
Member

Posts : 27
Join date : 2011-10-24

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by msw1 on Fri Nov 04, 2011 8:30 am

Well in that case do what I did above change all Minecraft's[uppercase] to MinecraftServer[uppercase] and minecraft[lowercase] to minecraftserver[lowercase] then tell me if it works.

msw1
Member

Posts : 8
Join date : 2011-11-01

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by msw1 on Thu Nov 10, 2011 9:12 am

Oh, turns out my tutorial was broken. Fixed.

msw1
Member

Posts : 8
Join date : 2011-11-01

View user profile

Back to top Go down

Re: [1.8.1]Adding your block to the creative GUI with no base files edited.

Post by Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum