Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.