Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for 1.21.2 #5

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repositories {
}

dependencies {
"minecraft"("com.mojang:minecraft:1.21.1")
"minecraft"("com.mojang:minecraft:1.21.2-rc1")
"mappings"(project.the<LoomGradleExtensionAPI>().officialMojangMappings())
"modImplementation"("net.fabricmc:fabric-loader:0.16.7")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void registerAdapters(GsonBuilder builder) {

@Override
public Registry<Block> getRegistry() {
return GameSetupUtils.getServerRegistries().registryOrThrow(Registries.BLOCK);
return GameSetupUtils.getServerRegistries().lookupOrThrow(Registries.BLOCK);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -55,27 +56,29 @@ public DataVersionDumper(File file) {
private <T> Map<String, List<String>> getTags(Registry<T> registry) {
Map<String, List<String>> 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<? extends Property> clazz) {
private String getTypeName(Property<?> property) {
Class<? extends Property> 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!");
}
Expand All @@ -85,14 +88,14 @@ private String getTypeName(Class<? extends Property> clazz) {
public void run() {
// Blocks
Map<String, Map<String, Object>> blocks = new TreeMap<>();
for (ResourceLocation blockId : getServerRegistries().registryOrThrow(Registries.BLOCK).keySet()) {
for (ResourceLocation blockId : getServerRegistries().lookupOrThrow(Registries.BLOCK).keySet()) {
Map<String, Object> bl = new TreeMap<>();
Block block = getServerRegistries().registryOrThrow(Registries.BLOCK).get(blockId);
Block block = getServerRegistries().lookupOrThrow(Registries.BLOCK).get(blockId).get().value();
Map<String, Object> properties = new TreeMap<>();
for (Property<?> prop : block.defaultBlockState().getProperties()) {
Map<String, Object> 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);
Expand All @@ -112,22 +115,22 @@ public void run() {
}

// Items
List<String> items = getServerRegistries().registryOrThrow(Registries.ITEM).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList());
List<String> items = getServerRegistries().lookupOrThrow(Registries.ITEM).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList());

// Entities
List<String> entities = getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList());
List<String> entities = getServerRegistries().lookupOrThrow(Registries.ENTITY_TYPE).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList());

// Biomes
List<String> biomes = getServerRegistries().registryOrThrow(Registries.BIOME).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList());
List<String> biomes = getServerRegistries().lookupOrThrow(Registries.BIOME).keySet().stream().sorted().map(ResourceLocation::toString).collect(Collectors.toList());

// BlockTags
Map<String, List<String>> blockTags = getTags(getServerRegistries().registryOrThrow(Registries.BLOCK));
Map<String, List<String>> blockTags = getTags(getServerRegistries().lookupOrThrow(Registries.BLOCK));

// ItemTags
Map<String, List<String>> itemTags = getTags(getServerRegistries().registryOrThrow(Registries.ITEM));
Map<String, List<String>> itemTags = getTags(getServerRegistries().lookupOrThrow(Registries.ITEM));

// EntityTags
Map<String, List<String>> entityTags = getTags(getServerRegistries().registryOrThrow(Registries.ENTITY_TYPE));
Map<String, List<String>> entityTags = getTags(getServerRegistries().lookupOrThrow(Registries.ENTITY_TYPE));

Map<String, Object> output = new TreeMap<>();
output.put("blocks", blocks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ItemRegistryDumper(File file) {

@Override
public Registry<Item> getRegistry() {
return GameSetupUtils.getServerRegistries().registryOrThrow(Registries.ITEM);
return GameSetupUtils.getServerRegistries().lookupOrThrow(Registries.ITEM);
}

@Override
Expand All @@ -55,7 +55,7 @@ public List<Map<String, Object>> getProperties(ResourceLocation resourceLocation
private Map<String, Object> getPropertiesForItem(ResourceLocation resourceLocation, Item item) {
Map<String, Object> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,10 @@ protected Iterator<ResourceLocation> 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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void run() {
ImmutableList<Map<String, Object>> 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())
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
});
Expand All @@ -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);

Expand Down