From 955eb361f4b8db2a3c3c89d5d38a390e5ba82d29 Mon Sep 17 00:00:00 2001 From: gnembon Date: Tue, 12 May 2020 17:00:02 -0300 Subject: [PATCH] added 'all' options to spawn entites and fixed definition of mobcappable --- .../java/carpet/commands/SpawnCommand.java | 7 ++--- src/main/java/carpet/utils/SpawnReporter.java | 26 ++++++++++--------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/java/carpet/commands/SpawnCommand.java b/src/main/java/carpet/commands/SpawnCommand.java index d141b291..f50e858b 100644 --- a/src/main/java/carpet/commands/SpawnCommand.java +++ b/src/main/java/carpet/commands/SpawnCommand.java @@ -98,7 +98,8 @@ public class SpawnCommand executes( (c) -> generalMobcaps(c.getSource()) ). then(argument("type", string()). suggests( (c, b)->suggestMatching(Arrays.stream(EntityCategory.values()).map(EntityCategory::getName), b)). - executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type"))))); + executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type"), false)). + then(literal("all").executes( (c) -> listEntitiesOfType(c.getSource(), getString(c, "type"), true))))); dispatcher.register(literalargumentbuilder); } @@ -262,10 +263,10 @@ public class SpawnCommand return 1; } - private static int listEntitiesOfType(ServerCommandSource source, String mobtype) throws CommandSyntaxException + private static int listEntitiesOfType(ServerCommandSource source, String mobtype, boolean all) throws CommandSyntaxException { EntityCategory cat = getCategory(mobtype); - Messenger.send(source, SpawnReporter.printEntitiesByType(cat, source.getWorld())); + Messenger.send(source, SpawnReporter.printEntitiesByType(cat, source.getWorld(), all)); return 1; } } diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index defd6071..4e6cd8a5 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -186,7 +186,7 @@ public class SpawnReporter } else { - return printEntitiesByType(creature_type, worldIn); + return printEntitiesByType(creature_type, worldIn, true); } @@ -250,22 +250,24 @@ public class SpawnReporter return get_type_string(get_creature_type_from_code(str)); } - public static List printEntitiesByType(EntityCategory cat, World worldIn) //Class entityType) + public static List printEntitiesByType(EntityCategory cat, World worldIn, boolean all) //Class entityType) { List lst = new ArrayList<>(); lst.add( Messenger.s(String.format("Loaded entities for %s class:", get_type_string(cat)))); for (Entity entity : ((ServerWorld)worldIn).getEntities(null, (e) -> e.getType().getCategory()==cat)) { - if (!(entity instanceof MobEntity) || !((MobEntity)entity).isPersistent()) - { - EntityType type = entity.getType(); - BlockPos pos = entity.getBlockPos(); - lst.add( Messenger.c( - "w - ", - Messenger.tp("wb",pos), - String.format("w : %s", type.getName().getString()) - )); - } + boolean persistent = entity instanceof MobEntity && ( ((MobEntity) entity).isPersistent() || ((MobEntity) entity).cannotDespawn()); + if (!all && persistent) + continue; + + EntityType type = entity.getType(); + BlockPos pos = entity.getBlockPos(); + lst.add( Messenger.c( + "w - ", + Messenger.tp(persistent?"gb":"wb",pos), + String.format(persistent?"g : %s":"w : %s", type.getName().getString()) + )); + } if (lst.size()==1) {