Jump to content

[1.7.10] [Solved]Getting all entities in the world


Tina Sprout

Recommended Posts

Any pointers would be greatly appreciated  :-*

 

0xDEADBEEF.

 

Jokes aside, what are you exactly trying to do that requires you to get all the entities. As there are A LOT of entities.

If my post helped you, please press that "Thank You"-button to show your appreciation.

 

Also if you don't know Java, I would suggest you read the official tutorials by Oracle to get an idea of how to do this. Thanks, and good modding!

 

Also if you haven't, set up a Git repo for your mod not only for convinience but also to make it easier to help you.

Link to comment
Share on other sites

Any pointers would be greatly appreciated  :-*

 

0xDEADBEEF.

 

Jokes aside, what are you exactly trying to do that requires you to get all the entities. As there are A LOT of entities.

I'm making a fun mod for me and my friend that will every 10-20 minute (haven't decided yet) it will swap entities position around, the mod should also work in singleplayer thus why i need to be able to do it client sided aswel

Link to comment
Share on other sites

Please define "client side"!

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

 

If you don't have access to server - you will not be able to swap their positions (or even grab them all for that matter).

 

EDIT

 

Hint:

SP is MP with one player online (there is server in background).

Yeah sorry i meant the server side as i forgot SP is MP now (haven't modded in a long time)

Link to comment
Share on other sites

1. @SubscribeEvent to WorldTickEvent.

* Remember to pick event.phase, or code will run twice!

* I am not sure if WorldTickEvent is fired on both sides, or maybe only server - if on both, make (!world.isRemote) check to run it ONLY on server.

2. Use Random (event.world.rand) to fire your code every "some" time.

3. To access all entities you can use World#entityList (or some getter, look into World.class and you will see entityList)

4. To teleport them you can call entity.setPosAndUpdate (since you are on 1.7, I don't know exact name, but something like this).

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

Link to comment
Share on other sites

* I am not sure if WorldTickEvent is fired on both sides, or maybe only server - if on both, make (!world.isRemote) check to run it ONLY on server.

 

It's server side and you'll want to check the phase (pick either Start or End, probably start).

 

Do be aware that you can only teleport entities in loaded chunks.  You won't be able to shuffle about entities in chunks that the server does not currently have in memory.

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

To get all entities in the world, I think you need to load all chunks in the world. That would be a nightmare (in an old MP world that has been widely explored, you'd exhaust memory and/or choke the CPU).

 

However, there may be a way to tease out some knowledge of all entity IDs in the world and pick one before getting the entity itself. Unfortunately, except for players, that might not tell you where the entity is so you can load its chunk and teleport it.

 

Perhaps you'd consider a less ambitious effect: If there are 2 or more players in the world, and if they are a minimum of ~200 blocks apart, then swap a mob near one with a mob near another. Then you'd only need to deal with loaded chunks.

 

Also: Chunks without players tend to despawn their monsters, leaving only passive mobs. If you want more mayhem, then you want to work close to your players anyway.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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



×
×
  • Create New...

Important Information

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