Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Okay so I recently made a forum post on the Minecraftforum.net and they said a bunch of things then after like 2 days one said that I was trying to open the gui on a singleplayer world and I had to use a PacketHandler for that. Now my question is, I don't understand the tutorial on the wiki. And I really need help with this. Minecraftforum.net link: http://www.minecraftforum.net/topic/1674623-i-need-help-with-a-guihandler

  • Author

Okay I've already got that part. But I want to open a gui on the open of a NEW world. So I tried the PlayerTracker but that didn't work :I

  • Author

Okay, I got an error that said that it tried to open a GUI without being a network mod. Code

 

 

package xul.mods.adventuremod;

import java.lang.annotation.Annotation;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import xul.mods.adventuremod.common.AdvCommonProxy;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.Init;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.Mod.PreInit;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.IConnectionHandler;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.ITinyPacketHandler;
import cpw.mods.fml.common.network.NetworkMod;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

@Mod(modid = "Xuluf_Adventuremod", name = "Adventuremod", version = "1.0 RC1")
@NetworkMod(clientSideRequired = true, serverSideRequired = false, channels = {"GenericRandom"}, packetHandler = PacketHandler.class)

public class Adventuremod
{


@Instance
public static Adventuremod instance = new Adventuremod();
private GuiHandler guiHandler = new GuiHandler();
@SidedProxy(clientSide = "xul.mods.adventuremod.AdvClientProxy", serverSide = "xul.mods.adventuremod.common.AdvCommonProxy")
public static AdvCommonProxy proxy;


/** Weapons */
public static Item battleaxewood;
public static Item battleaxestone;
public static Item battleaxeiron;
public static Item battleaxegold;
public static Item battleaxediamond;
public static Item battleaxedeamon;

@Init
public void Init(FMLInitializationEvent event) 
{
 proxy.registerRenderThings();

 battleaxewood = new ItemAdv(5000).setIconIndex(0).setItemName("BATTLEAXEWOOD");
 battleaxestone = new ItemAdv(5001).setIconIndex(1).setItemName("BATTLEAXESTONE");
 battleaxeiron = new ItemAdv(5002).setIconIndex(2).setItemName("BATTLEAXEIRON");
 battleaxegold = new ItemAdv(5003).setIconIndex(3).setItemName("BATTLEAXEGOLD");
 battleaxediamond = new ItemAdv(5004).setIconIndex(4).setItemName("BATTLEAXEDIAMOND");
 battleaxedeamon = new ItemAdv(5005).setIconIndex(5).setItemName("BATTLEAXEDEAMON");



 GameRegistry.registerItem(battleaxewood, "Wooden Battleaxe");
 LanguageRegistry.addName(battleaxewood, "Wooden Battleaxe");

 GameRegistry.registerItem(battleaxestone, "Stone Battleaxe");
 LanguageRegistry.addName(battleaxestone, "Stone Battleaxe");

 GameRegistry.registerItem(battleaxeiron, "Iron Battleaxe");
 LanguageRegistry.addName(battleaxeiron, "Iron Battleaxe");

 GameRegistry.registerItem(battleaxegold, "Gold Battleaxe");
 LanguageRegistry.addName(battleaxegold, "Gold Battleaxe");

 GameRegistry.registerItem(battleaxediamond, "Diamond Battleaxe");
 LanguageRegistry.addName(battleaxediamond, "Diamond Battleaxe");

 GameRegistry.registerItem(battleaxedeamon, "Deamon Battleaxe");
 LanguageRegistry.addName(battleaxedeamon, "Deamon Battleaxe");

 GameRegistry.addRecipe(new ItemStack(battleaxewood, 1), new Object[]{
	"***","***","***", '*', Block.dirt 

 });

 GameRegistry.addRecipe(new ItemStack(battleaxestone, 1), new Object[]{
	"***","*  ","***", '*', Block.dirt 

 });
 GameRegistry.addRecipe(new ItemStack(battleaxeiron, 1), new Object[]{
	"* *","***","***", '*', Block.dirt 

 });
 GameRegistry.addRecipe(new ItemStack(battleaxegold, 1), new Object[]{
	"***","* *","***", '*', Block.dirt 

 });
 GameRegistry.addRecipe(new ItemStack(battleaxediamond, 1), new Object[]{
	"***","***","* *", '*', Block.dirt 

 });
 GameRegistry.addRecipe(new ItemStack(battleaxedeamon, 1), new Object[]{
	"*", '*', Block.dirt 

 });

 MinecraftForgeClient.preloadTexture("/adventure/gui/items.png");

 GameRegistry.registerPlayerTracker(new PlayerTracker());
 NetworkRegistry.instance().registerGuiHandler(this, guiHandler);

}
}

 

 

 

package xul.mods.adventuremod;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.src.ModLoader;
import net.minecraft.world.World;
import cpw.mods.fml.common.IPlayerTracker;

public class PlayerTracker implements IPlayerTracker{

@Override
public void onPlayerLogin(EntityPlayer player) {

	NBTTagCompound tag = player.getEntityData();




	if(tag.getBoolean("onceConnected") != true){
		player.sendChatToPlayer("Hi! You just connected.");

		player.openGui(Adventuremod.instance, 26, player.worldObj, 0, 0, 0);

	}
	else{
		player.sendChatToPlayer("You are not a new player ");
	}tag.setBoolean("onceConnected", true);
}

@Override
public void onPlayerLogout(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void onPlayerChangedDimension(EntityPlayer player) {
	// TODO Auto-generated method stub

}

@Override
public void onPlayerRespawn(EntityPlayer player) {
	// TODO Auto-generated method stub

}

}

 

 

 

package xul.mods.adventuremod;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {
        //returns an instance of the Container you made earlier
        @Override
        public Object getServerGuiElement(int id, EntityPlayer player, World world,
                        int x, int y, int z) {
        	System.out.println("Server is working!");
                        return null;
        }

        //returns an instance of the Gui you made earlier
        @Override
        public Object getClientGuiElement(int id, EntityPlayer player, World world,
                        int x, int y, int z) {
        	
        	System.out.println("Client is working!");
        	
        	switch(id)
        	{
        	case 26:
        		System.out.println("Whatever");
			return new GuiStart();
        	default:
        	 return null;
        	}

        }
}

 

 

Tell me if I forgot any class or code :)

  • Author

For some odd reason the getClientGuiElement in the GuiHandler wont be called. Do I need to setup something or shouldn't I use that? :P

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.