I am currently working on a mod (requested by darkAntlord) that adds features from Steven Universe into Minecraft. When a player joins a world for the first time, a GUI is supposed to come up to allow them to customize several new features of their character that are added by the mod. However, the GUI will not open.
Base mod class:
package stevenUniverseMod;
import stevenUniverseMod.event.FMLEventHandler;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
@Mod(modid=UniverseBase.MODID, name=UniverseBase.MODNAME, version=UniverseBase.MODVER) //Tell forge "Oh hey, there's a new mod here to load."
public class UniverseBase {
FMLEventHandler events = new FMLEventHandler();
//Set the ID of the mod (Should be lower case).
public static final String MODID = "universegem";
//Set the "Name" of the mod.
public static final String MODNAME = "Steven Universe Mod";
//Set the version of the mod.
public static final String MODVER = "0.0.0";
@Instance(value = UniverseBase.MODID) //Tell Forge what instance to use.
public static UniverseBase instance;
@SidedProxy ( clientSide = "stevenUniverseMod.ClientProxy", serverSide = "stevenUniverseMod.CommonProxy" )
public static CommonProxy proxy;
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
FMLCommonHandler.instance().bus().register(events);
}
@EventHandler
public void init(FMLInitializationEvent event)
{
NetworkRegistry.INSTANCE.registerGuiHandler(instance, proxy);
}
@EventHandler
public void postInit(FMLPostInitializationEvent event)
{
}
}
Custom GUI class:
package stevenUniverseMod;
import java.awt.MouseInfo;
import java.awt.Point;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.StatCollector;
public class GuiGemSelection extends GuiScreen {
public static final int GUI_ID = 20;
public GuiGemSelection(){}
@Override
public void initGui(){
GuiButton Choice1 = new GuiButton(0, 10, 125, "Cabochon");
Choice1.visible = true;
buttonList.add(Choice1);
GuiButton Choice2 = new GuiButton(1, 10, 150, "Round Brilliant");
Choice2.visible = true;
buttonList.add(Choice2);
GuiButton Choice3 = new GuiButton(1, 10, 175, "Old Mine");
Choice3.visible = true;
buttonList.add(Choice3);
GuiButton Choice4 = new GuiButton(1, 10, 200, "Table");
Choice4.visible = true;
buttonList.add(Choice4);
GuiButton Choice5 = new GuiButton(1, 10, 225, "Emerald");
Choice5.visible = true;
buttonList.add(Choice5);
}
@Override
public void drawScreen(int par1, int par2, float par3) {
this.drawDefaultBackground();
fontRendererObj.drawString("Choose your gem cut", 10, 50, 0xFFFF00);
for(Object button : buttonList){
GuiButton gbutton = (GuiButton) button;
gbutton.drawButton(Minecraft.getMinecraft(), gbutton.xPosition, gbutton.yPosition);
}
}
@Override
public void updateScreen(){
for(Object button : buttonList){
GuiButton gbutton = (GuiButton) button;
Point p = MouseInfo.getPointerInfo().getLocation();
if(gbutton.mousePressed(Minecraft.getMinecraft(), p.x, p.y)){
for(Object button2 : buttonList){
GuiButton gbutton2 = (GuiButton) button;
gbutton2.visible = false;
}
}
}
}
}
Event handler class:
package stevenUniverseMod;
import stevenUniverseMod.GuiGemSelection;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
public class FMLEventHandler {
@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
NBTTagCompound universeData = event.player.getEntityData();
NBTTagCompound persistent;
if (!universeData.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) {
universeData.setTag(EntityPlayer.PERSISTED_NBT_TAG, (persistent = new NBTTagCompound()));
} else {
persistent = universeData.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
}
if (!persistent.hasKey("gemSelected")) {
persistent.setBoolean("gemSelected", true);
Minecraft.getMinecraft().displayGuiScreen(new GuiGemSelection());
}
}
}
I am currently working on a mod (requested by darkAntlord) that adds features from Steven Universe into Minecraft. When a player joins a world for the first time, a GUI is supposed to come up to allow them to customize several new features of their character that are added by the mod. However, the GUI will not open.
Base mod class:
Custom GUI class:
Event handler class:
Please help!
This isn't the correct way to display guis.
try
Your proxy should extend IGuiHandler. And you should register it like so
This still doesn't work. What are pos.getX, Y, Z()? They appeared as errors when I typed them in, so I just replaced them all with 0, but to no avail.
EDIT: I'm not using a block to open the GUI, so I don't know what I should set the pos.get()'s to.
Still not working!
Interestingly, after adding several System.out.println()'s in strategic locations, this is what I got:
[15:34:41] [Server thread/INFO]: Preparing spawn area: 4%
[15:34:42] [Server thread/INFO]: Preparing spawn area: 8%
[15:34:43] [Server thread/INFO]: Preparing spawn area: 15%
[15:34:44] [Server thread/INFO]: Preparing spawn area: 22%
[15:34:45] [Server thread/INFO]: Preparing spawn area: 29%
[15:34:46] [Server thread/INFO]: Preparing spawn area: 36%
[15:34:47] [Server thread/INFO]: Preparing spawn area: 43%
[15:34:48] [Server thread/INFO]: Preparing spawn area: 51%
[15:34:49] [Server thread/INFO]: Preparing spawn area: 58%
[15:34:50] [Server thread/INFO]: Preparing spawn area: 66%
[15:34:51] [Server thread/INFO]: Preparing spawn area: 76%
[15:34:52] [Server thread/INFO]: Preparing spawn area: 84%
[15:34:53] [Server thread/INFO]: Preparing spawn area: 87%
[15:34:54] [Server thread/INFO]: Preparing spawn area: 98%
[15:34:54] [Server thread/INFO]: Changing view distance to 12, from 10
[15:34:55] [Netty Client IO #0/INFO] [FML]: Server protocol version 2
[15:34:55] [Netty IO #1/INFO] [FML]: Client protocol version 2
[15:34:55] [Netty IO #1/INFO] [FML]: Client attempting to join with 4 mods : [email protected],[email protected],[email protected],[email protected]
[15:34:55] [Netty IO #1/INFO] [FML]: Attempting connection with missing mods [] at CLIENT
[15:34:55] [Netty Client IO #0/INFO] [FML]: Attempting connection with missing mods [] at SERVER
[15:34:55] [Server thread/INFO] [FML]: [Server thread] Server side modded connection established
[15:34:55] [Server thread/INFO]: Player846[local:E:ee62fbdd] logged in with entity id 236 at (-253.5, 64.0, 241.5)
[15:34:55] [Server thread/INFO]: Player846 joined the game
[15:34:55] [Server thread/INFO] [STDOUT]: [stevenUniverseMod.FMLEventHandler:onPlayerJoin:24]: Gui triggered!
[15:34:56] [Client thread/INFO] [FML]: [Client thread] Client side modded connection established
After "Gui triggered!" there was supposed to be another stdout message: "Rendering working!"
Nevermind, I was able to get this working by changing GuiGemSelection to extend ContainerGui and adding a dummy container class.