Jump to content

Get Current Minecraft Player


Nicba1010

Recommended Posts

I am trying to make a level system. I have succseeded in some places but in other not. The main problem is: how to get current minecraft player, like i mean EntityPlayer.

Here is the error log: http://pastebin.com/ZMVjyjD6

This is the Gui class code:http://pastebin.com/LkVbuNQB

Before i have had

EntityPlayer p = mc.theplayer;

but this doesn't work.

 

Example where it works:

I the Block On Activated method:

public boolean onBlockActivated(World world, int x, int y, int z,EntityPlayer p, int a, float f, float b, float c){
	nbt=p.getEntityData();
	nbt.setInteger("level", getLevel()+1);
	return true;
	}
public int getLevel() {
	return nbt.getInteger("level");
}

because here i have the EntityPlayer supplied.

Chemistryzation.java(main class):http://pastebin.com/aNg5VYCq

 

Please help!

For any useful info you will be credited!

Link to comment
Share on other sites

It doesn't work because of the client-server architecture.

 

A SSP game and a SMP game with one connected user are indistinguishable.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

You can, you just have to approach it differently.

 

You are going to need an event hook to listen for players joining the server, then save data into the player that way.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

if you use a

spoiler

maybe, because my current network blocks pastebin

 

btw if you wanna check which side your on use:

 

FMLCo[ac].instance().getEffectiveSide().isClient()  ( the [ac] is auto complete, i dont remember the class name exactly)

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

 

package nicba1010.chemistryzation.common;

 

 

 

import net.minecraft.client.Minecraft;

 

import net.minecraft.client.gui.FontRenderer;

 

import net.minecraft.client.gui.Gui;

 

import net.minecraft.entity.player.EntityPlayer;

 

import net.minecraft.nbt.NBTTagCompound;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

 

import net.minecraftforge.event.EventPriority;

 

import net.minecraftforge.event.ForgeSubscribe;

 

 

 

//

 

// GuiBuffBar implements a simple status bar at the top of the screen which

 

// shows the current buffs/debuffs applied to the character.

 

//

 

public class GuiChemistryLevel extends Gui {

 

        private Minecraft mc;

 

        FontRenderer fontrenderer;

 

        EntityPlayer p;

 

        NBTTagCompound nbt;

 

 

 

        public GuiChemistryLevel(Minecraft mc) {

 

                super();

 

                fontrenderer = mc.fontRenderer;

 

                // We need this to invoke the render engine.

 

                this.mc = mc;

 

                nbt = p.getEntityData();

 

        }

 

 

 

        @ForgeSubscribe(priority = EventPriority.NORMAL)

 

        public void onRenderExperienceBar(RenderGameOverlayEvent event) {

 

                if (event.isCancelable() || event.type != ElementType.EXPERIENCE) {

 

                        return;

 

                }

 

                int level;

 

                level = nbt.getInteger("level");

 

                if (level == 0) {

 

                        nbt.setInteger("level", 1);

 

                        level = nbt.getInteger("level");

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                } else {

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                }

 

 

 

                this.mc.renderEngine.bindTexture("/gui/inventory.png");

 

        }

 

}

 

Link to comment
Share on other sites

heu ... yeah no shit you're having a NPE

 

 

 

package nicba1010.chemistryzation.common;

 

 

 

import net.minecraft.client.Minecraft;

 

import net.minecraft.client.gui.FontRenderer;

 

import net.minecraft.client.gui.Gui;

 

import net.minecraft.entity.player.EntityPlayer;

 

import net.minecraft.nbt.NBTTagCompound;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

 

import net.minecraftforge.event.EventPriority;

 

import net.minecraftforge.event.ForgeSubscribe;

 

 

 

//

 

// GuiBuffBar implements a simple status bar at the top of the screen which

 

// shows the current buffs/debuffs applied to the character.

 

//

 

public class GuiChemistryLevel extends Gui {

 

        private Minecraft mc;

 

        FontRenderer fontrenderer;

 

        EntityPlayer p;

 

        NBTTagCompound nbt;

 

 

 

        public GuiChemistryLevel(Minecraft mc) {

 

                super();

 

                fontrenderer = mc.fontRenderer;

 

                // We need this to invoke the render engine.

 

                this.mc = mc;

 

                nbt = p.getEntityData();

 

        }

 

 

 

        @ForgeSubscribe(priority = EventPriority.NORMAL)

 

        public void onRenderExperienceBar(RenderGameOverlayEvent event) {

 

                if (event.isCancelable() || event.type != ElementType.EXPERIENCE) {

 

                        return;

 

                }

 

                int level;

 

                level = nbt.getInteger("level");

 

                if (level == 0) {

 

                        nbt.setInteger("level", 1);

 

                        level = nbt.getInteger("level");

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                } else {

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                }

 

 

 

                this.mc.renderEngine.bindTexture("/gui/inventory.png");

 

        }

 

}

 

 

 

the EntityPlayer is never initialized

 

 

 

 

package nicba1010.chemistryzation.common;

 

 

 

import net.minecraft.client.Minecraft;

 

import net.minecraft.client.gui.FontRenderer;

 

import net.minecraft.client.gui.Gui;

 

import net.minecraft.entity.player.EntityPlayer;

 

import net.minecraft.nbt.NBTTagCompound;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

 

import net.minecraftforge.event.EventPriority;

 

import net.minecraftforge.event.ForgeSubscribe;

 

 

 

//

 

// GuiBuffBar implements a simple status bar at the top of the screen which

 

// shows the current buffs/debuffs applied to the character.

 

//

 

public class GuiChemistryLevel extends Gui {

 

        private Minecraft mc;

 

        FontRenderer fontrenderer;

 

        EntityPlayer p;

        //this should probably be a

        EntityClientPlayerMP player;

 

        NBTTagCompound nbt;

 

 

 

        public GuiChemistryLevel(Minecraft mc) {

 

                super();

 

                fontrenderer = mc.fontRenderer;

 

                // We need this to invoke the render engine.

 

                this.mc = mc;

                //now like i said earlier

                p = Minecraft.getMinecraft().thePlayer;

                //or

                p = mc.thePlayer;

                //since mc is a reference to the current Minecraft

 

                nbt = p.getEntityData();

 

        }

 

 

 

        @ForgeSubscribe(priority = EventPriority.NORMAL)

 

        public void onRenderExperienceBar(RenderGameOverlayEvent event) {

 

                if (event.isCancelable() || event.type != ElementType.EXPERIENCE) {

 

                        return;

 

                }

 

                int level;

 

                level = nbt.getInteger("level");

 

                if (level == 0) {

 

                        nbt.setInteger("level", 1);

 

                        level = nbt.getInteger("level");

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                } else {

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                }

 

 

 

                this.mc.renderEngine.bindTexture("/gui/inventory.png");

 

        }

 

}

 

 

 

btw not to be mean but i suggest you attack smaller mods. This is a pretty obvious error.

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

BTW STILL Caught exception from chemistryzation

java.lang.NullPointerException

at nicba1010.chemistryzation.common.GuiChemistryLevel.<init>(GuiChemistryLevel.java:49)

at nicba1010.chemistryzation.common.Chemistryzation.postInit(Chemistryzation.java:76)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:494)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

at com.google.common.eventbus.EventBus.post(EventBus.java:267)

at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98)

at cpw.mods.fml.common.Loader.initializeMods(Loader.java:695)

at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:206)

at net.minecraft.client.Minecraft.startGame(Minecraft.java:447)

at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)

at net.minecraft.client.Minecraft.run(Minecraft.java:732)

at java.lang.Thread.run(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] java.lang.NullPointerException

2013-06-27 16:23:32 [iNFO] [sTDERR] at nicba1010.chemistryzation.common.GuiChemistryLevel.<init>(GuiChemistryLevel.java:49)

2013-06-27 16:23:32 [iNFO] [sTDERR] at nicba1010.chemistryzation.common.Chemistryzation.postInit(Chemistryzation.java:76)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at cpw.mods.fml.common.FMLModContainer.handleModStateEvent(FMLModContainer.java:494)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:267)

2013-06-27 16:23:32 [iNFO] [sTDERR] at cpw.mods.fml.common.LoadController.propogateStateMessage(LoadController.java:165)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at java.lang.reflect.Method.invoke(Unknown Source)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventHandler.handleEvent(EventHandler.java:74)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.SynchronizedEventHandler.handleEvent(SynchronizedEventHandler.java:45)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatch(EventBus.java:314)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.dispatchQueuedEvents(EventBus.java:296)

2013-06-27 16:23:32 [iNFO] [sTDERR] at com.google.common.eventbus.EventBus.post(EventBus.java:267)

2013-06-27 16:23:32 [iNFO] [sTDERR] at cpw.mods.fml.common.LoadController.distributeStateMessage(LoadController.java:98)

2013-06-27 16:23:32 [iNFO] [sTDERR] at cpw.mods.fml.common.Loader.initializeMods(Loader.java:695)

2013-06-27 16:23:32 [iNFO] [sTDERR] at cpw.mods.fml.client.FMLClientHandler.finishMinecraftLoading(FMLClientHandler.java:206)

2013-06-27 16:23:32 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.startGame(Minecraft.java:447)

2013-06-27 16:23:32 [iNFO] [sTDERR] at net.minecraft.client.MinecraftAppletImpl.startGame(MinecraftAppletImpl.java:44)

2013-06-27 16:23:32 [iNFO] [sTDERR] at net.minecraft.client.Minecraft.run(Minecraft.java:732)

2013-06-27 16:23:32 [iNFO] [sTDERR] at java.lang.Thread.run(Unknown Source)

 

Link to comment
Share on other sites

can we see the class "Chemistryzation". why are you calling a gui from there ? Even worst, why is it from a method called postInit ?

 

 

at nicba1010.chemistryzation.common.GuiChemistryLevel.<init>(GuiChemistryLevel.java:49)

at nicba1010.chemistryzation.common.Chemistryzation.postInit(Chemistryzation.java:76)

 

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

package nicba1010.chemistryzation.common;

 

import net.minecraft.block.Block;

import net.minecraft.block.material.Material;

import net.minecraft.client.Minecraft;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.crafting.FurnaceRecipes;

import net.minecraftforge.common.MinecraftForge;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.Init;

import cpw.mods.fml.common.Mod.PostInit;

import cpw.mods.fml.common.event.FMLInitializationEvent;

import cpw.mods.fml.common.event.FMLPostInitializationEvent;

import cpw.mods.fml.common.network.NetworkMod;

import cpw.mods.fml.common.registry.GameRegistry;

import cpw.mods.fml.common.registry.LanguageRegistry;

 

@Mod(modid = Chemistryzation.modid, name = "chemistryzation", version = "0")

@NetworkMod(clientSideRequired = true, serverSideRequired = false)

public class Chemistryzation {

        public static final String modid = "chemistryzation";

        public static Block NaClBlock;

        public static Item NaClItem, NaClInBucketSolid, NaClInBucketMelted,

                        TestTube, NaClInTestTubeSolid;

 

        @Init

        public void load(FMLInitializationEvent event) {

                NaClBlock = new BlockNaClBlock(500, Material.rock)

                                .setUnlocalizedName("NaClBlock");

                GameRegistry.registerBlock(NaClBlock,

                                modid + "NaClBlock");

                LanguageRegistry.addName(NaClBlock, "Salt");

 

                NaClItem = new ItemNaClItem(5000).setUnlocalizedName("NaClItem");

                LanguageRegistry.addName(NaClItem, "NaCl");

 

                NaClInBucketSolid = new NaClInBucketSolid(5001)

                                .setUnlocalizedName("NaClInBucketSolid");

                LanguageRegistry.addName(NaClInBucketSolid, "NaCl");

 

                NaClInBucketMelted = new NaClInBucketMelted(5002)

                                .setUnlocalizedName("NaClInBucketMelted");

                LanguageRegistry.addName(NaClInBucketMelted, "NaCl");

 

                TestTube = new TestTube(5003).setUnlocalizedName("TestTube");

                LanguageRegistry.addName(TestTube, "Test Tube");

 

                NaClInTestTubeSolid = new NaClInTestTubeSolid(5004)

                                .setUnlocalizedName("NaClInTestTubeSolid");

                LanguageRegistry.addName(NaClInTestTubeSolid, "NaCl");

 

                GameRegistry.addRecipe(new ItemStack(Chemistryzation.TestTube, 8),

                                "XYX", "X X", " X ", Character.valueOf('X'), new ItemStack(

                                                Block.glass), Character.valueOf('Y'), Item.slimeBall);

 

                ItemStack NaClItemStack = new ItemStack(Chemistryzation.NaClItem);

                GameRegistry.addShapelessRecipe(new ItemStack(NaClInBucketSolid),

                                new Object[] { NaClItemStack, NaClItemStack, NaClItemStack,

                                                NaClItemStack, NaClItemStack, NaClItemStack,

                                                NaClItemStack, NaClItemStack,

                                                new ItemStack(Item.bucketEmpty) });

                GameRegistry

                                .addShapelessRecipe(new ItemStack(NaClInTestTubeSolid),

                                                new Object[] { NaClItemStack, NaClItemStack,

                                                                NaClItemStack, NaClItemStack,

                                                                new ItemStack(Chemistryzation.TestTube) });

                FurnaceRecipes.smelting().addSmelting(

                                Chemistryzation.NaClInBucketSolid.itemID, 0,

                                new ItemStack(Chemistryzation.NaClInBucketMelted), 0.1F);

        }

 

        @PostInit

        public void postInit(FMLPostInitializationEvent event) {

                MinecraftForge.EVENT_BUS.register(new GuiChemistryLevel(Minecraft

                                .getMinecraft()));

        }

}

Link to comment
Share on other sites

1 please use spoilers,

 

2 ..................

 

 

 

 

what you are saying to the mod right now is

"oh you're initializing the server? OPEN A GUI NOW NOW NOW" which cant happen server side

 

1 make a class that implements IGuiHandler

2 register this class like this

NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());

3 make GuiChemistryLevel  extends GuiScreen instead

4 call the gui from any method (either right click a block or bind it to a key)

5 look at the wiki and tutorials.

 

 

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

use something liek thsi

 

 

 

package nicba1010.chemistryzation.common;

 

 

 

import net.minecraft.client.Minecraft;

 

import net.minecraft.client.gui.FontRenderer;

 

import net.minecraft.client.gui.Gui;

 

import net.minecraft.entity.player.EntityPlayer;

 

import net.minecraft.nbt.NBTTagCompound;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent;

 

import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;

 

import net.minecraftforge.event.EventPriority;

 

import net.minecraftforge.event.ForgeSubscribe;

 

 

 

//

 

// GuiBuffBar implements a simple status bar at the top of the screen which

 

// shows the current buffs/debuffs applied to the character.

 

//

 

public class GuiChemistryLevel extends Gui {

 

        private Minecraft mc;

 

        FontRenderer fontrenderer;

 

        EntityPlayer p;

 

        NBTTagCompound nbt;

 

 

 

        public GuiChemistryLevel(Minecraft mc) {

 

                super();

 

                fontrenderer = mc.fontRenderer;

 

                // We need this to invoke the render engine.

 

                this.mc = mc;

 

        }

 

 

 

        @ForgeSubscribe(priority = EventPriority.NORMAL)

 

        public void onRenderExperienceBar(RenderGameOverlayEvent event) {

             

 

              p = mc.thePlayer;

              nbt = p.getEntityData();

 

                 

                if (event.isCancelable() || event.type != ElementType.EXPERIENCE) {

 

                        return;

 

                }

 

                int level;

 

                level = nbt.getInteger("level");

 

                if (level == 0) {

 

                        nbt.setInteger("level", 1);

 

                        level = nbt.getInteger("level");

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                } else {

 

                        fontrenderer.drawString("Level " + level, 1, 1, 0xffffffff);

 

                }

 

 

 

                this.mc.renderEngine.bindTexture("/gui/inventory.png");

 

        }

 

}

 

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

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.

×
×
  • Create New...

Important Information

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