From 5cb019d5b5a1aca249580052882266d5edf3b46b Mon Sep 17 00:00:00 2001 From: gnembon Date: Sat, 20 Jun 2020 11:18:39 -0300 Subject: [PATCH] there can be more than 3 dimensions, fixes #336 --- .../java/carpet/script/CarpetExpression.java | 16 ++++++++++++- .../java/carpet/utils/CarpetProfiler.java | 24 ++++++++++++------- src/main/java/carpet/utils/SpawnReporter.java | 11 +++++++-- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/src/main/java/carpet/script/CarpetExpression.java b/src/main/java/carpet/script/CarpetExpression.java index c47809a0..2f9a19ad 100644 --- a/src/main/java/carpet/script/CarpetExpression.java +++ b/src/main/java/carpet/script/CarpetExpression.java @@ -127,6 +127,7 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3i; import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.gen.feature.Feature; import net.minecraft.world.gen.feature.StructureFeature; import net.minecraft.world.SpawnHelper; @@ -3219,7 +3220,20 @@ public class CarpetExpression innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(World.OVERWORLD)); //ow break; default: - throw new InternalExpressionException("Incorrect dimension string: "+dimString); + RegistryKey dim = null; + Identifier id = new Identifier(dimString); + // not using RegistryKey.of since that one creates on check + for (RegistryKey world : (outerSource.getMinecraftServer().getWorldRegistryKeys())) + { + if (id.equals(world.getValue())) + { + dim = world; + break; + } + } + if (dim == null) + throw new InternalExpressionException("Incorrect dimension string: "+dimString); + innerSource = outerSource.withWorld(outerSource.getMinecraftServer().getWorld(dim)); } } ((CarpetContext) c).s = innerSource; diff --git a/src/main/java/carpet/utils/CarpetProfiler.java b/src/main/java/carpet/utils/CarpetProfiler.java index ca2f3034..fea6c1cb 100644 --- a/src/main/java/carpet/utils/CarpetProfiler.java +++ b/src/main/java/carpet/utils/CarpetProfiler.java @@ -6,6 +6,7 @@ import net.minecraft.server.MinecraftServer; import net.minecraft.block.entity.BlockEntity; import net.minecraft.server.command.ServerCommandSource; import net.minecraft.util.registry.Registry; +import net.minecraft.util.registry.RegistryKey; import net.minecraft.world.World; import java.util.Comparator; @@ -22,7 +23,6 @@ public class CarpetProfiler private static TYPE test_type = TYPE.NONE; //1 for ticks, 2 for entities; private static long current_tick_start = 0; private static final String[] GENERAL_SECTIONS = {"Network", "Autosave", "Async Tasks"}; - private static final String[] DIMENSIONS = {"overworld", "the_end", "the_nether"}; private static final String[] SECTIONS = { "Spawning and Random Ticks", "Ticket Manager","Unloading", "Blocks", "Entities", "Block Entities", @@ -56,7 +56,7 @@ public class CarpetProfiler private static String getSectionString(World world, String section) { return String.format("%s.%s%s", - world.getRegistryKey().getValue().toString().replaceFirst("minecraft:", ""), + world.getRegistryKey().getValue().getPath(), section, // ^ getDImension getId world.isClient ? " (Client)" : ""); } @@ -64,19 +64,24 @@ public class CarpetProfiler private static String getEntityString(World world, Entity e) { return String.format("%s.%s%s", - world.getRegistryKey().getValue().toString().replaceFirst("minecraft:", ""), - Registry.ENTITY_TYPE.getId(e.getType()).toString().replaceFirst("minecraft:", ""), + world.getRegistryKey().getValue().getPath(), + Registry.ENTITY_TYPE.getId(e.getType()).getPath(), world.isClient ? " (Client)" : ""); } private static String getTEntityString(World world, BlockEntity be) { return String.format("%s.%s%s", - world.getRegistryKey().getValue().toString().replaceFirst("minecraft:", ""), - Registry.BLOCK_ENTITY_TYPE.getId(be.getType()).toString().replaceFirst("minecraft:", ""), + world.getRegistryKey().getValue().getPath(), + Registry.BLOCK_ENTITY_TYPE.getId(be.getType()).getPath(), world.isClient ? " (Client)" : ""); } + private static String getDimName(RegistryKey world) + { + return world.getValue().getPath(); + } + public static void prepare_tick_report(ServerCommandSource source, int ticks) { //maybe add so it only spams the sending player, but honestly - all may want to see it @@ -89,11 +94,11 @@ public class CarpetProfiler { time_repo.put(section, 0L); } - for (String level : DIMENSIONS) + for (RegistryKey level : source.getMinecraftServer().getWorldRegistryKeys()) { for (String section : SECTIONS) { - time_repo.put(level + "." + section, 0L); + time_repo.put(getDimName(level) + "." + section, 0L); } } @@ -225,8 +230,9 @@ public class CarpetProfiler } } - for (String dimension : DIMENSIONS) + for (RegistryKey dim : server.getWorldRegistryKeys()) { + String dimension = getDimName(dim); boolean hasSomethin = false; for (String section : SECTIONS) { diff --git a/src/main/java/carpet/utils/SpawnReporter.java b/src/main/java/carpet/utils/SpawnReporter.java index e7fd674e..040eccbb 100644 --- a/src/main/java/carpet/utils/SpawnReporter.java +++ b/src/main/java/carpet/utils/SpawnReporter.java @@ -32,6 +32,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; public class SpawnReporter { @@ -325,6 +326,12 @@ public class SpawnReporter } track_spawns = 0L; } + + private static String getWorldCode(RegistryKey world) + { + if (world == World.OVERWORLD) return ""; + return "("+world.getValue().getPath().toUpperCase(Locale.ROOT).replace("THE_","").charAt(0)+")"; + } public static List tracking_report(World worldIn) { @@ -349,7 +356,7 @@ public class SpawnReporter { //String type_code = String.format("%s", enumcreaturetype); boolean there_are_mobs_to_list = false; - for (RegistryKey dim : Arrays.asList(World.OVERWORLD, World.NETHER, World.END)) //String world_code: new String[] {"", " (N)", " (E)"}) + for (RegistryKey dim : worldIn.getServer().getWorldRegistryKeys()) //String world_code: new String[] {"", " (N)", " (E)"}) { Pair, SpawnGroup> code = Pair.of(dim, enumcreaturetype); if (spawn_ticks_spawns.get(code) > 0L) @@ -357,7 +364,7 @@ public class SpawnReporter there_are_mobs_to_list = true; double hours = overall_spawn_ticks.get(code)/72000.0; report.add(Messenger.s(String.format(" > %s (%.1f min), %.1f m/t, {%.1f%%F / %.1f%%- / %.1f%%+}; %.2f s/att", - code.getRight()+((code.getLeft()==World.OVERWORLD)?"":( (code.getLeft()==World.NETHER)?"(N)":"(E)" )), // OW, nether + getWorldCode(dim), 60*hours, (1.0D*spawn_cap_count.get(code))/ spawn_attempts.get(code), (100.0D*spawn_ticks_full.get(code))/ spawn_attempts.get(code),