[1.8.1]Adding your block to the creative GUI with no base files edited.
2 posters
Page 1 of 1
[1.8.1]Adding your block to the creative GUI with no base files edited.
This is a very easy thing to do.
So first, go to your mod_ file and add this to your constructor:
There! Now you can use ModLoader's OnTickInGUI and OnTickInGame method.
Now add this OUTSIDE your constructor.
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:
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
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
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.
EDIT: It doesn't know what "lastGUIOpen" is, so I'm assuming you defined it.
groxmapper- Member
- Posts : 27
Join date : 2011-10-24
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
Ah I'm an idiot. Forgot a step!
*EDIT* Updated tut.
*EDIT* Updated tut.
msw1- Member
- Posts : 8
Join date : 2011-11-01
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
And yes it should work for SMP. Just turn it from
to
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?
- 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
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
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?
groxmapper- Member
- Posts : 27
Join date : 2011-10-24
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
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'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
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
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.
groxmapper- Member
- Posts : 27
Join date : 2011-10-24
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
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
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
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
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...
groxmapper- Member
- Posts : 27
Join date : 2011-10-24
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
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
Re: [1.8.1]Adding your block to the creative GUI with no base files edited.
Oh, turns out my tutorial was broken. Fixed.
msw1- Member
- Posts : 8
Join date : 2011-11-01
Similar topics
» [1.8.1] Adding a new gamemode
» [1.8.1] Block
» How to make a new block that has a gui simply
» [1.8.1] On/Off Light Block
» [1.8.1] Advanced Block
» [1.8.1] Block
» How to make a new block that has a gui simply
» [1.8.1] On/Off Light Block
» [1.8.1] Advanced Block
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum