Tina Sprout Posted June 11, 2016 Posted June 11, 2016 How would one go about getting all the entities in the world, that includes ones that are not within the clients render distance. Any pointers would be greatly appreciated Quote
sham1 Posted June 11, 2016 Posted June 11, 2016 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. Quote 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.
Tina Sprout Posted June 11, 2016 Author Posted June 11, 2016 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 Quote
Ernio Posted June 11, 2016 Posted June 11, 2016 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). Quote 1.7.10 is no longer supported by forge, you are on your own.
Tina Sprout Posted June 11, 2016 Author Posted June 11, 2016 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) Quote
Ernio Posted June 11, 2016 Posted June 11, 2016 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). Quote 1.7.10 is no longer supported by forge, you are on your own.
Draco18s Posted June 11, 2016 Posted June 11, 2016 * 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. Quote 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.
jeffryfisher Posted June 11, 2016 Posted June 11, 2016 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. Quote 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.
Recommended Posts
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.