From b20ae72a0de769e13303e643d5ff99a49fb0d340 Mon Sep 17 00:00:00 2001 From: nickid2018 Date: Sun, 30 Jun 2024 22:44:59 +0800 Subject: [PATCH] Add attribute exporting --- .../nickid2018/genwiki/RemapSettings.java | 4 ++ .../autovalue/EntityDataExtractor.java | 21 ++++++++ .../wikidata/DoubleNumberWikiData.java | 49 +++++++++++-------- .../autovalue/wikidata/NumberWikiData.java | 13 ++--- .../core/registries/BuiltInRegistries.java | 2 + .../world/entity/ai/attributes/Attribute.java | 15 ++++++ .../entity/ai/attributes/RangedAttribute.java | 12 +++++ 7 files changed, 90 insertions(+), 26 deletions(-) create mode 100644 wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/Attribute.java create mode 100644 wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/RangedAttribute.java diff --git a/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java b/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java index a484748..c743841 100644 --- a/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java +++ b/src/main/java/io/github/nickid2018/genwiki/RemapSettings.java @@ -180,6 +180,10 @@ public static void remapSettings(GenWikiMode mode, RemapProgram remapProgram) { } ) ); + remapProgram.addPostTransform( + "net.minecraft.world.entity.ai.attributes.Attribute", + ExtendAccessTransform.FIELD + ); remapProgram.addInjectEntries(new IncludeJarPackages("io.github.nickid2018.genwiki.autovalue")); } else { remapProgram.addPostTransform( diff --git a/src/main/java/io/github/nickid2018/genwiki/autovalue/EntityDataExtractor.java b/src/main/java/io/github/nickid2018/genwiki/autovalue/EntityDataExtractor.java index 176140b..a5560d3 100644 --- a/src/main/java/io/github/nickid2018/genwiki/autovalue/EntityDataExtractor.java +++ b/src/main/java/io/github/nickid2018/genwiki/autovalue/EntityDataExtractor.java @@ -14,6 +14,8 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.MobSpawnType; +import net.minecraft.world.entity.ai.attributes.Attribute; +import net.minecraft.world.entity.ai.attributes.RangedAttribute; import net.minecraft.world.item.alchemy.Potion; import java.util.Comparator; @@ -28,6 +30,10 @@ public class EntityDataExtractor { public static final BooleanWikiData EFFECT_INSTANTENOUS = new BooleanWikiData(); public static final StringListWikiData EFFECT_CANNOT_AFFECT = new StringListWikiData(); + public static final StringWikiData ATTRIBUTE_SENTIMENT = new StringWikiData(); + public static final DoubleNumberWikiData ATTRIBUTE_RANGE = new DoubleNumberWikiData(); + public static final NumberWikiData ATTRIBUTE_DEFAULT_VALUE = new NumberWikiData(); + public static final PotionEffectWikiData POTION_EFFECT = new PotionEffectWikiData(); @SneakyThrows @@ -93,11 +99,26 @@ public static void extractEntityData(MinecraftServer serverObj) { } } + for (ResourceKey attributeKey : BuiltInRegistries.ATTRIBUTE.registryKeySet()) { + String attributeID = attributeKey.location().getPath(); + Attribute attribute = BuiltInRegistries.ATTRIBUTE.get(attributeKey); + ATTRIBUTE_SENTIMENT.put(attributeID, attribute.sentiment.name()); + ATTRIBUTE_DEFAULT_VALUE.put(attributeID, attribute.defaultValue); + if (attribute instanceof RangedAttribute rangedAttribute) { + double minValue = rangedAttribute.getMinValue(); + double maxValue = rangedAttribute.getMaxValue(); + ATTRIBUTE_RANGE.put(attributeID, minValue, maxValue); + } + } + WikiData.write(MOB_CATEGORY, "entity_mob_category.txt"); WikiData.write(EFFECT_CATEGORY, "mob_effect_category.txt"); WikiData.write(EFFECT_COLOR, "mob_effect_color.txt"); WikiData.write(EFFECT_INSTANTENOUS, "mob_effect_instantenous.txt"); WikiData.write(EFFECT_CANNOT_AFFECT, "mob_effect_cannot_affect.txt"); WikiData.write(POTION_EFFECT, "potion_effect.txt"); + WikiData.write(ATTRIBUTE_SENTIMENT, "attribute_sentiment.txt"); + WikiData.write(ATTRIBUTE_RANGE, "attribute_range.txt"); + WikiData.write(ATTRIBUTE_DEFAULT_VALUE, "attribute_default_value.txt"); } } diff --git a/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/DoubleNumberWikiData.java b/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/DoubleNumberWikiData.java index 0ca7723..5c93a2e 100644 --- a/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/DoubleNumberWikiData.java +++ b/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/DoubleNumberWikiData.java @@ -1,7 +1,7 @@ package io.github.nickid2018.genwiki.autovalue.wikidata; -import it.unimi.dsi.fastutil.floats.FloatFloatImmutablePair; -import it.unimi.dsi.fastutil.floats.FloatFloatPair; +import it.unimi.dsi.fastutil.doubles.DoubleDoubleImmutablePair; +import it.unimi.dsi.fastutil.doubles.DoubleDoublePair; import it.unimi.dsi.fastutil.objects.Object2ObjectAVLTreeMap; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; @@ -12,19 +12,27 @@ public class DoubleNumberWikiData implements WikiData { private boolean enableFallback = false; - private float fallback1 = 0; - private float fallback2 = 0; + private double fallback1 = 0; + private double fallback2 = 0; private boolean fallbackNil = false; private boolean useFirstKeyComparator = true; - private static final Comparator FIRST_KEY_COMPARATOR = (o1, o2) -> Float.compare(o2.firstFloat(), o1.firstFloat()); - private static final Comparator SECOND_KEY_COMPARATOR = (o1, o2) -> Float.compare(o2.secondFloat(), o1.secondFloat()); + private static final Comparator FIRST_KEY_COMPARATOR = (o1, o2) -> Double.compare( + o2.firstDouble(), + o1.firstDouble() + ); + private static final Comparator SECOND_KEY_COMPARATOR = (o1, o2) -> Double.compare( + o2.secondDouble(), + o1.secondDouble() + ); - private static final Comparator FIRST_FIRST = FIRST_KEY_COMPARATOR.thenComparing(SECOND_KEY_COMPARATOR); - private static final Comparator FIRST_SECOND = SECOND_KEY_COMPARATOR.thenComparing(FIRST_KEY_COMPARATOR); + private static final Comparator FIRST_FIRST = FIRST_KEY_COMPARATOR.thenComparing( + SECOND_KEY_COMPARATOR); + private static final Comparator FIRST_SECOND = SECOND_KEY_COMPARATOR.thenComparing( + FIRST_KEY_COMPARATOR); - private final Object2ObjectAVLTreeMap> groups = new Object2ObjectAVLTreeMap<>( - (o1, o2) -> useFirstKeyComparator ? FIRST_FIRST.compare(o1, o2) : FIRST_SECOND.compare(o1, o2) + private final Object2ObjectAVLTreeMap> groups = new Object2ObjectAVLTreeMap<>( + (o1, o2) -> useFirstKeyComparator ? FIRST_FIRST.compare(o1, o2) : FIRST_SECOND.compare(o1, o2) ); public DoubleNumberWikiData setUseFirstKeyComparator(boolean useFirstKeyComparator) { @@ -37,20 +45,20 @@ public DoubleNumberWikiData setFallbackNil(boolean fallbackNil) { return this; } - public DoubleNumberWikiData setFallback(float fallback1, float fallback2) { + public DoubleNumberWikiData setFallback(double fallback1, double fallback2) { enableFallback = true; this.fallback1 = fallback1; this.fallback2 = fallback2; return this; } - public void put(String id, float value1, float value2) { + public void put(String id, double value1, double value2) { if (enableFallback && value1 == fallback1) return; - groups.computeIfAbsent(new FloatFloatImmutablePair(value1, value2), k -> new TreeSet<>()).add(id); + groups.computeIfAbsent(new DoubleDoubleImmutablePair(value1, value2), k -> new TreeSet<>()).add(id); } - private String formatValue(float value) { + private String formatValue(double value) { String formatted = String.format("%.3f", value); if (formatted.contains(".")) while (formatted.endsWith("0")) @@ -68,14 +76,15 @@ public String output(int indent) { builder.append(tab).append("['__fallback'] = nil,\n\n"); else builder.append(tab).append("['__fallback'] = {") - .append(formatValue(fallback1)).append(", ").append(formatValue(fallback2)).append("},\n\n"); - for (Object2ObjectMap.Entry> entry : groups.object2ObjectEntrySet()) { - FloatFloatPair value = entry.getKey(); - String formatted1 = formatValue(value.firstFloat()); - String formatted2 = formatValue(value.secondFloat()); + .append(formatValue(fallback1)).append(", ").append(formatValue(fallback2)).append("},\n\n"); + for (Object2ObjectMap.Entry> entry : groups.object2ObjectEntrySet()) { + DoubleDoublePair value = entry.getKey(); + String formatted1 = formatValue(value.firstDouble()); + String formatted2 = formatValue(value.secondDouble()); builder.append(tab).append("-- <").append(formatted1).append(", ").append(formatted2).append(">\n"); for (String id : entry.getValue()) - builder.append(tab).append("['").append(id).append("'] = {").append(formatted1).append(", ").append(formatted2).append("},\n"); + builder.append(tab).append("['").append(id).append("'] = {").append(formatted1).append(", ").append( + formatted2).append("},\n"); builder.append("\n"); } return builder.toString(); diff --git a/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/NumberWikiData.java b/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/NumberWikiData.java index 72bbfaa..652df64 100644 --- a/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/NumberWikiData.java +++ b/src/main/java/io/github/nickid2018/genwiki/autovalue/wikidata/NumberWikiData.java @@ -1,13 +1,14 @@ package io.github.nickid2018.genwiki.autovalue.wikidata; -import it.unimi.dsi.fastutil.floats.*; +import it.unimi.dsi.fastutil.doubles.Double2ObjectAVLTreeMap; +import it.unimi.dsi.fastutil.doubles.Double2ObjectMap; import java.util.Set; import java.util.TreeSet; public class NumberWikiData implements WikiData { - private final Float2ObjectMap> groups = new Float2ObjectAVLTreeMap<>(); + private final Double2ObjectMap> groups = new Double2ObjectAVLTreeMap<>(); private boolean enableFallback = false; private float fallback = 0; @@ -18,13 +19,13 @@ public NumberWikiData setFallback(float fallback) { return this; } - public void put(String id, float value) { + public void put(String id, double value) { if (enableFallback && value == fallback) return; groups.computeIfAbsent(value, k -> new TreeSet<>()).add(id); } - public static String formatValue(float value) { + public static String formatValue(double value) { String formatted = String.format("%.3f", value); if (formatted.contains(".")) while (formatted.endsWith("0")) @@ -39,8 +40,8 @@ public String output(int indent) { String tab = "\t".repeat(indent); if (enableFallback) builder.append(tab).append("['__fallback'] = ").append(formatValue(fallback)).append(",\n\n"); - for (Float2ObjectMap.Entry> entry : groups.float2ObjectEntrySet()) { - float value = entry.getFloatKey(); + for (Double2ObjectMap.Entry> entry : groups.double2ObjectEntrySet()) { + double value = entry.getDoubleKey(); String formatted = formatValue(value); builder.append(tab).append("-- ").append(formatted).append("\n"); for (String id : entry.getValue()) diff --git a/wrapped-mc/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java b/wrapped-mc/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java index bf5f5e0..d9cb5f9 100644 --- a/wrapped-mc/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java +++ b/wrapped-mc/src/main/java/net/minecraft/core/registries/BuiltInRegistries.java @@ -5,6 +5,7 @@ import net.minecraft.core.Registry; import net.minecraft.world.effect.MobEffect; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.item.CreativeModeTab; import net.minecraft.world.item.Item; import net.minecraft.world.item.alchemy.Potion; @@ -18,4 +19,5 @@ public class BuiltInRegistries { public static final Registry MOB_EFFECT = SneakyUtil.sneakyNotNull(); public static final Registry POTION = SneakyUtil.sneakyNotNull(); public static final DefaultedRegistry BLOCK = SneakyUtil.sneakyNotNull(); + public static final Registry ATTRIBUTE = SneakyUtil.sneakyNotNull(); } diff --git a/wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/Attribute.java b/wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/Attribute.java new file mode 100644 index 0000000..4a874f9 --- /dev/null +++ b/wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/Attribute.java @@ -0,0 +1,15 @@ +package net.minecraft.world.entity.ai.attributes; + +import io.github.nickid2018.util.SneakyUtil; + +public class Attribute { + + public final double defaultValue = SneakyUtil.sneakyInt(); + public Sentiment sentiment = Sentiment.POSITIVE; + + public enum Sentiment { + POSITIVE, + NEUTRAL, + NEGATIVE + } +} diff --git a/wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/RangedAttribute.java b/wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/RangedAttribute.java new file mode 100644 index 0000000..c23ed27 --- /dev/null +++ b/wrapped-mc/src/main/java/net/minecraft/world/entity/ai/attributes/RangedAttribute.java @@ -0,0 +1,12 @@ +package net.minecraft.world.entity.ai.attributes; + +public class RangedAttribute extends Attribute { + + public double getMinValue() { + throw new RuntimeException(); + } + + public double getMaxValue() { + throw new RuntimeException(); + } +}