From 2f6b1b15a6d6daf23f2db26fb3f35e60cfaad086 Mon Sep 17 00:00:00 2001 From: Madeline Miller Date: Sat, 19 Oct 2024 20:00:19 +1000 Subject: [PATCH] Update for 1.21.2-rc1 --- build.gradle.kts | 2 +- .../minecraft/dumper/BlockRegistryDumper.java | 2 +- .../minecraft/dumper/DataVersionDumper.java | 35 ++++++++++--------- .../minecraft/dumper/ItemRegistryDumper.java | 4 +-- .../minecraft/dumper/RegistryClassDumper.java | 4 +-- .../util/minecraft/dumper/RegistryDumper.java | 2 +- .../util/minecraft/util/GameSetupUtils.java | 7 ++-- 7 files changed, 31 insertions(+), 25 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index b267ae4..a5e1bc6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,7 +13,7 @@ repositories { } dependencies { - "minecraft"("com.mojang:minecraft:1.21.1") + "minecraft"("com.mojang:minecraft:1.21.2-rc1") "mappings"(project.the().officialMojangMappings()) "modImplementation"("net.fabricmc:fabric-loader:0.16.7") diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java b/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java index c169f81..3cbac3e 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java +++ b/src/main/java/org/enginehub/util/minecraft/dumper/BlockRegistryDumper.java @@ -64,7 +64,7 @@ public void registerAdapters(GsonBuilder builder) { @Override public Registry getRegistry() { - return GameSetupUtils.getServerRegistries().registryOrThrow(Registries.BLOCK); + return GameSetupUtils.getServerRegistries().lookupOrThrow(Registries.BLOCK); } @Override diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java b/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java index 69ecdad..21c4013 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java +++ b/src/main/java/org/enginehub/util/minecraft/dumper/DataVersionDumper.java @@ -5,12 +5,12 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import net.minecraft.SharedConstants; +import net.minecraft.core.Direction; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.state.properties.BooleanProperty; -import net.minecraft.world.level.block.state.properties.DirectionProperty; import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.Property; @@ -24,6 +24,7 @@ import java.util.Map; import java.util.TreeMap; import java.util.stream.Collectors; +import java.util.stream.StreamSupport; import static com.google.common.base.Preconditions.checkNotNull; import static org.enginehub.util.minecraft.util.GameSetupUtils.getServerRegistries; @@ -55,27 +56,29 @@ public DataVersionDumper(File file) { private Map> getTags(Registry registry) { Map> tagCollector = new TreeMap<>(); - registry.getTags().forEach(tagPair -> - tagCollector.put(tagPair.getFirst().location().toString(), tagPair.getSecond().stream() + registry.listTagIds().forEach(tagPair -> + tagCollector.put(tagPair.location().toString(), StreamSupport.stream(registry.getTagOrEmpty(tagPair).spliterator(), false) .map(entry -> checkNotNull(registry.getKey(entry.value()))) .map(ResourceLocation::toString) .sorted() - .collect(Collectors.toList())) + .toList()) ); return tagCollector; } @SuppressWarnings("rawtypes") - private String getTypeName(Class clazz) { + private String getTypeName(Property property) { + Class clazz = property.getClass(); if (clazz == EnumProperty.class) { + if (property.getValueClass() == Direction.class) { + return "direction"; + } return "enum"; } else if (clazz == IntegerProperty.class) { return "int"; } else if (clazz == BooleanProperty.class) { return "bool"; - } else if (clazz == DirectionProperty.class) { - return "direction"; } else { throw new RuntimeException("Unknown property!"); } @@ -85,14 +88,14 @@ private String getTypeName(Class clazz) { public void run() { // Blocks Map> blocks = new TreeMap<>(); - for (ResourceLocation blockId : getServerRegistries().registryOrThrow(Registries.BLOCK).keySet()) { + for (ResourceLocation blockId : getServerRegistries().lookupOrThrow(Registries.BLOCK).keySet()) { Map bl = new TreeMap<>(); - Block block = getServerRegistries().registryOrThrow(Registries.BLOCK).get(blockId); + Block block = getServerRegistries().lookupOrThrow(Registries.BLOCK).get(blockId).get().value(); Map properties = new TreeMap<>(); for (Property prop : block.defaultBlockState().getProperties()) { Map propertyValues = new TreeMap<>(); propertyValues.put("values", prop.getPossibleValues().stream().map(s -> s.toString().toLowerCase()).collect(Collectors.toList())); - propertyValues.put("type", getTypeName(prop.getClass())); + propertyValues.put("type", getTypeName(prop)); properties.put(prop.getName(), propertyValues); } bl.put("properties", properties); @@ -112,22 +115,22 @@ public void run() { } // Items - List items = getServerRegistries().registryOrThrow(Registries.ITEM).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + List items = getServerRegistries().lookupOrThrow(Registries.ITEM).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); // Entities - List entities = getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + List entities = getServerRegistries().lookupOrThrow(Registries.ENTITY_TYPE).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); // Biomes - List biomes = getServerRegistries().registryOrThrow(Registries.BIOME).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); + List biomes = getServerRegistries().lookupOrThrow(Registries.BIOME).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList()); // BlockTags - Map> blockTags = getTags(getServerRegistries().registryOrThrow(Registries.BLOCK)); + Map> blockTags = getTags(getServerRegistries().lookupOrThrow(Registries.BLOCK)); // ItemTags - Map> itemTags = getTags(getServerRegistries().registryOrThrow(Registries.ITEM)); + Map> itemTags = getTags(getServerRegistries().lookupOrThrow(Registries.ITEM)); // EntityTags - Map> entityTags = getTags(getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE)); + Map> entityTags = getTags(getServerRegistries().lookupOrThrow(Registries.ENTITY_TYPE)); Map output = new TreeMap<>(); output.put("blocks", blocks); diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java b/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java index ee2b732..ee8c416 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java +++ b/src/main/java/org/enginehub/util/minecraft/dumper/ItemRegistryDumper.java @@ -38,7 +38,7 @@ public ItemRegistryDumper(File file) { @Override public Registry getRegistry() { - return GameSetupUtils.getServerRegistries().registryOrThrow(Registries.ITEM); + return GameSetupUtils.getServerRegistries().lookupOrThrow(Registries.ITEM); } @Override @@ -55,7 +55,7 @@ public List> getProperties(ResourceLocation resourceLocation private Map getPropertiesForItem(ResourceLocation resourceLocation, Item item) { Map map = new TreeMap<>(); map.put("id", resourceLocation.toString()); - map.put("unlocalizedName", item.getDescriptionId(item.getDefaultInstance())); + map.put("unlocalizedName", item.getDescriptionId()); map.put("localizedName", item.getName(item.getDefaultInstance()).getString()); map.put("maxDamage", item.components().get(DataComponents.MAX_DAMAGE)); map.put("maxStackSize", item.components().get(DataComponents.MAX_STACK_SIZE)); diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java b/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java index 59ff1c2..dba6062 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java +++ b/src/main/java/org/enginehub/util/minecraft/dumper/RegistryClassDumper.java @@ -162,10 +162,10 @@ protected Iterator getDeprecatedTags() { @Override public void run() { - var registry = GameSetupUtils.getServerRegistries().registryOrThrow(key); + var registry = GameSetupUtils.getServerRegistries().lookupOrThrow(key); idDumper.generate(registry.keySet().iterator(), getDeprecatedIds()); - tagDumper.generate(registry.getTagNames().map(TagKey::location).iterator(), getDeprecatedTags()); + tagDumper.generate(registry.listTagIds().map(TagKey::location).iterator(), getDeprecatedTags()); } } diff --git a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java b/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java index 5b69967..fdeadd4 100644 --- a/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java +++ b/src/main/java/org/enginehub/util/minecraft/dumper/RegistryDumper.java @@ -36,7 +36,7 @@ public void run() { ImmutableList> list = ImmutableList.sortedCopyOf( getComparator(), getRegistry().keySet().stream() - .flatMap(v -> getProperties(v, registry.get(v)).stream()) + .flatMap(v -> getProperties(v, registry.get(v).get().value()).stream()) .collect(Collectors.toList()) ); diff --git a/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java b/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java index 3fdaac7..0f8aaa1 100644 --- a/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java +++ b/src/main/java/org/enginehub/util/minecraft/util/GameSetupUtils.java @@ -11,6 +11,7 @@ import net.minecraft.server.packs.repository.PackRepository; import net.minecraft.server.packs.repository.ServerPacksSource; import net.minecraft.world.Difficulty; +import net.minecraft.world.flag.FeatureFlagSet; import net.minecraft.world.flag.FeatureFlags; import net.minecraft.world.level.DataPackConfig; import net.minecraft.world.level.GameRules; @@ -27,13 +28,15 @@ public final class GameSetupUtils { + private static final FeatureFlagSet featureFlagSet = FeatureFlags.DEFAULT_FLAGS; + public static void setupGame() { SharedConstants.tryDetectVersion(); Bootstrap.bootStrap(); } private static final Lock lock = new ReentrantLock(); - private static final GameRules GAME_RULES = Util.make(new GameRules(), gameRules -> { + private static final GameRules GAME_RULES = Util.make(new GameRules(featureFlagSet), gameRules -> { gameRules.getRule(GameRules.RULE_DOMOBSPAWNING).set(false, null); gameRules.getRule(GameRules.RULE_WEATHER_CYCLE).set(false, null); }); @@ -49,7 +52,7 @@ public static RegistryAccess getServerRegistries() { } PackRepository resourcePackManager = new PackRepository(new ServerPacksSource(new DirectoryValidator(path -> true))); - WorldDataConfiguration wdc = new WorldDataConfiguration(DataPackConfig.DEFAULT, FeatureFlags.DEFAULT_FLAGS); + WorldDataConfiguration wdc = new WorldDataConfiguration(DataPackConfig.DEFAULT, featureFlagSet); WorldLoader.PackConfig dataPacks = new WorldLoader.PackConfig(resourcePackManager, wdc, false, true); WorldLoader.InitConfig serverConfig = new WorldLoader.InitConfig(dataPacks, Commands.CommandSelection.DEDICATED, 4);