-
Notifications
You must be signed in to change notification settings - Fork 1
/
FeatureDebugger.java
158 lines (135 loc) · 5.6 KB
/
FeatureDebugger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
package com.terraforged.feature.util;
import com.mojang.datafixers.types.JsonOps;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.ConfiguredRandomFeatureList;
import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.gen.feature.MultipleRandomFeatureConfig;
import net.minecraft.world.gen.feature.MultipleWithChanceRandomFeatureConfig;
import net.minecraft.world.gen.feature.SingleRandomFeature;
import net.minecraft.world.gen.feature.TwoFeatureChoiceConfig;
import net.minecraft.world.gen.placement.ConfiguredPlacement;
import net.minecraftforge.registries.ForgeRegistries;
import java.util.ArrayList;
import java.util.List;
public class FeatureDebugger {
public static List<String> getErrors(ConfiguredFeature<?, ?> feature) {
List<String> errors = new ArrayList<>();
try {
checkConfiguredFeature(feature, errors);
} catch (Throwable t) {
errors.add(
"Exception thrown whilst debugging biome feature: " + feature + " (this is bad)"
+ "\nError message:"
+ "\n" + t.getMessage()
);
}
return errors;
}
private static void checkConfiguredFeature(ConfiguredFeature<?, ?> feature, List<String> errors) {
if (!isValid(feature, errors)) {
return;
}
if (feature.config instanceof DecoratedFeatureConfig) {
decorated((DecoratedFeatureConfig) feature.config, errors);
return;
}
// note SingleRandomFeature & SingleRandomFeatureConfig names a mixed up
if (feature.config instanceof SingleRandomFeature) {
single((SingleRandomFeature) feature.config, errors);
return;
}
if (feature.config instanceof TwoFeatureChoiceConfig) {
twoChoice((TwoFeatureChoiceConfig) feature.config, errors);
return;
}
if (feature.config instanceof MultipleRandomFeatureConfig) {
multi((MultipleRandomFeatureConfig) feature.config, errors);
return;
}
if (feature.config instanceof MultipleWithChanceRandomFeatureConfig) {
multiChance((MultipleWithChanceRandomFeatureConfig) feature.config, errors);
return;
}
}
private static void decorated(DecoratedFeatureConfig config, List<String> errors) {
checkConfiguredFeature(config.feature, errors);
isValid(config.decorator, errors);
}
private static void single(SingleRandomFeature config, List<String> errors) {
for (ConfiguredFeature<?, ?> feature : config.features) {
checkConfiguredFeature(feature, errors);
}
}
private static void twoChoice(TwoFeatureChoiceConfig config, List<String> errors) {
checkConfiguredFeature(config.field_227285_a_, errors);
checkConfiguredFeature(config.field_227286_b_, errors);
}
private static void multi(MultipleRandomFeatureConfig config, List<String> errors) {
for (ConfiguredRandomFeatureList<?> feature : config.features) {
checkConfiguredFeature(feature.feature, errors);
}
}
private static void multiChance(MultipleWithChanceRandomFeatureConfig config, List<String> errors) {
for (ConfiguredFeature<?, ?> feature : config.features) {
checkConfiguredFeature(feature, errors);
}
}
private static boolean isValid(ConfiguredFeature<?, ?> feature, List<String> list) {
if (feature == null) {
list.add("null configured feature (this is bad! D: )");
return false;
}
return isValid(feature.feature, list) && isValid(feature.config, list);
}
private static boolean isValid(Feature<?> feature, List<String> list) {
if (feature == null) {
list.add("null feature");
return false;
} else if (!ForgeRegistries.FEATURES.containsValue(feature)) {
list.add("unregistered feature: " + feature.getClass().getName());
return false;
}
return true;
}
private static boolean isValid(IFeatureConfig config, List<String> list) {
if (config == null) {
list.add("null config");
return false;
}
try {
config.serialize(JsonOps.INSTANCE);
return true;
} catch (Throwable t) {
list.add("config: " + config.getClass().getName() + ", error: " + t.getMessage());
return false;
}
}
private static boolean isValid(ConfiguredPlacement<?> decorator, List<String> list) {
if (decorator == null) {
list.add("null configured placement");
return false;
}
boolean valid = true;
if (decorator.decorator == null) {
list.add("null placement");
valid = false;
} else if (!ForgeRegistries.DECORATORS.containsValue(decorator.decorator)) {
list.add("unregistered placement: " + decorator.decorator.getClass().getName());
valid = false;
}
if (decorator.config == null) {
list.add("null decorator config");
valid = false;
} else {
try {
decorator.config.serialize(JsonOps.INSTANCE);
} catch (Throwable t) {
valid = false;
list.add("placement config: " + decorator.config.getClass().getName() + ", error: " + t.getMessage());
}
}
return valid;
}
}