XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

MyDimension

【Java】我的维度模组

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/MyDimension

优化维度名称显示

0bedda9
XFE工作室室长 <mail@xfegzs.com>
提交于

代码差异

4 个文件 +55 -18
Modified build.gradle +8 -8
@@ -54,11 +54,11 @@ tasks.register('generatePlayerMindDimensions') {
54 54 outputs.dir(outputDir)
55 55
56 56 doLast {
57 def dimensionDir = outputDir.get().dir('data/mydimension/dimension/player_minds').asFile
57 def dimensionDir = outputDir.get().dir('data/mydimension/dimension').asFile
58 58 delete(dimensionDir)
59 59
60 60 def dimensions = [
61 ethereal_mind: [
61 e: [
62 62 type : 'mydimension:ethereal_mind',
63 63 generator: [
64 64 type : 'minecraft:flat',
@@ -75,7 +75,7 @@ tasks.register('generatePlayerMindDimensions') {
75 75 ]
76 76 ]
77 77 ],
78 mirror_mind : [
78 m: [
79 79 type : 'mydimension:mirror_mind',
80 80 generator: [
81 81 type : 'mydimension:no_structure_noise',
@@ -86,7 +86,7 @@ tasks.register('generatePlayerMindDimensions') {
86 86 settings : 'minecraft:overworld'
87 87 ]
88 88 ],
89 water_mind : [
89 w: [
90 90 type : 'mydimension:water_mind',
91 91 generator: [
92 92 type : 'minecraft:flat',
@@ -103,7 +103,7 @@ tasks.register('generatePlayerMindDimensions') {
103 103 ]
104 104 ]
105 105 ],
106 nature_mind : [
106 n: [
107 107 type : 'mydimension:nature_mind',
108 108 generator: [
109 109 type : 'minecraft:flat',
@@ -120,7 +120,7 @@ tasks.register('generatePlayerMindDimensions') {
120 120 ]
121 121 ]
122 122 ],
123 soaring_mind : [
123 s: [
124 124 type : 'mydimension:soaring_mind',
125 125 generator: [
126 126 type : 'mydimension:soaring_islands',
@@ -147,8 +147,8 @@ tasks.register('generatePlayerMindDimensions') {
147 147 ]
148 148
149 149 (0..<2).each { slot ->
150 dimensions.each { name, json ->
151 def file = new File(dimensionDir, "slot_${slot}/${name}.json")
150 dimensions.each { code, json ->
151 def file = new File(dimensionDir, "p${slot}${code}.json")
152 152 file.parentFile.mkdirs()
153 153 file.text = groovy.json.JsonOutput.prettyPrint(groovy.json.JsonOutput.toJson(json)) + System.lineSeparator()
154 154 }
Modified gradle.properties +1 -1
@@ -11,7 +11,7 @@ loader_version_range=[47,)
11 11 mod_id=mydimension
12 12 mod_name=\u6211\u7684\u7ef4\u5ea6
13 13 mod_license=CC0-1.0
14 mod_version=2.2.0
14 mod_version=2.2.1
15 15 mod_group_id=com.xfestudio.mydimension
16 16 maven_group=com.xfestudio
17 17 archives_base_name=mydimension
Modified src/main/java/com/xfestudio/mydimension/world/MindInstances.java +7 -8
@@ -119,7 +119,7 @@ public class MindInstances {
119 119
120 120 private static void writeGeneratedDatapack(MinecraftServer server, int slotsNeeded) {
121 121 Path datapackRoot = server.getWorldPath(LevelResource.DATAPACK_DIR).resolve(GENERATED_DATAPACK_NAME);
122 Path dimensionDir = datapackRoot.resolve("data").resolve(MyDimension.MOD_ID).resolve("dimension").resolve("player_minds");
122 Path dimensionDir = datapackRoot.resolve("data").resolve(MyDimension.MOD_ID).resolve("dimension");
123 123 try {
124 124 deleteDirectory(dimensionDir);
125 125 Files.createDirectories(dimensionDir);
@@ -141,13 +141,12 @@ public class MindInstances {
141 141 }
142 142
143 143 private static void writeSlotDimensions(Path dimensionDir, int slot) throws IOException {
144 Path slotDir = dimensionDir.resolve("slot_" + slot);
145 Files.createDirectories(slotDir);
146 Files.writeString(slotDir.resolve("ethereal_mind.json"), etherealMindJson(), StandardCharsets.UTF_8);
147 Files.writeString(slotDir.resolve("mirror_mind.json"), mirrorMindJson(), StandardCharsets.UTF_8);
148 Files.writeString(slotDir.resolve("water_mind.json"), waterMindJson(), StandardCharsets.UTF_8);
149 Files.writeString(slotDir.resolve("nature_mind.json"), natureMindJson(), StandardCharsets.UTF_8);
150 Files.writeString(slotDir.resolve("soaring_mind.json"), soaringMindJson(), StandardCharsets.UTF_8);
144 Files.createDirectories(dimensionDir);
145 Files.writeString(dimensionDir.resolve("p" + slot + "e.json"), etherealMindJson(), StandardCharsets.UTF_8);
146 Files.writeString(dimensionDir.resolve("p" + slot + "m.json"), mirrorMindJson(), StandardCharsets.UTF_8);
147 Files.writeString(dimensionDir.resolve("p" + slot + "w.json"), waterMindJson(), StandardCharsets.UTF_8);
148 Files.writeString(dimensionDir.resolve("p" + slot + "n.json"), natureMindJson(), StandardCharsets.UTF_8);
149 Files.writeString(dimensionDir.resolve("p" + slot + "s.json"), soaringMindJson(), StandardCharsets.UTF_8);
151 150 }
152 151
153 152 private static void deleteDirectory(Path directory) throws IOException {
Modified src/main/java/com/xfestudio/mydimension/world/ModDimensions.java +39 -1
@@ -85,6 +85,22 @@ public class ModDimensions {
85 85 "soaring_mind", SOARING_MIND
86 86 );
87 87
88 private static final Map<String, ResourceKey<Level>> PRIVATE_MIND_CODES = Map.of(
89 "e", ETHEREAL_MIND,
90 "m", MIRROR_MIND,
91 "w", WATER_MIND,
92 "n", NATURE_MIND,
93 "s", SOARING_MIND
94 );
95
96 private static final Map<ResourceKey<Level>, String> PRIVATE_MIND_IDS = Map.of(
97 ETHEREAL_MIND, "e",
98 MIRROR_MIND, "m",
99 WATER_MIND, "w",
100 NATURE_MIND, "n",
101 SOARING_MIND, "s"
102 );
103
88 104 public static boolean isMindDimension(ResourceKey<Level> dimension) {
89 105 return baseMindDimension(dimension) != null;
90 106 }
@@ -100,6 +116,11 @@ public class ModDimensions {
100 116 }
101 117
102 118 String path = location.getPath();
119 ResourceKey<Level> privateBase = basePrivateMindDimension(path);
120 if (privateBase != null) {
121 return privateBase;
122 }
123
103 124 String prefix = "player_minds/slot_";
104 125 if (!path.startsWith(prefix)) {
105 126 return null;
@@ -113,6 +134,23 @@ public class ModDimensions {
113 134 return MIND_IDS.get(path.substring(slash + 1));
114 135 }
115 136
137 private static ResourceKey<Level> basePrivateMindDimension(String path) {
138 if (path.length() < 3 || path.charAt(0) != 'p') {
139 return null;
140 }
141
142 int index = 1;
143 while (index < path.length() && Character.isDigit(path.charAt(index))) {
144 index++;
145 }
146
147 if (index == 1 || index != path.length() - 1) {
148 return null;
149 }
150
151 return PRIVATE_MIND_CODES.get(path.substring(index));
152 }
153
116 154 public static ResourceKey<Level> playerDimension(ResourceKey<Level> baseDimension, int slot) {
117 155 ResourceKey<Level> base = baseMindDimension(baseDimension);
118 156 if (base == null) {
@@ -121,7 +159,7 @@ public class ModDimensions {
121 159
122 160 return ResourceKey.create(
123 161 Registries.DIMENSION,
124 new ResourceLocation(MyDimension.MOD_ID, "player_minds/slot_" + slot + "/" + base.location().getPath())
162 new ResourceLocation(MyDimension.MOD_ID, "p" + slot + PRIVATE_MIND_IDS.get(base))
125 163 );
126 164 }
127 165