Jump to content

How to get list of Entity that can summon


Taskkill

Recommended Posts

First, please excuse my spelling errors.

I need to get the list of the entities that can summon by the commands. I've tried EntityList#getEntityNameList and EntityList#getClass , but as I'm using this, game crashed because of the Entity that spawned.

Please tell me how to do, thanks.

package task.heartstone.register;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.apache.logging.log4j.LogManager;

import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.passive.EntityPig;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;

public class EntityUtil {
	
	public static final List<Class<? extends Entity>> list = new ArrayList<Class<? extends Entity>>();
	
	public static void load() {
		Set<ResourceLocation> namelist = EntityList.getEntityNameList();
		for(ResourceLocation name : namelist) {
			Class<? extends Entity> clazz = EntityList.getClass(name);
			if(clazz != null) {
				list.add(clazz);
			}
		}
		for(Class clazz : list) {
			LogManager.getLogger("EntityUtil").info(clazz.getName());
		}
	}
	
	public static Entity getRandEntity(World world) {
		Random rand = new Random();
		int index = rand.nextInt(list.size()-1);
		return EntityList.newEntity(list.get(index), world);
	}
	
}

 

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.