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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • i tried to open the modpack with multimc by importing it from Ftb and it gave me an error https://paste.ee/p/YDqWN
    • Hi, I'm trying to render a single quad in the world. I'm mixing into the ChestRenderer class. If I understand correctly, BufferSource#getBuffer opens a buffer according to the supplied RenderType (Quads with POSITION_COLOR in my case). Then, I can supply my vertices (a simple 1-block plane along the Z Axis) and close the buffer using BufferSource#endBatch for rendering. This is the code I'm using: @Inject(at = @At("TAIL"), method = "render(...)V") public void render(T blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int packedLight, int packedOverlay, CallbackInfo ci) { BlockPos pos = blockEntity.getBlockPos(); AABB box = new AABB(pos, pos.offset(1, 1, 1)); BufferSource buffer = Minecraft.getInstance().renderBuffers().bufferSource(); VertexConsumer consumer = buffer.getBuffer(RenderType.guiOverlay()); poseStack.pushPose(); poseStack.translate(-pos.getX(), -pos.getY(), -pos.getZ()); consumer.vertex(box.minX, box.maxY, box.minZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.maxY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.maxZ).color(1, 1, 1, 1).endVertex(); consumer.vertex(box.minX, box.minY, box.minZ).color(1, 1, 1, 1).endVertex(); buffer.endBatch(RenderType.guiOverlay()); poseStack.popPose(); } However, the plane does not get rendered. However, if I replace those 4 vertices with a call to LevelRenderer#renderLineBox and set the RenderType to LINES, it works. Do I need something else to render planes other than the 4 edges of the quad? I used QUADS back in 1.8 where it was still the raw OpenGL type and it worked then. Or am I missing something else entirely? Thanks!
    • The Essential Role of Brunoe Quick Hack in Bitcoin Recovery Efforts The Brunoe Quick Hack has emerged as a vital tool in the ongoing efforts to recover lost or stolen Bitcoin. As the cryptocurrency landscape has evolved, the need for reliable and effective methods to regain access to misplaced or compromised digital assets has become increasingly pressing. The Brunoe Quick Hack, a specialized software solution, has stepped in to fill this critical void, offering Bitcoin users a lifeline when faced with the devastating prospect of permanently losing their hard-earned cryptocurrency holdings. At the core of this innovative technique lies a deep understanding of the underlying blockchain technology that powers Bitcoin, combined with a meticulous, methodical approach to identifying and exploiting vulnerabilities in the system. Through a series of carefully orchestrated steps, the Brunoe Quick Hack is able to bypass security measures, recover private keys, and restore access to Bitcoin wallets that were previously thought to be irretrievable. This process, while highly technical and requiring a skilled hand, has proven to be a game-changer for countless individuals and businesses who have fallen victim to the inherent risks of the cryptocurrency ecosystem. As the adoption of Bitcoin continues to grow, the Brunoe Quick Hack has emerged as an essential safeguard, providing a crucial safety net for those navigating the complex and ever-evolving world of digital finance. Contact this experts through: WhtasApp: + 170-"578-42"-635 Website: brunoequickhack.COM Email: brunoequickhack (AT) GMAIL (DOT) COM Thanks.
    • it doesnt let me import the zip that i use with curseforge
    • it doesnt let me import the zip that i use with curseforge
  • Topics

×
×
  • Create New...

Important Information

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