Jump to content

PacketHandler to open a GUI?


Xuluf

Recommended Posts

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

Link to comment
Share on other sites

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 :)

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.