Jump to content

Recommended Posts

Posted

 

 

I want to get a random number from server, and add the number to entityplayer class.

 

here is my simple thought

 

 

public void Prepare()

{

java.util.Random random=new java.util.Random();

int MaxPlayer=Minecraft.getMinecraft().theWorld.playerEntities.size();

int result=random.nextInt(MaxPlayer);

EntityPlayer ply;

for(int i=0;i<MaxPlayer;i++)

{

 

 

 

ply=(EntityPlayer)Minecraft.getMinecraft().theWorld.playerEntities.get(i);

ply.addChatComponentMessage(new ChatComponentTranslation(ply.getDisplayName(), new Object[0]));

if(i!=result)

{

 

ply.getEntityData().setInteger("Team", 1);

}

else

{

ply.getEntityData().setInteger("Team", 2);

}

 

}

}

 

 

of course it's not working.

 

maybe the reason is client or server stuff,i don't know how to fix this.

 

could you tell me the property way to make it , thanks  a lot

 

 

PS: i know networking send messages can do that,but it seems a little complicated, is there  any easier way to do that?

Posted

In 1.7 you need to assign IExtendedEntityProperties (IEEP) via @SubscribeEvent of EntityConstructingEvent.

 

IEEP is generally assigned on both sides, but it is entirely up to you.

If the data will be only used by server (nothing will be ever displayed to clients) you can assign IEEP only on server (!world.isRemote), otherwise assign on both.

 

Your IEEP class will need to hold that one integer generated during construction (mind that there is alredy Random instance in entity class).

If the value should be saved (not per-session) - you need to write/read it from NBT (all in IEEP interface).

 

If you need clients to ever see anything - you will always need to sync data (SimpleNetworkWrapper - SNW).

 

Links:

Sides: http://mcforge.readthedocs.io/en/latest/concepts/sides/

 

IEEP: http://mcforge.readthedocs.io/en/latest/datastorage/extendedentityproperties/

Implementation: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-forge-1-6-4-1-8-eventhandler-and

 

SNW: www.minecraftforge.net/forum/index.php/topic,20135.0.html

Implementation: http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/2137055-1-7-x-1-8-customizing-packet-handling-with

 

Ask if you have a problem (but seriously, you ahve everything you need to make what you are after, use google for Event tutorials)

1.7.10 is no longer supported by forge, you are on your own.

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.