Posted January 10, 20196 yr 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); } }
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.