mirror of https://github.com/PaperMC/Paper.git
consolidate key format for mob goal keys
This commit is contained in:
parent
aa12616d3d
commit
6731eb20c7
|
@ -3,10 +3,10 @@ package io.papermc.generator.rewriter;
|
|||
import io.papermc.generator.utils.ClassHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public record ClassNamed(String packageName, String simpleName, String dottedNestedName, @Nullable Class<?> clazz) {
|
||||
public record ClassNamed(String packageName, String simpleName, String dottedNestedName, @Nullable Class<?> knownClass) {
|
||||
|
||||
public ClassNamed(Class<?> clazz) {
|
||||
this(clazz.getPackageName(), clazz.getSimpleName(), ClassHelper.retrieveFullNestedName(clazz), clazz);
|
||||
public ClassNamed(Class<?> knownClass) {
|
||||
this(knownClass.getPackageName(), knownClass.getSimpleName(), ClassHelper.retrieveFullNestedName(knownClass), knownClass);
|
||||
}
|
||||
|
||||
// the class name shouldn't have any '$' char in it
|
||||
|
@ -26,8 +26,8 @@ public record ClassNamed(String packageName, String simpleName, String dottedNes
|
|||
}
|
||||
|
||||
public String rootClassSimpleName() {
|
||||
if (this.clazz != null) {
|
||||
return ClassHelper.getRootClass(this.clazz).getSimpleName();
|
||||
if (this.knownClass != null) {
|
||||
return ClassHelper.getRootClass(this.knownClass).getSimpleName();
|
||||
}
|
||||
|
||||
int dotIndex = this.dottedNestedName.indexOf('.');
|
||||
|
@ -42,8 +42,8 @@ public record ClassNamed(String packageName, String simpleName, String dottedNes
|
|||
}
|
||||
|
||||
public String canonicalName() {
|
||||
if (this.clazz != null) {
|
||||
return this.clazz.getCanonicalName();
|
||||
if (this.knownClass != null) {
|
||||
return this.knownClass.getCanonicalName();
|
||||
}
|
||||
|
||||
return this.packageName + '.' + this.dottedNestedName;
|
||||
|
|
|
@ -1,21 +1,20 @@
|
|||
package io.papermc.generator.rewriter;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CompositeRewriter extends SearchReplaceRewriter {
|
||||
|
||||
private final Map<String, SearchReplaceRewriter> patternsInfo;
|
||||
private final Map<String, SearchReplaceRewriter> rewriterByPattern;
|
||||
|
||||
private CompositeRewriter(ClassNamed rewriteClass, List<SearchReplaceRewriter> rewriters) {
|
||||
super(rewriteClass, null, false);
|
||||
this.patternsInfo = rewriters.stream().collect(Collectors.toMap(rewriter -> rewriter.pattern, rewriter -> rewriter));
|
||||
this.rewriterByPattern = rewriters.stream().collect(Collectors.toMap(rewriter -> rewriter.pattern, rewriter -> rewriter));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +24,20 @@ public class CompositeRewriter extends SearchReplaceRewriter {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SearchReplaceRewriter getRewriterFor(String pattern) {
|
||||
return this.rewriterByPattern.get(pattern);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Set<String> getPatterns() {
|
||||
return this.rewriterByPattern.keySet();
|
||||
}
|
||||
|
||||
public Collection<SearchReplaceRewriter> getRewriters() {
|
||||
return this.rewriterByPattern.values();
|
||||
}
|
||||
|
||||
public static CompositeRewriter bind(SearchReplaceRewriter... rewriters) {
|
||||
return bind(Arrays.asList(rewriters));
|
||||
}
|
||||
|
@ -43,14 +56,4 @@ public class CompositeRewriter extends SearchReplaceRewriter {
|
|||
|
||||
return new CompositeRewriter(rewriteClass, rewriters);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void searchAndReplace(BufferedReader reader, StringBuilder content, Map<String, SearchReplaceRewriter> patternInfo) throws IOException {
|
||||
Preconditions.checkState(patternInfo.isEmpty());
|
||||
super.searchAndReplace(reader, content, this.patternsInfo);
|
||||
}
|
||||
|
||||
public Collection<SearchReplaceRewriter> getRewriters() {
|
||||
return this.patternsInfo.values();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,9 +18,7 @@ import java.io.IOException;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -58,25 +56,27 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
|
||||
protected void beginSearch() {}
|
||||
|
||||
private SearchReplaceRewriter foundRewriter;
|
||||
|
||||
private void searchAndReplace(BufferedReader reader, StringBuilder content) throws IOException {
|
||||
searchAndReplace(reader, content, this.pattern == null ? new HashMap<>() : Map.of(this.pattern, this)); // todo collect srt per pattern on bootstrap
|
||||
protected SearchReplaceRewriter getRewriterFor(String pattern) {
|
||||
return this;
|
||||
}
|
||||
|
||||
protected void searchAndReplace(BufferedReader reader, StringBuilder content, Map<String, SearchReplaceRewriter> patternInfo) throws IOException {
|
||||
Preconditions.checkState(!patternInfo.isEmpty());
|
||||
protected Set<String> getPatterns() {
|
||||
return Set.of(this.pattern);
|
||||
}
|
||||
|
||||
protected void searchAndReplace(BufferedReader reader, StringBuilder content) throws IOException {
|
||||
Set<String> patterns = this.getPatterns();
|
||||
Preconditions.checkState(!patterns.isEmpty());
|
||||
this.beginSearch();
|
||||
|
||||
Set<String> patterns = patternInfo.keySet();
|
||||
Set<String> foundPatterns = new HashSet<>();
|
||||
StringBuilder strippedContent = null;
|
||||
|
||||
final ImportCollector importCollector;
|
||||
String rootClassDeclaration = null;
|
||||
|
||||
if (this.rewriteClass.clazz() != null) {
|
||||
Class<?> rootClass = ClassHelper.getRootClass(this.rewriteClass.clazz());
|
||||
if (this.rewriteClass.knownClass() != null) {
|
||||
Class<?> rootClass = ClassHelper.getRootClass(this.rewriteClass.knownClass());
|
||||
importCollector = new ImportTypeCollector(rootClass);
|
||||
rootClassDeclaration = "%s %s".formatted(ClassHelper.getDeclaredType(rootClass), this.rewriteClass.rootClassSimpleName());
|
||||
} else {
|
||||
|
@ -84,6 +84,7 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
}
|
||||
|
||||
String indent = Formatting.incrementalIndent(INDENT_UNIT, this.rewriteClass);
|
||||
SearchReplaceRewriter foundRewriter = null;
|
||||
boolean inBody = false;
|
||||
int i = 0;
|
||||
while (true) {
|
||||
|
@ -104,30 +105,30 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
|
||||
Optional<String> endPattern = this.searchPattern(line, indent, PAPER_END_FORMAT, patterns);
|
||||
if (endPattern.isPresent()) {
|
||||
if (this.foundRewriter == null) {
|
||||
if (foundRewriter == null) {
|
||||
throw new IllegalStateException("Start generated comment missing for pattern " + endPattern.get() + " in class " + this.rewriteClass.simpleName() + " at line " + (i + 1));
|
||||
}
|
||||
if (this.foundRewriter.pattern.equals(endPattern.get())) {
|
||||
if (!this.foundRewriter.equalsSize) {
|
||||
if (foundRewriter.pattern.equals(endPattern.get())) {
|
||||
if (!foundRewriter.equalsSize) {
|
||||
appendGeneratedComment(content, indent);
|
||||
|
||||
this.foundRewriter.insert(new SearchMetadata(importCollector, indent, strippedContent.toString(), i), content);
|
||||
foundRewriter.insert(new SearchMetadata(importCollector, indent, strippedContent.toString(), i), content);
|
||||
strippedContent = null;
|
||||
}
|
||||
this.foundRewriter = null;
|
||||
foundRewriter = null;
|
||||
} else {
|
||||
throw new IllegalStateException("End generated comment doesn't match for pattern " + this.foundRewriter.pattern + " in " + this.rewriteClass.simpleName() + " at line " + (i + 1));
|
||||
throw new IllegalStateException("End generated comment doesn't match for pattern " + foundRewriter.pattern + " in " + this.rewriteClass.simpleName() + " at line " + (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
if (this.foundRewriter == null) {
|
||||
if (foundRewriter == null) {
|
||||
content.append(line);
|
||||
content.append('\n');
|
||||
} else {
|
||||
if (this.foundRewriter.equalsSize) {
|
||||
if (foundRewriter.equalsSize) {
|
||||
// there's no generated comment here since when the size is equals the replaced content doesn't depend on the game content
|
||||
// if it does that means the replaced content might not be equals during MC update because of adding/removed content
|
||||
this.foundRewriter.replaceLine(new SearchMetadata(importCollector, indent, line, i), content);
|
||||
foundRewriter.replaceLine(new SearchMetadata(importCollector, indent, line, i), content);
|
||||
} else {
|
||||
strippedContent.append(line);
|
||||
strippedContent.append('\n');
|
||||
|
@ -136,7 +137,7 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
|
||||
Optional<String> startPattern = this.searchPattern(line, null, PAPER_START_FORMAT, patterns);
|
||||
if (startPattern.isPresent()) {
|
||||
if (this.foundRewriter != null) {
|
||||
if (foundRewriter != null) {
|
||||
throw new IllegalStateException("Nested generated comments are not allowed for " + this.rewriteClass.simpleName() + " at line " + (i + 1));
|
||||
}
|
||||
int startPatternIndex = line.indexOf(GENERATED_COMMENT_FORMAT.formatted(PAPER_START_FORMAT, startPattern.get()));
|
||||
|
@ -145,17 +146,17 @@ public class SearchReplaceRewriter implements SourceRewriter {
|
|||
throw new IllegalStateException("Start generated comment is not properly indented at line " + (i + 1));
|
||||
}
|
||||
|
||||
this.foundRewriter = patternInfo.get(startPattern.get());
|
||||
foundPatterns.add(this.foundRewriter.pattern);
|
||||
if (!this.foundRewriter.equalsSize) {
|
||||
foundRewriter = this.getRewriterFor(startPattern.get());
|
||||
foundPatterns.add(foundRewriter.pattern);
|
||||
if (!foundRewriter.equalsSize) {
|
||||
strippedContent = new StringBuilder();
|
||||
}
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (this.foundRewriter != null) {
|
||||
throw new IllegalStateException("End generated comment " + this.foundRewriter.pattern + " missing for " + this.rewriteClass.simpleName());
|
||||
if (foundRewriter != null) {
|
||||
throw new IllegalStateException("End generated comment " + foundRewriter.pattern + " missing for " + this.rewriteClass.simpleName());
|
||||
}
|
||||
|
||||
Set<String> diff = Sets.difference(patterns, foundPatterns);
|
||||
|
|
|
@ -68,9 +68,9 @@ public class RegistryFieldRewriter<T, A> extends SearchReplaceRewriter {
|
|||
return;
|
||||
}
|
||||
|
||||
Preconditions.checkState(this.rewriteClass.clazz() != null, "This rewriter doesn't support server gen!");
|
||||
Preconditions.checkState(this.rewriteClass.knownClass() != null, "This rewriter can't check the integrity of the fetch method since it doesn't know the rewritten class!");
|
||||
try {
|
||||
this.rewriteClass.clazz().getDeclaredMethod(this.fetchMethod, String.class);
|
||||
this.rewriteClass.knownClass().getDeclaredMethod(this.fetchMethod, String.class);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class RegistryFieldRewriter<T, A> extends SearchReplaceRewriter {
|
|||
builder.append(this.rewriteClass.simpleName()).append(' ').append(this.rewriteFieldName(reference));
|
||||
builder.append(" = ");
|
||||
if (this.fetchMethod == null) {
|
||||
builder.append("%s.%s.get(%s.minecraft(%s))".formatted(org.bukkit.Registry.class.getSimpleName(), REGISTRY_FIELD_NAMES.get(this.rewriteClass.clazz()), NamespacedKey.class.getSimpleName(), quoted(pathKey)));
|
||||
builder.append("%s.%s.get(%s.minecraft(%s))".formatted(org.bukkit.Registry.class.getSimpleName(), REGISTRY_FIELD_NAMES.get(this.rewriteClass.knownClass()), NamespacedKey.class.getSimpleName(), quoted(pathKey)));
|
||||
} else {
|
||||
builder.append("%s(%s)".formatted(this.fetchMethod, quoted(pathKey)));
|
||||
}
|
||||
|
|
|
@ -4,11 +4,9 @@ import io.papermc.generator.Main;
|
|||
import io.papermc.generator.rewriter.SearchMetadata;
|
||||
import io.papermc.generator.rewriter.SearchReplaceRewriter;
|
||||
import io.papermc.generator.rewriter.utils.Annotations;
|
||||
import io.papermc.generator.rewriter.ClassNamed;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import io.papermc.generator.utils.TagRegistry;
|
||||
import net.minecraft.core.Registry;
|
||||
|
@ -27,27 +25,23 @@ import static io.papermc.generator.utils.TagRegistry.registry;
|
|||
|
||||
public class TagRewriter extends SearchReplaceRewriter {
|
||||
|
||||
private static final List<TagRegistry> TAG_REGISTRIES = List.of(
|
||||
private static final TagRegistry[] TAG_REGISTRIES = {
|
||||
registry("blocks", Material.class, Registries.BLOCK),
|
||||
registry("items", Material.class, Registries.ITEM),
|
||||
registry("fluids", Fluid.class, Registries.FLUID),
|
||||
registry("entity_types", EntityType.class, Registries.ENTITY_TYPE),
|
||||
registry("game_events", GameEvent.class, Registries.GAME_EVENT)
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
public TagRewriter(final Class<?> rewriteClass, final String pattern) {
|
||||
super(rewriteClass, pattern, false);
|
||||
}
|
||||
|
||||
public TagRewriter(final ClassNamed rewriteClass, final String pattern) {
|
||||
super(rewriteClass, pattern, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void insert(final SearchMetadata metadata, final StringBuilder builder) {
|
||||
for (int i = 0, len = TAG_REGISTRIES.size(); i < len; i++) {
|
||||
final TagRegistry tagRegistry = TAG_REGISTRIES.get(i);
|
||||
for (int i = 0, len = TAG_REGISTRIES.length; i < len; i++) {
|
||||
final TagRegistry tagRegistry = TAG_REGISTRIES[i];
|
||||
|
||||
final ResourceKey<? extends Registry<?>> registryKey = tagRegistry.registryKey();
|
||||
final Registry<?> registry = Main.REGISTRY_ACCESS.registryOrThrow(registryKey);
|
||||
|
|
|
@ -8,8 +8,7 @@ public final class Types {
|
|||
public static final String BLOCKDATA_IMPL_PACKAGE = BASE_PACKAGE + ".block.impl";
|
||||
|
||||
public static final ClassNamed CRAFT_BLOCKDATA = ClassNamed.of(BASE_PACKAGE + ".block.data", "CraftBlockData");
|
||||
|
||||
public static final ClassNamed CRAFT_BLOCKSTATES = ClassNamed.of(BASE_PACKAGE + ".block", "CraftBlockStates");
|
||||
|
||||
public static final ClassNamed CRAFT_BLOCK = ClassNamed.of(BASE_PACKAGE + ".block", "CraftBlock");
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import io.papermc.generator.rewriter.SearchMetadata;
|
|||
import io.papermc.generator.rewriter.SearchReplaceRewriter;
|
||||
import io.papermc.generator.rewriter.types.Types;
|
||||
import io.papermc.generator.utils.BlockStateMapping;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import java.util.Comparator;
|
||||
|
||||
public class CraftBlockDataMapping extends SearchReplaceRewriter {
|
||||
|
||||
|
@ -14,7 +14,7 @@ public class CraftBlockDataMapping extends SearchReplaceRewriter {
|
|||
|
||||
@Override
|
||||
protected void insert(final SearchMetadata metadata, final StringBuilder builder) {
|
||||
BlockStateMapping.MAPPING.entrySet().stream().sorted(Formatting.alphabeticKeyOrder(entry -> entry.getKey().getCanonicalName())).forEach(entry -> {
|
||||
BlockStateMapping.MAPPING.entrySet().stream().sorted(Comparator.comparing(entry -> entry.getKey().getCanonicalName())).forEach(entry -> {
|
||||
builder.append(metadata.indent());
|
||||
builder.append("register(%s.class, %s.%s::new);".formatted(entry.getKey().getCanonicalName(), Types.BLOCKDATA_IMPL_PACKAGE, entry.getValue().impl()));
|
||||
builder.append('\n');
|
||||
|
|
|
@ -9,6 +9,7 @@ import java.util.IdentityHashMap;
|
|||
import java.util.Map;
|
||||
import io.papermc.generator.Main;
|
||||
import io.papermc.generator.rewriter.types.EnumRegistryRewriter;
|
||||
import io.papermc.generator.utils.ClassHelper;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
|
@ -91,10 +92,7 @@ public class StatisticRewriter {
|
|||
int mod = field.getModifiers();
|
||||
if (Modifier.isPublic(mod) & Modifier.isStatic(mod) & Modifier.isFinal(mod)) {
|
||||
java.lang.reflect.Type genericType = ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0];
|
||||
if (genericType instanceof ParameterizedType complexType) {
|
||||
genericType = complexType.getRawType(); // needed for generic in a generic like entity type
|
||||
}
|
||||
map.put((StatType<?>) field.get(null), (Class<?>) genericType);
|
||||
map.put((StatType<?>) field.get(null), ClassHelper.eraseType(genericType));
|
||||
}
|
||||
}
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
|
|
|
@ -1,18 +1,17 @@
|
|||
package io.papermc.generator.types.enumgen;
|
||||
package io.papermc.generator.types;
|
||||
|
||||
import com.squareup.javapoet.TypeSpec;
|
||||
import io.papermc.generator.types.SimpleGenerator;
|
||||
import io.papermc.generator.utils.Annotations;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class EnumGenerator<T extends Enum<T>> extends SimpleGenerator {
|
||||
public class SimpleEnumGenerator<T extends Enum<T>> extends SimpleGenerator {
|
||||
|
||||
private final Class<T> enumClass;
|
||||
|
||||
public EnumGenerator(final Class<T> enumClass, final String pkg) {
|
||||
public SimpleEnumGenerator(final Class<T> enumClass, final String pkg) {
|
||||
super(enumClass.getSimpleName(), pkg);
|
||||
this.enumClass = enumClass;
|
||||
}
|
|
@ -21,7 +21,6 @@ import io.papermc.generator.utils.BlockStateMapping;
|
|||
import io.papermc.generator.utils.CommonVariable;
|
||||
import io.papermc.generator.utils.NamingManager;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.BrewingStandBlock;
|
||||
import net.minecraft.world.level.block.ChiseledBookShelfBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
|
||||
|
@ -53,12 +52,14 @@ public class CraftBlockDataGenerator<T extends BlockData> extends StructuredGene
|
|||
this.blockData = blockData;
|
||||
}
|
||||
|
||||
// default keywords: get/set
|
||||
// for single boolean property: get = is
|
||||
// for indexed boolean property: get = has
|
||||
private static final Map<Property<?>, NamingManager.AccessKeyword> FLUENT_KEYWORD = ImmutableMap.<Property<?>, NamingManager.AccessKeyword>builder()
|
||||
.put(BlockStateProperties.ATTACH_FACE, keywordGetSet("getAttached", "setAttached")) // todo remove this once switch methods are gone
|
||||
.put(BlockStateProperties.EYE, keywordGet("has"))
|
||||
.put(BlockStateProperties.BERRIES, keywordGet("has")) // spigot method rename
|
||||
// data holder keywords is only needed for the first property they hold
|
||||
.put(BrewingStandBlock.HAS_BOTTLE[0], keywordGet("has"))
|
||||
.put(ChiseledBookShelfBlock.SLOT_OCCUPIED_PROPERTIES.get(0), keywordGet("is"))
|
||||
.build();
|
||||
|
||||
|
@ -90,7 +91,7 @@ public class CraftBlockDataGenerator<T extends BlockData> extends StructuredGene
|
|||
TypeSpec.Builder typeBuilder = TypeSpec.classBuilder(this.className)
|
||||
.addModifiers(PUBLIC)
|
||||
.addAnnotation(Annotations.GENERATED_FROM)
|
||||
.addAnnotation(Annotations.suppressWarnings("unused"))
|
||||
.addAnnotation(Annotations.suppressWarnings("unused")) // todo remove
|
||||
.superclass(Types.CRAFT_BLOCKDATA)
|
||||
.addSuperinterface(this.baseClass);
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class EnumPropertyWriter<T extends Enum<T> & StringRepresentable> extends
|
|||
Class<?> apiClass = this.property.getValueClass();
|
||||
apiClass = BlockStateMapping.ENUM_BRIDGE.get(apiClass);
|
||||
if (apiClass == null) {
|
||||
throw new IllegalStateException("Unknown type for " + this.property);
|
||||
throw new IllegalStateException("Unknown enum type for " + this.property);
|
||||
}
|
||||
return apiClass;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public class IntegerPropertyWriter extends PropertyWriter<Integer> {
|
|||
|
||||
IntegerProperty property = (IntegerProperty) this.property;
|
||||
|
||||
if (property.min != 0 || this.property.getName().equals(BlockStateProperties.LEVEL.getName())) { // special case (levelled)
|
||||
if (property.min != 0 || property.getName().equals(BlockStateProperties.LEVEL.getName())) { // special case (levelled: composter)
|
||||
MethodSpec.Builder methodBuilder = generator.createMethod(naming.getterName(name -> true).pre("Minimum").concat());
|
||||
methodBuilder.addStatement("return $N.min", field);
|
||||
methodBuilder.returns(this.getApiType());
|
||||
|
|
|
@ -23,19 +23,19 @@ public class ArrayAppender implements DataAppender {
|
|||
@Override
|
||||
public void addExtras(final TypeSpec.Builder builder, final FieldSpec field, final ParameterSpec indexParameter, final ConverterBase childConverter, final StructuredGenerator<?> generator, final NamingManager naming) {
|
||||
if (childConverter.getApiType() == Boolean.TYPE) {
|
||||
String collectFieldName = naming.getVariableNameWrapper().post("s").concat();
|
||||
String collectVarName = naming.getVariableNameWrapper().post("s").concat();
|
||||
MethodSpec.Builder methodBuilder = generator.createMethod(naming.getMethodNameWrapper().post("s").concat());
|
||||
methodBuilder.addStatement("$T $L = $T.builder()", ParameterizedTypeName.get(ImmutableSet.Builder.class, Integer.class), collectFieldName, ImmutableSet.class);
|
||||
methodBuilder.addStatement("$T $L = $T.builder()", ParameterizedTypeName.get(ImmutableSet.Builder.class, Integer.class), collectVarName, ImmutableSet.class);
|
||||
methodBuilder.beginControlFlow("for (int $1L = 0, len = $2N.length; $1L < len; $1L++)", CommonVariable.INDEX, field);
|
||||
{
|
||||
methodBuilder.beginControlFlow("if (" + childConverter.rawGetExprent().formatted("$N[$N]") + ")", field, indexParameter);
|
||||
{
|
||||
methodBuilder.addStatement("$L.add($L)", collectFieldName, CommonVariable.INDEX);
|
||||
methodBuilder.addStatement("$L.add($L)", collectVarName, CommonVariable.INDEX);
|
||||
}
|
||||
methodBuilder.endControlFlow();
|
||||
}
|
||||
methodBuilder.endControlFlow();
|
||||
methodBuilder.addStatement("return $L.build()", collectFieldName);
|
||||
methodBuilder.addStatement("return $L.build()", collectVarName);
|
||||
methodBuilder.returns(ParameterizedTypeName.get(Set.class, Integer.class));
|
||||
|
||||
builder.addMethod(methodBuilder.build());
|
||||
|
|
|
@ -30,19 +30,19 @@ public class ListAppender implements DataAppender {
|
|||
NamingManager.NameWrapper methodName = NamingManager.NameWrapper.wrap("get", METHOD_BASE_RENAMES.getOrDefault(naming.getMethodBaseName(), naming.getMethodBaseName()));
|
||||
|
||||
if (childConverter.getApiType() == Boolean.TYPE) {
|
||||
String collectFieldName = naming.getVariableNameWrapper().post("s").concat();
|
||||
String collectVarName = naming.getVariableNameWrapper().post("s").concat();
|
||||
MethodSpec.Builder methodBuilder = generator.createMethod(methodName.post("s").concat());
|
||||
methodBuilder.addStatement("$T $L = $T.builder()", ParameterizedTypeName.get(ImmutableSet.Builder.class, Integer.class), collectFieldName, ImmutableSet.class);
|
||||
methodBuilder.addStatement("$T $L = $T.builder()", ParameterizedTypeName.get(ImmutableSet.Builder.class, Integer.class), collectVarName, ImmutableSet.class);
|
||||
methodBuilder.beginControlFlow("for (int $1L = 0, size = $2N.size(); $1L < size; $1L++)", CommonVariable.INDEX, field);
|
||||
{
|
||||
methodBuilder.beginControlFlow("if (" + childConverter.rawGetExprent().formatted("$N.get($N)") + ")", field, indexParameter);
|
||||
{
|
||||
methodBuilder.addStatement("$L.add($L)", collectFieldName, CommonVariable.INDEX);
|
||||
methodBuilder.addStatement("$L.add($L)", collectVarName, CommonVariable.INDEX);
|
||||
}
|
||||
methodBuilder.endControlFlow();
|
||||
}
|
||||
methodBuilder.endControlFlow();
|
||||
methodBuilder.addStatement("return $L.build()", collectFieldName);
|
||||
methodBuilder.addStatement("return $L.build()", collectVarName);
|
||||
methodBuilder.returns(ParameterizedTypeName.get(Set.class, Integer.class));
|
||||
|
||||
builder.addMethod(methodBuilder.build());
|
||||
|
|
|
@ -27,19 +27,19 @@ public class MapAppender implements DataAppender {
|
|||
@Override
|
||||
public void addExtras(final TypeSpec.Builder builder, final FieldSpec field, final ParameterSpec indexParameter, final ConverterBase childConverter, final StructuredGenerator<?> generator, final NamingManager naming) {
|
||||
if (childConverter.getApiType() == Boolean.TYPE) {
|
||||
String collectFieldName = naming.getVariableNameWrapper().post("s").concat();
|
||||
String collectVarName = naming.getVariableNameWrapper().post("s").concat();
|
||||
MethodSpec.Builder methodBuilder = generator.createMethod(naming.getMethodNameWrapper().post("s").concat());
|
||||
methodBuilder.addStatement("$T $L = $T.builder()", ParameterizedTypeName.get(ClassName.get(ImmutableSet.Builder.class), indexParameter.type), collectFieldName, ImmutableSet.class);
|
||||
methodBuilder.addStatement("$T $L = $T.builder()", ParameterizedTypeName.get(ClassName.get(ImmutableSet.Builder.class), indexParameter.type), collectVarName, ImmutableSet.class);
|
||||
methodBuilder.beginControlFlow("for ($T $N : $N.entrySet())", ParameterizedTypeName.get(ClassName.get(Map.Entry.class), indexParameter.type, ClassName.get(BooleanProperty.class)), CommonVariable.MAP_ENTRY, field);
|
||||
{
|
||||
methodBuilder.beginControlFlow("if (" + childConverter.rawGetExprent().formatted("$L.getValue()") + ")", CommonVariable.MAP_ENTRY);
|
||||
{
|
||||
methodBuilder.addStatement("$L.add($N.getKey())", collectFieldName, CommonVariable.MAP_ENTRY);
|
||||
methodBuilder.addStatement("$L.add($N.getKey())", collectVarName, CommonVariable.MAP_ENTRY);
|
||||
}
|
||||
methodBuilder.endControlFlow();
|
||||
}
|
||||
methodBuilder.endControlFlow();
|
||||
methodBuilder.addStatement("return $L.build()", collectFieldName);
|
||||
methodBuilder.addStatement("return $L.build()", collectVarName);
|
||||
methodBuilder.returns(ParameterizedTypeName.get(ClassName.get(Set.class), indexParameter.type));
|
||||
|
||||
builder.addMethod(methodBuilder.build());
|
||||
|
|
|
@ -14,11 +14,13 @@ import io.github.classgraph.ClassGraph;
|
|||
import io.github.classgraph.ScanResult;
|
||||
import io.papermc.generator.types.SimpleGenerator;
|
||||
import io.papermc.generator.utils.Annotations;
|
||||
import io.papermc.generator.utils.ClassHelper;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import io.papermc.generator.utils.Javadocs;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import net.minecraft.world.entity.ai.goal.Goal;
|
||||
import net.minecraft.world.entity.ai.goal.GoalSelector;
|
||||
import net.minecraft.world.entity.ai.goal.WrappedGoal;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
|
@ -69,92 +71,92 @@ public class MobGoalGenerator extends SimpleGenerator {
|
|||
|
||||
private static final String CLASS_HEADER = Javadocs.getVersionDependentClassHeader("Mob Goals");
|
||||
|
||||
private static final DeprecatedEntry[] DEPRECATED_ENTRIES = {
|
||||
//<editor-fold defaultstate="collapsed" desc="legacy entries">
|
||||
new DeprecatedEntry(Vindicator.class, "vindicator_melee_attack", null, "1.20.2"),
|
||||
new DeprecatedEntry(Ravager.class, "ravager_melee_attack", null, "1.20.2"),
|
||||
new DeprecatedEntry(Rabbit.class, "evil_rabbit_attack", null, "1.20.2"),
|
||||
new DeprecatedEntry(PigZombie.class, "anger", "1.21", "1.16"),
|
||||
new DeprecatedEntry(PigZombie.class, "anger_other", "1.21", "1.16"),
|
||||
new DeprecatedEntry(Blaze.class, "blaze_fireball", "1.21", null),
|
||||
new DeprecatedEntry(Cat.class, "tempt_chance", "1.21", null),
|
||||
new DeprecatedEntry(Dolphin.class, "dolphin_play_with_items", "1.21", null),
|
||||
new DeprecatedEntry(Drowned.class, "drowned_goto_beach", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "drowned_goto_water", "1.21", null),
|
||||
new DeprecatedEntry(Enderman.class, "enderman_pickup_block", "1.21", null),
|
||||
new DeprecatedEntry(Enderman.class, "enderman_place_block", "1.21", null),
|
||||
new DeprecatedEntry(Enderman.class, "player_who_looked_at_target", "1.21", null),
|
||||
new DeprecatedEntry(Evoker.class, "evoker_cast_spell", "1.21", null),
|
||||
new DeprecatedEntry(Fox.class, "fox_defend_trusted", "1.21", null),
|
||||
new DeprecatedEntry(Fox.class, "fox_faceplant", "1.21", null),
|
||||
new DeprecatedEntry(Fox.class, "fox_perch_and_search", "1.21", null),
|
||||
new DeprecatedEntry(Fox.class, "fox_sleep", "1.21", null),
|
||||
new DeprecatedEntry(Fox.class, "fox_seek_shelter", "1.21", null),
|
||||
new DeprecatedEntry(Fox.class, "fox_stalk_prey", "1.21", null),
|
||||
new DeprecatedEntry(Ghast.class, "ghast_attack_target", "1.21", null),
|
||||
new DeprecatedEntry(Ghast.class, "ghast_idle_move", "1.21", null),
|
||||
new DeprecatedEntry(Ghast.class, "ghast_move_towards_target", "1.21", null),
|
||||
new DeprecatedEntry(Spellcaster.class, "spellcaster_cast_spell", "1.21", null),
|
||||
new DeprecatedEntry(TraderLlama.class, "llamatrader_defended_wandering_trader", "1.21", null),
|
||||
new DeprecatedEntry(Panda.class, "panda_hurt_by_target", "1.21", null),
|
||||
new DeprecatedEntry(PolarBear.class, "polarbear_attack_players", "1.21", null),
|
||||
new DeprecatedEntry(PolarBear.class, "polarbear_hurt_by", "1.21", null),
|
||||
new DeprecatedEntry(PolarBear.class, "polarbear_melee", "1.21", null),
|
||||
new DeprecatedEntry(PolarBear.class, "polarbear_panic", "1.21", null),
|
||||
new DeprecatedEntry(Rabbit.class, "eat_carrots", "1.21", null),
|
||||
new DeprecatedEntry(Rabbit.class, "killer_rabbit_melee_attack", "1.21", null),
|
||||
new DeprecatedEntry(Rabbit.class, "rabbit_avoid_target", "1.21", null),
|
||||
new DeprecatedEntry(Raider.class, "raider_hold_ground", "1.21", null),
|
||||
new DeprecatedEntry(Raider.class, "raider_obtain_banner", "1.21", null),
|
||||
new DeprecatedEntry(Shulker.class, "shulker_defense", "1.21", null),
|
||||
new DeprecatedEntry(Shulker.class, "shulker_nearest", "1.21", null),
|
||||
new DeprecatedEntry(Silverfish.class, "silverfish_hide_in_block", "1.21", null),
|
||||
new DeprecatedEntry(Silverfish.class, "silverfish_wake_others", "1.21", null),
|
||||
new DeprecatedEntry(Slime.class, "slime_idle", "1.21", null),
|
||||
new DeprecatedEntry(Slime.class, "slime_nearest_player", "1.21", null),
|
||||
new DeprecatedEntry(Slime.class, "slime_random_jump", "1.21", null),
|
||||
new DeprecatedEntry(Spider.class, "spider_melee_attack", "1.21", null),
|
||||
new DeprecatedEntry(Spider.class, "spider_nearest_attackable_target", "1.21", null),
|
||||
new DeprecatedEntry(Squid.class, "squid", "1.21", null),
|
||||
new DeprecatedEntry(Turtle.class, "turtle_goto_water", "1.21", null),
|
||||
new DeprecatedEntry(Turtle.class, "turtle_tempt", "1.21", null),
|
||||
new DeprecatedEntry(Vex.class, "vex_copy_target_of_owner", "1.21", null),
|
||||
new DeprecatedEntry(WanderingTrader.class, "villagertrader_wander_to_position", "1.21", null),
|
||||
new DeprecatedEntry(RangedEntity.class, "arrow_attack", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "avoid_target", "1.21", null),
|
||||
new DeprecatedEntry(Monster.class, "bow_shoot", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "breath", "1.21", null),
|
||||
new DeprecatedEntry(Cat.class, "cat_sit_on_bed", "1.21", null),
|
||||
new DeprecatedEntry(Monster.class, "crossbow_attack", "1.21", null),
|
||||
new DeprecatedEntry(Mob.class, "door_open", "1.21", null),
|
||||
new DeprecatedEntry(Mob.class, "eat_tile", "1.21", null),
|
||||
new DeprecatedEntry(Fish.class, "fish_school", "1.21", null),
|
||||
new DeprecatedEntry(Mob.class, "follow_entity", "1.21", null),
|
||||
new DeprecatedEntry(SkeletonHorse.class, "horse_trap", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "hurt_by_target", "1.21", null),
|
||||
new DeprecatedEntry(Cat.class, "jump_on_block", "1.21", null),
|
||||
new DeprecatedEntry(Mob.class, "leap_at_target", "1.21", null),
|
||||
new DeprecatedEntry(Llama.class, "llama_follow", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "move_towards_target", "1.21", null),
|
||||
new DeprecatedEntry(Mob.class, "nearest_attackable_target", "1.21", null),
|
||||
new DeprecatedEntry(Raider.class, "nearest_attackable_target_witch", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "nearest_village", "1.21", null),
|
||||
new DeprecatedEntry(Tameable.class, "owner_hurt_by_target", "1.21", null),
|
||||
new DeprecatedEntry(Tameable.class, "owner_hurt_target", "1.21", null),
|
||||
new DeprecatedEntry(Parrot.class, "perch", "1.21", null),
|
||||
new DeprecatedEntry(Raider.class, "raid", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "random_fly", "1.21", null),
|
||||
new DeprecatedEntry(Mob.class, "random_lookaround", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "random_stroll_land", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "random_swim", "1.21", null),
|
||||
new DeprecatedEntry(Tameable.class, "random_target_non_tamed", "1.21", null),
|
||||
new DeprecatedEntry(Tameable.class, "sit", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "stroll_village", "1.21", null),
|
||||
new DeprecatedEntry(AbstractHorse.class, "tame", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "water", "1.21", null),
|
||||
new DeprecatedEntry(Dolphin.class, "water_jump", "1.21", null),
|
||||
new DeprecatedEntry(Creature.class, "stroll_village_golem", "1.21", null),
|
||||
new DeprecatedEntry(Mob.class, "universal_anger_reset", "1.21", null)
|
||||
private static final DeprecatedGoal[] DEPRECATED_GOALS = {
|
||||
//<editor-fold defaultstate="collapsed" desc="legacy goals">
|
||||
new DeprecatedGoal(Vindicator.class, "vindicator_melee_attack", null, "1.20.2"),
|
||||
new DeprecatedGoal(Ravager.class, "ravager_melee_attack", null, "1.20.2"),
|
||||
new DeprecatedGoal(Rabbit.class, "evil_rabbit_attack", null, "1.20.2"),
|
||||
new DeprecatedGoal(PigZombie.class, "anger", "1.21", "1.16"),
|
||||
new DeprecatedGoal(PigZombie.class, "anger_other", "1.21", "1.16"),
|
||||
new DeprecatedGoal(Blaze.class, "blaze_fireball", "1.21", null),
|
||||
new DeprecatedGoal(Cat.class, "tempt_chance", "1.21", null),
|
||||
new DeprecatedGoal(Dolphin.class, "dolphin_play_with_items", "1.21", null),
|
||||
new DeprecatedGoal(Drowned.class, "drowned_goto_beach", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "drowned_goto_water", "1.21", null),
|
||||
new DeprecatedGoal(Enderman.class, "enderman_pickup_block", "1.21", null),
|
||||
new DeprecatedGoal(Enderman.class, "enderman_place_block", "1.21", null),
|
||||
new DeprecatedGoal(Enderman.class, "player_who_looked_at_target", "1.21", null),
|
||||
new DeprecatedGoal(Evoker.class, "evoker_cast_spell", "1.21", null),
|
||||
new DeprecatedGoal(Fox.class, "fox_defend_trusted", "1.21", null),
|
||||
new DeprecatedGoal(Fox.class, "fox_faceplant", "1.21", null),
|
||||
new DeprecatedGoal(Fox.class, "fox_perch_and_search", "1.21", null),
|
||||
new DeprecatedGoal(Fox.class, "fox_sleep", "1.21", null),
|
||||
new DeprecatedGoal(Fox.class, "fox_seek_shelter", "1.21", null),
|
||||
new DeprecatedGoal(Fox.class, "fox_stalk_prey", "1.21", null),
|
||||
new DeprecatedGoal(Ghast.class, "ghast_attack_target", "1.21", null),
|
||||
new DeprecatedGoal(Ghast.class, "ghast_idle_move", "1.21", null),
|
||||
new DeprecatedGoal(Ghast.class, "ghast_move_towards_target", "1.21", null),
|
||||
new DeprecatedGoal(Spellcaster.class, "spellcaster_cast_spell", "1.21", null),
|
||||
new DeprecatedGoal(TraderLlama.class, "llamatrader_defended_wandering_trader", "1.21", null),
|
||||
new DeprecatedGoal(Panda.class, "panda_hurt_by_target", "1.21", null),
|
||||
new DeprecatedGoal(PolarBear.class, "polarbear_attack_players", "1.21", null),
|
||||
new DeprecatedGoal(PolarBear.class, "polarbear_hurt_by", "1.21", null),
|
||||
new DeprecatedGoal(PolarBear.class, "polarbear_melee", "1.21", null),
|
||||
new DeprecatedGoal(PolarBear.class, "polarbear_panic", "1.21", null),
|
||||
new DeprecatedGoal(Rabbit.class, "eat_carrots", "1.21", null),
|
||||
new DeprecatedGoal(Rabbit.class, "killer_rabbit_melee_attack", "1.21", null),
|
||||
new DeprecatedGoal(Rabbit.class, "rabbit_avoid_target", "1.21", null),
|
||||
new DeprecatedGoal(Raider.class, "raider_hold_ground", "1.21", null),
|
||||
new DeprecatedGoal(Raider.class, "raider_obtain_banner", "1.21", null),
|
||||
new DeprecatedGoal(Shulker.class, "shulker_defense", "1.21", null),
|
||||
new DeprecatedGoal(Shulker.class, "shulker_nearest", "1.21", null),
|
||||
new DeprecatedGoal(Silverfish.class, "silverfish_hide_in_block", "1.21", null),
|
||||
new DeprecatedGoal(Silverfish.class, "silverfish_wake_others", "1.21", null),
|
||||
new DeprecatedGoal(Slime.class, "slime_idle", "1.21", null),
|
||||
new DeprecatedGoal(Slime.class, "slime_nearest_player", "1.21", null),
|
||||
new DeprecatedGoal(Slime.class, "slime_random_jump", "1.21", null),
|
||||
new DeprecatedGoal(Spider.class, "spider_melee_attack", "1.21", null),
|
||||
new DeprecatedGoal(Spider.class, "spider_nearest_attackable_target", "1.21", null),
|
||||
new DeprecatedGoal(Squid.class, "squid", "1.21", null),
|
||||
new DeprecatedGoal(Turtle.class, "turtle_goto_water", "1.21", null),
|
||||
new DeprecatedGoal(Turtle.class, "turtle_tempt", "1.21", null),
|
||||
new DeprecatedGoal(Vex.class, "vex_copy_target_of_owner", "1.21", null),
|
||||
new DeprecatedGoal(WanderingTrader.class, "villagertrader_wander_to_position", "1.21", null),
|
||||
new DeprecatedGoal(RangedEntity.class, "arrow_attack", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "avoid_target", "1.21", null),
|
||||
new DeprecatedGoal(Monster.class, "bow_shoot", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "breath", "1.21", null),
|
||||
new DeprecatedGoal(Cat.class, "cat_sit_on_bed", "1.21", null),
|
||||
new DeprecatedGoal(Monster.class, "crossbow_attack", "1.21", null),
|
||||
new DeprecatedGoal(Mob.class, "door_open", "1.21", null),
|
||||
new DeprecatedGoal(Mob.class, "eat_tile", "1.21", null),
|
||||
new DeprecatedGoal(Fish.class, "fish_school", "1.21", null),
|
||||
new DeprecatedGoal(Mob.class, "follow_entity", "1.21", null),
|
||||
new DeprecatedGoal(SkeletonHorse.class, "horse_trap", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "hurt_by_target", "1.21", null),
|
||||
new DeprecatedGoal(Cat.class, "jump_on_block", "1.21", null),
|
||||
new DeprecatedGoal(Mob.class, "leap_at_target", "1.21", null),
|
||||
new DeprecatedGoal(Llama.class, "llama_follow", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "move_towards_target", "1.21", null),
|
||||
new DeprecatedGoal(Mob.class, "nearest_attackable_target", "1.21", null),
|
||||
new DeprecatedGoal(Raider.class, "nearest_attackable_target_witch", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "nearest_village", "1.21", null),
|
||||
new DeprecatedGoal(Tameable.class, "owner_hurt_by_target", "1.21", null),
|
||||
new DeprecatedGoal(Tameable.class, "owner_hurt_target", "1.21", null),
|
||||
new DeprecatedGoal(Parrot.class, "perch", "1.21", null),
|
||||
new DeprecatedGoal(Raider.class, "raid", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "random_fly", "1.21", null),
|
||||
new DeprecatedGoal(Mob.class, "random_lookaround", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "random_stroll_land", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "random_swim", "1.21", null),
|
||||
new DeprecatedGoal(Tameable.class, "random_target_non_tamed", "1.21", null),
|
||||
new DeprecatedGoal(Tameable.class, "sit", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "stroll_village", "1.21", null),
|
||||
new DeprecatedGoal(AbstractHorse.class, "tame", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "water", "1.21", null),
|
||||
new DeprecatedGoal(Dolphin.class, "water_jump", "1.21", null),
|
||||
new DeprecatedGoal(Creature.class, "stroll_village_golem", "1.21", null),
|
||||
new DeprecatedGoal(Mob.class, "universal_anger_reset", "1.21", null)
|
||||
//</editor-fold>
|
||||
};
|
||||
|
||||
|
@ -194,9 +196,9 @@ public class MobGoalGenerator extends SimpleGenerator {
|
|||
|
||||
List<GoalKey<Mob>> vanillaNames = classes.stream()
|
||||
.filter(clazz -> !java.lang.reflect.Modifier.isAbstract(clazz.getModifiers()))
|
||||
.filter(clazz -> !clazz.isAnonymousClass() || ClassHelper.getRootClass(clazz) != GoalSelector.class)
|
||||
.filter(clazz -> !WrappedGoal.class.equals(clazz)) // TODO - properly fix
|
||||
.map(goalClass -> MobGoalNames.getKey(goalClass.getName(), goalClass))
|
||||
.filter((key) -> !MobGoalNames.isIgnored(key.getNamespacedKey().getKey()))
|
||||
.map(MobGoalNames::getKey)
|
||||
.sorted(Comparator.<GoalKey<?>, String>comparing(o -> o.getEntityClass().getSimpleName())
|
||||
.thenComparing(vanillaGoalKey -> vanillaGoalKey.getNamespacedKey().getKey())
|
||||
)
|
||||
|
@ -204,30 +206,28 @@ public class MobGoalGenerator extends SimpleGenerator {
|
|||
|
||||
|
||||
for (final GoalKey<?> goalKey : vanillaNames) {
|
||||
TypeName typedKey = ParameterizedTypeName.get(GoalKey.class, goalKey.getEntityClass());
|
||||
NamespacedKey key = goalKey.getNamespacedKey();
|
||||
|
||||
String keyPath = key.getKey();
|
||||
String keyPath = goalKey.getNamespacedKey().getKey();
|
||||
String fieldName = Formatting.formatKeyAsField(keyPath);
|
||||
|
||||
TypeName typedKey = ParameterizedTypeName.get(GoalKey.class, goalKey.getEntityClass());
|
||||
FieldSpec.Builder fieldBuilder = FieldSpec.builder(typedKey, fieldName, PUBLIC, STATIC, FINAL)
|
||||
.initializer("$N($S, $T.class)", createMethod.build(), keyPath, goalKey.getEntityClass());
|
||||
typeBuilder.addField(fieldBuilder.build());
|
||||
}
|
||||
|
||||
for (final DeprecatedEntry value : DEPRECATED_ENTRIES) {
|
||||
TypeName typedKey = ParameterizedTypeName.get(GoalKey.class, value.entity);
|
||||
String keyPath = value.entryName;
|
||||
for (final DeprecatedGoal deprecatedGoal : DEPRECATED_GOALS) {
|
||||
TypeName typedKey = ParameterizedTypeName.get(GoalKey.class, deprecatedGoal.goalClass());
|
||||
|
||||
String fieldName = Formatting.formatKeyAsField(keyPath);
|
||||
String fieldName = Formatting.formatKeyAsField(deprecatedGoal.path());
|
||||
FieldSpec.Builder fieldBuilder = FieldSpec.builder(typedKey, fieldName, PUBLIC, STATIC, FINAL)
|
||||
.addAnnotation(Annotations.deprecatedVersioned(value.removedVersion, value.removalVersion != null))
|
||||
.initializer("$N($S, $T.class)", createMethod.build(), keyPath, value.entity);
|
||||
.addAnnotation(Annotations.deprecatedVersioned(deprecatedGoal.removedVersion(), deprecatedGoal.removalVersion() != null))
|
||||
.initializer("$N($S, $T.class)", createMethod.build(), deprecatedGoal.path(), deprecatedGoal.goalClass());
|
||||
|
||||
if (value.removedVersion != null) {
|
||||
fieldBuilder.addJavadoc("Removed in $L", value.removedVersion);
|
||||
if (deprecatedGoal.removedVersion() != null) {
|
||||
fieldBuilder.addJavadoc("Removed in $L", deprecatedGoal.removedVersion());
|
||||
}
|
||||
if (value.removalVersion != null) {
|
||||
fieldBuilder.addAnnotation(Annotations.scheduledRemoval(value.removalVersion));
|
||||
if (deprecatedGoal.removalVersion() != null) {
|
||||
fieldBuilder.addAnnotation(Annotations.scheduledRemoval(deprecatedGoal.removalVersion()));
|
||||
}
|
||||
|
||||
typeBuilder.addField(fieldBuilder.build());
|
||||
|
@ -236,8 +236,7 @@ public class MobGoalGenerator extends SimpleGenerator {
|
|||
return typeBuilder.addMethod(createMethod.build()).build();
|
||||
}
|
||||
|
||||
record DeprecatedEntry(Class<? extends Mob> entity, String entryName, @Nullable String removalVersion,
|
||||
@Nullable String removedVersion) {
|
||||
record DeprecatedGoal(Class<? extends Mob> goalClass, String path, @Nullable String removalVersion,
|
||||
@Nullable String removedVersion) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,15 @@ package io.papermc.generator.types.goal;
|
|||
|
||||
import com.destroystokyo.paper.entity.RangedEntity;
|
||||
import com.destroystokyo.paper.entity.ai.GoalKey;
|
||||
import com.google.common.base.CaseFormat;
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import io.papermc.generator.utils.Formatting;
|
||||
import net.minecraft.world.entity.FlyingMob;
|
||||
import net.minecraft.world.entity.PathfinderMob;
|
||||
import net.minecraft.world.entity.TamableAnimal;
|
||||
import net.minecraft.world.entity.ai.goal.Goal;
|
||||
import net.minecraft.world.entity.ai.goal.WrappedGoal;
|
||||
import net.minecraft.world.entity.ambient.AmbientCreature;
|
||||
import net.minecraft.world.entity.animal.AbstractFish;
|
||||
import net.minecraft.world.entity.animal.AbstractGolem;
|
||||
|
@ -26,6 +29,7 @@ import net.minecraft.world.entity.monster.RangedAttackMob;
|
|||
import net.minecraft.world.entity.monster.SpellcasterIllager;
|
||||
import net.minecraft.world.entity.monster.ZombifiedPiglin;
|
||||
import net.minecraft.world.entity.monster.piglin.AbstractPiglin;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.AbstractHorse;
|
||||
import org.bukkit.entity.AbstractSkeleton;
|
||||
|
@ -119,17 +123,14 @@ import org.bukkit.entity.ZombieVillager;
|
|||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class MobGoalNames {
|
||||
public final class MobGoalNames {
|
||||
|
||||
private static final Map<Class<? extends Goal>, Class<? extends Mob>> entityClassCache = new HashMap<>();
|
||||
public static final Map<Class<? extends net.minecraft.world.entity.Mob>, Class<? extends Mob>> bukkitMap = new HashMap<>();
|
||||
|
||||
|
||||
static {
|
||||
static { // todo move serverside? via CraftEntityTypes
|
||||
//<editor-fold defaultstate="collapsed" desc="bukkitMap Entities">
|
||||
bukkitMap.put(net.minecraft.world.entity.Mob.class, Mob.class);
|
||||
bukkitMap.put(net.minecraft.world.entity.AgeableMob.class, Ageable.class);
|
||||
|
@ -239,77 +240,54 @@ public class MobGoalNames {
|
|||
}
|
||||
|
||||
private static final BiMap<String, String> deobfuscationMap = HashBiMap.create();
|
||||
private static final Set<String> ignored = new HashSet<>();
|
||||
|
||||
static {
|
||||
deobfuscationMap.put("abstract_skeleton_1", "abstract_skeleton_melee");
|
||||
|
||||
ignored.add("goal_selector_1");
|
||||
ignored.add("goal_selector_2");
|
||||
ignored.add("selector_1");
|
||||
ignored.add("selector_2");
|
||||
ignored.add("wrapped");
|
||||
}
|
||||
|
||||
public static String getUsableName(String name) {
|
||||
final String original = name;
|
||||
name = name.substring(name.lastIndexOf('.') + 1);
|
||||
boolean flag = false;
|
||||
// inner classes
|
||||
if (name.contains("$")) {
|
||||
String cut = name.substring(name.indexOf('$') + 1);
|
||||
if (cut.length() <= 2) {
|
||||
name = name.replace("Entity", "");
|
||||
name = name.replace('$', '_');
|
||||
flag = true;
|
||||
} else {
|
||||
// mapped, wooo
|
||||
name = cut;
|
||||
}
|
||||
}
|
||||
name = name.replace("PathfinderGoal", "");
|
||||
name = name.replace("TargetGoal", "");
|
||||
name = name.replace("Goal", "");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (char c : name.toCharArray()) {
|
||||
if (c >= 'A' && c <= 'Z') {
|
||||
sb.append('_');
|
||||
sb.append(Character.toLowerCase(c));
|
||||
} else {
|
||||
sb.append(c);
|
||||
}
|
||||
}
|
||||
name = sb.toString();
|
||||
name = name.replaceFirst("_", "");
|
||||
private static String getPathName(String name) {
|
||||
String pathName = name.substring(name.lastIndexOf('.') + 1);
|
||||
boolean needDeobfMap = false;
|
||||
|
||||
if (flag && !deobfuscationMap.containsKey(name.toLowerCase()) && !ignored.contains(name)) {
|
||||
System.out.println("need to map " + original + " (" + name.toLowerCase() + ")");
|
||||
// inner classes
|
||||
int firstInnerDelimiter = pathName.indexOf('$');
|
||||
if (firstInnerDelimiter != -1) {
|
||||
String innerClassName = pathName.substring(firstInnerDelimiter + 1);
|
||||
for (String nestedClass : innerClassName.split("\\$")) {
|
||||
if (NumberUtils.isDigits(nestedClass)) {
|
||||
needDeobfMap = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!needDeobfMap) {
|
||||
pathName = innerClassName;
|
||||
}
|
||||
pathName = pathName.replace('$', '_');
|
||||
// mapped, wooo!
|
||||
}
|
||||
|
||||
pathName = Formatting.stripWordOfCamelCaseName(pathName, "TargetGoal", true); // replace last? reverse search?
|
||||
pathName = Formatting.stripWordOfCamelCaseName(pathName, "Goal", true);
|
||||
pathName = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, pathName);
|
||||
|
||||
if (needDeobfMap && !deobfuscationMap.containsKey(pathName)) {
|
||||
System.err.println("need to map " + name + " (" + pathName + ")");
|
||||
}
|
||||
|
||||
// did we rename this key?
|
||||
return deobfuscationMap.getOrDefault(name, name);
|
||||
return deobfuscationMap.getOrDefault(pathName, pathName);
|
||||
}
|
||||
|
||||
public static boolean isIgnored(String name) {
|
||||
return ignored.contains(name);
|
||||
}
|
||||
|
||||
|
||||
public static <T extends Mob> GoalKey<T> getKey(String clazzName, Class<? extends Goal> goalClass) {
|
||||
String name = getUsableName(clazzName);
|
||||
if (MobGoalNames.isIgnored(name)) {
|
||||
//noinspection unchecked
|
||||
return (GoalKey<T>) GoalKey.of(Mob.class, NamespacedKey.minecraft(name));
|
||||
}
|
||||
public static <T extends Mob> GoalKey<T> getKey(Class<? extends Goal> goalClass) {
|
||||
String name = getPathName(goalClass.getName());
|
||||
return GoalKey.of(getEntity(goalClass), NamespacedKey.minecraft(name));
|
||||
}
|
||||
|
||||
public static <T extends Mob> Class<T> getEntity(Class<? extends Goal> goalClass) {
|
||||
private static <T extends Mob> Class<T> getEntity(Class<? extends Goal> goalClass) {
|
||||
//noinspection unchecked
|
||||
return (Class<T>) entityClassCache.computeIfAbsent(goalClass, key -> {
|
||||
for (Constructor<?> ctor : key.getDeclaredConstructors()) {
|
||||
for (int i = 0; i < ctor.getParameterCount(); i++) {
|
||||
Class<?> param = ctor.getParameterTypes()[i];
|
||||
for (Class<?> param : ctor.getParameterTypes()) {
|
||||
if (net.minecraft.world.entity.Mob.class.isAssignableFrom(param)) {
|
||||
//noinspection unchecked
|
||||
return toBukkitClass((Class<? extends net.minecraft.world.entity.Mob>) param);
|
||||
|
@ -318,14 +296,14 @@ public class MobGoalNames {
|
|||
}
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Can't figure out applicable entity for mob goal " + goalClass); // maybe just return EntityInsentient?
|
||||
throw new RuntimeException("Can't figure out applicable goalClass for mob goal " + goalClass + " " + WrappedGoal.class.isAssignableFrom(goalClass)); // maybe just return Mob?
|
||||
});
|
||||
}
|
||||
|
||||
public static Class<? extends Mob> toBukkitClass(Class<? extends net.minecraft.world.entity.Mob> nmsClass) {
|
||||
private static Class<? extends Mob> toBukkitClass(Class<? extends net.minecraft.world.entity.Mob> nmsClass) {
|
||||
Class<? extends Mob> bukkitClass = bukkitMap.get(nmsClass);
|
||||
if (bukkitClass == null) {
|
||||
throw new RuntimeException("Can't figure out applicable bukkit entity for nms entity " + nmsClass); // maybe just return Mob?
|
||||
throw new RuntimeException("Can't figure out applicable bukkit goalClass for nms goalClass " + nmsClass); // maybe just return Mob?
|
||||
}
|
||||
return bukkitClass;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import io.papermc.generator.utils.Javadocs;
|
|||
import io.papermc.generator.utils.TagRegistry;
|
||||
import io.papermc.paper.tag.EntityTags;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import net.minecraft.core.Registry;
|
||||
|
@ -75,13 +74,13 @@ public class TagGenerator extends SimpleGenerator {
|
|||
|
||||
private static final String REGISTRY_FIELD_JAVADOC = "Key for the built-in $L registry.";
|
||||
|
||||
private static final List<TagRegistry> TAG_REGISTRIES = List.of(
|
||||
private static final TagRegistry[] TAG_REGISTRIES = {
|
||||
registry("blocks", Material.class, Registries.BLOCK),
|
||||
registry("items", Material.class, Registries.ITEM),
|
||||
registry("fluids", Fluid.class, Registries.FLUID),
|
||||
registry("entity_types", EntityType.class, Registries.ENTITY_TYPE),
|
||||
registry("game_events", GameEvent.class, Registries.GAME_EVENT)
|
||||
);
|
||||
};
|
||||
|
||||
public TagGenerator(final String className, final String pkg) {
|
||||
super(className, pkg);
|
||||
|
|
|
@ -313,6 +313,7 @@ public final class BlockStateMapping {
|
|||
remove some patches:
|
||||
- Add missing block data mins and maxes
|
||||
- Allow changing bed's 'occupied' property
|
||||
rename module
|
||||
remove scrap of old spigot tooling (archetype)
|
||||
*/
|
||||
@Nullable
|
||||
|
|
|
@ -72,7 +72,7 @@ public final class Formatting {
|
|||
return Optional.of(resourcePath.substring(tagsIndex + tagDir.length() + 1, dotIndex)); // namespace/tags/registry_key/[tag_key].json
|
||||
}
|
||||
|
||||
public static int countOccurrences(String value, char match) {
|
||||
private static int countOccurrences(String value, char match) {
|
||||
int count = 0;
|
||||
for (int i = 0, len = value.length(); i < len; i++) {
|
||||
if (value.charAt(i) == match) {
|
||||
|
@ -83,18 +83,17 @@ public final class Formatting {
|
|||
}
|
||||
|
||||
public static String incrementalIndent(String unit, ClassNamed classNamed) {
|
||||
if (classNamed.clazz() == null) {
|
||||
if (classNamed.knownClass() == null) {
|
||||
return unit.repeat(countOccurrences(classNamed.dottedNestedName(), '.') + 1);
|
||||
}
|
||||
|
||||
Class<?> parent = classNamed.clazz().getEnclosingClass();
|
||||
Class<?> parent = classNamed.knownClass().getEnclosingClass();
|
||||
StringBuilder indentBuilder = new StringBuilder(unit);
|
||||
while (parent != null) {
|
||||
indentBuilder.append(unit);
|
||||
parent = parent.getEnclosingClass();
|
||||
}
|
||||
return indentBuilder.toString();
|
||||
|
||||
}
|
||||
|
||||
public static String quoted(String value) {
|
||||
|
|
|
@ -16,13 +16,13 @@ public record CollectingContext<T>(Set<ResourceKey<T>> registered,
|
|||
Registry<T> registry) implements BootstrapContext<T> {
|
||||
|
||||
@Override
|
||||
public Holder.Reference<T> register(final ResourceKey<T> resourceKey, final @NonNull T value, final Lifecycle lifecycle) {
|
||||
this.registered.add(resourceKey);
|
||||
return Holder.Reference.createStandAlone(this.registry.holderOwner(), resourceKey);
|
||||
public Holder.Reference<T> register(final ResourceKey<T> key, final @NonNull T value, final Lifecycle lifecycle) {
|
||||
this.registered.add(key);
|
||||
return Holder.Reference.createStandAlone(this.registry.holderOwner(), key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <S> HolderGetter<S> lookup(final ResourceKey<? extends Registry<? extends S>> resourceKey) {
|
||||
return Main.REGISTRY_ACCESS.registryOrThrow(resourceKey).asLookup();
|
||||
public <S> HolderGetter<S> lookup(final ResourceKey<? extends Registry<? extends S>> key) {
|
||||
return Main.REGISTRY_ACCESS.lookupOrThrow(key);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue