Jump to content

Recommended Posts

Posted

Hi, im making a gold coin manager for minecraft 1.6.2 you can add and remove gold. It saves fine for singleplayer and for the player hosting the world over lan, but it doesnt save gold for other players over lan and they have to start again!

 

My question:

How can i save the int gold for a player over lan?

 

Details:

Im using NBTTagCompound to save and load.

 

My GoldHandler class:

 

  Reveal hidden contents

 

 

My PlayerHandler class:

 

  Reveal hidden contents

 

 

Please HELP!!!!    Thanks in advance!

Posted

1: i would use IExtendedProperty for that (and EntityConstructingEvent)

2:

 

  Quote
private static int currGold;

do you know what static means ??? because that would mean that its the SAME amount of gold for everyone

 

and btw theres no difference between LAN and a real server

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

-hydroflame, author of the forge revolution-

Posted

Hi, first of all thanks for replying.

 

I do know what static means and when more that 1 player are on the world they have different gold values so that isnt a problem.

 

Can u pls explain a bit more about the iextendedproperty?

 

Thanks

Posted

i can 100% guarantee you that it doesnt work like you want it to

but since you're confident i wont talk about it

 

 

for IExtendedProperty, make a class that implements it and attach it to an entity. this way you will be noticed when an entity is saved to the NBT and you can add your gold there

 

 

ps: [lmgtfy]how to use hashmap in java[/lmgtfy], trust me it will help

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

-hydroflame, author of the forge revolution-

Posted

Like this?:      Its not printing the "Testing 123..."    I tried @ForgeSubscribe, that didnt work either!  :(

 

 

  Reveal hidden contents

 

Posted

am i the only one who actually traced the code and foudn out that the currGold should NOT be static

 

 

1 everythign in thsi class is static except the constructor (but it cant sooo ... )

 

2:

public static void addGold(EntityPlayer player, int gold) {
      int index;
      GoldHandler instance;
      for(int i=0; i<PlayerHandler.names.size(); i++) {
         if(PlayerHandler.names.get(i).equalsIgnoreCase(player.username)) {
            index = i;
            instance = PlayerHandler.gh.get(i);
            break;
         }
      }
      currGold += gold;
      NBTTagCompound tag = player.getEntityData();
      tag.setInteger("player" + player.username + "Gold", currGold);
   }

what exactly is the variable "instance" suppose to do ? same for "index"

this code is the same as:

public static void addGold(EntityPlayer player, int gold) {
      currGold += gold;
      NBTTagCompound tag = player.getEntityData();
      tag.setInteger("player" + player.username + "Gold", currGold);
   }

 

 

same here ? instance and index are never used (actually most IDE would be whining about this)

public static void removeGold(EntityPlayer player, int gold) {
      int index;
      GoldHandler instance;
      for(int i=0; i<PlayerHandler.names.size(); i++) {
         if(PlayerHandler.names.get(i).equalsIgnoreCase(player.username)) {
            index = i;
            instance = PlayerHandler.gh.get(i);
            break;
         }
      }
      currGold -= gold;
      NBTTagCompound tag = player.getEntityData();
      tag.setInteger("player" + player.username + "Gold", currGold);
   }

is the same as:

public static void removeGold(EntityPlayer player, int gold) {
      currGold -= gold;
      NBTTagCompound tag = player.getEntityData();
      tag.setInteger("player" + player.username + "Gold", currGold);
   }

 

if you want to see how it doesnt work

 

do this:

take 2 player, set their gold to 50 each

add 25 gold to one player

remove 10 gold to the OTHER player

 

 

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

-hydroflame, author of the forge revolution-

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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