Skip to content

Commit

Permalink
Update to 25w05a.
Browse files Browse the repository at this point in the history
- Update to 25w05a
- Very alpha at the moment due to vanilla PersistentState changes
- Fabric only until the Forges catch up
  • Loading branch information
gniftygnome committed Feb 4, 2025
1 parent 04c9ca7 commit 0381a3c
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 113 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id 'dev.architectury.loom' version '1.7-SNAPSHOT' apply(false)
id 'dev.architectury.loom' version '1.9-SNAPSHOT' apply(false)
}

architectury {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ public static void handleWorldStarting(ServerWorld world) {
if (dimensionKey.isPresent()) {
if (DimensionTypes.THE_END.equals(dimensionKey.get())) {
if (END_STATE == null) {
END_STATE = new BiolithState(world, "end");
END_STATE = world.getPersistentStateManager().getOrCreate(BiolithState.getPersistentStateType("end"));
END.serverReplaced(END_STATE, world.getSeed());
} else {
Biolith.LOGGER.warn("More than one End dimension world created; cowardly ignoring '{}' in favor of '{}'", world.getRegistryKey().getValue(), END_STATE.getWorldId());
}
} else if (DimensionTypes.THE_NETHER.equals(dimensionKey.get())) {
if (NETHER_STATE == null) {
NETHER_STATE = new BiolithState(world, "nether");
NETHER_STATE = world.getPersistentStateManager().getOrCreate(BiolithState.getPersistentStateType("nether"));
NETHER.serverReplaced(NETHER_STATE, world.getSeed());
} else {
Biolith.LOGGER.warn("More than one Nether dimension world created; cowardly ignoring '{}' in favor of '{}'", world.getRegistryKey().getValue(), NETHER_STATE.getWorldId());
}
} else if (DimensionTypes.OVERWORLD.equals(dimensionKey.get())) {
if (OVERWORLD_STATE == null) {
OVERWORLD_STATE = new BiolithState(world, "overworld");
OVERWORLD_STATE = world.getPersistentStateManager().getOrCreate(BiolithState.getPersistentStateType("overworld"));
OVERWORLD.serverReplaced(OVERWORLD_STATE, world.getSeed());
} else {
Biolith.LOGGER.warn("More than one Overworld dimension world created; cowardly ignoring '{}' in favor of '{}'", world.getRegistryKey().getValue(), OVERWORLD_STATE.getWorldId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@ public abstract class DimensionBiomePlacement {

public static final RegistryKey<Biome> VANILLA_PLACEHOLDER = RegistryKey.of(RegistryKeys.BIOME, Identifier.of(Biolith.MOD_ID, "vanilla"));

protected void serverReplaced(BiolithState state, long seed) {
protected void serverReplaced(@NotNull BiolithState state, long seed) {
this.state = state;
this.replacementNoise = new OpenSimplexNoise2(seed);
this.seedRandom = new Random(seed);
this.replacementRequests.forEach((biomeKey, requestSet) -> requestSet.complete(BiomeCoordinator.getBiomeLookupOrThrow()));
this.subBiomeRequests.forEach((biomeKey, requestSet) -> requestSet.complete(BiomeCoordinator.getBiomeLookupOrThrow()));
this.state.write();

// populate the seedlets from the game seed
for (int i = 0; i < 8; ++i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import net.minecraft.world.biome.source.BiomeCoords;
import net.minecraft.world.biome.source.util.MultiNoiseUtil;
import net.minecraft.world.gen.densityfunction.DensityFunction;
import org.jetbrains.annotations.NotNull;

import java.util.function.Consumer;

Expand Down Expand Up @@ -40,7 +41,7 @@ public EndBiomePlacement() {
}

@Override
protected void serverReplaced(BiolithState state, long seed) {
protected void serverReplaced(@NotNull BiolithState state, long seed) {
super.serverReplaced(state, seed);

// Update vanilla biome entries for the End
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.terraformersmc.biolith.impl.config;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.terraformersmc.biolith.impl.Biolith;
import net.minecraft.datafixer.DataFixTypes;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtList;
import net.minecraft.nbt.NbtString;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier;
import net.minecraft.world.PersistentState;
import net.minecraft.world.PersistentStateType;
import net.minecraft.world.biome.Biome;

import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Objects;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -25,72 +23,71 @@ public class BiolithState extends PersistentState {
private final LinkedHashMap<RegistryKey<Biome>, LinkedHashSet<RegistryKey<Biome>>> biomeReplacements = new LinkedHashMap<>(64);
private final ServerWorld world;

private final String stateId;
private static final int STATE_VERSION = 0;
private static <E> Codec<LinkedHashSet<E>> getLinkedHashSetCodec(Codec<E> entryCodec) {
return entryCodec.listOf().xmap(LinkedHashSet::new, lhs -> lhs.stream().toList());
}

public BiolithState(ServerWorld serverWorld, String name) {
// Make sure we've got the server world stowed for state loads/saves.
world = serverWorld;
stateId = Biolith.MOD_ID + "_" + name + "_state";
world.getPersistentStateManager().set(stateId, this);
this.readState();
public static Codec<BiolithState> getCodec(PersistentState.Context context) {
return RecordCodecBuilder.create(
(instance) -> instance.group(
Codec.unboundedMap(RegistryKey.createCodec(RegistryKeys.BIOME), getLinkedHashSetCodec(RegistryKey.createCodec(RegistryKeys.BIOME))).optionalFieldOf("biome_replacements", Map.of())
.forGetter(biolithState -> biolithState.biomeReplacements),
getLinkedHashSetCodec(RegistryKey.createCodec(RegistryKeys.BIOME)).listOf().optionalFieldOf("BiomeReplacementsList", List.of())
.forGetter(biolithState -> List.of())
)
.apply(instance, (replacements, biomeReplacementsList) -> {
if (!replacements.isEmpty()) {
return unmarshall_v1(context, replacements);
} else if (!biomeReplacementsList.isEmpty()) {
return unmarshall_v0(context, biomeReplacementsList);
} else {
return new BiolithState(context);
}
}));
}

private void writeState() {
this.markDirty();
world.getPersistentStateManager().save();
public static PersistentStateType<BiolithState> getPersistentStateType(String name) {
return new PersistentStateType<>(
Biolith.MOD_ID + "_" + name + "_state",
BiolithState::new,
BiolithState::getCodec,
null
);
}

private void readState() {
NbtCompound nbt = null;
NbtCompound nbtState = null;
public BiolithState(PersistentState.Context context) {
this.world = context.getWorldOrThrow();
}

try {
nbt = world.getPersistentStateManager().readNbt(stateId, DataFixTypes.LEVEL, STATE_VERSION);
} catch (IOException e) {
Biolith.LOGGER.debug("No saved state found for {}; starting anew...", stateId);
}
if (nbt != null && nbt.contains("data")) {
int nbtVersion = nbt.getInt("DataVersion");
nbtState = nbt.getCompound("data");
}
// Legacy unmarshaller for upgrading from v0 to v1
// Each map was stored as a flat ordered list with the key in position 0.
private static BiolithState unmarshall_v0(PersistentState.Context context, List<LinkedHashSet<RegistryKey<Biome>>> biomeReplacementsList) {
BiolithState state = new BiolithState(context);

biomeReplacements.clear();
if (nbtState != null && !nbtState.isEmpty()) {
NbtList biomeReplacementsNbt = nbtState.getList("BiomeReplacementsList", NbtList.LIST_TYPE);
biomeReplacementsNbt.forEach(nbtElement -> {
NbtList replacementsNbt = (NbtList) nbtElement.copy();
Identifier elementId = Identifier.tryParse(replacementsNbt.getString(0));
if (elementId == null) {
Biolith.LOGGER.warn("{}: Failed to parse target biome identifier from NBT: {}", stateId, replacementsNbt.getString(0));
} else if (replacementsNbt.size() < 2) {
Biolith.LOGGER.warn("{}: Replacements list from NBT contains no replacements: {}", stateId, replacementsNbt.getString(0));
} else {
RegistryKey<Biome> target = RegistryKey.of(RegistryKeys.BIOME, elementId);
replacementsNbt.remove(0);
biomeReplacements.put(target, replacementsNbt.stream()
.map(element -> Identifier.tryParse(element.asString())).filter(Objects::nonNull)
.map(id -> RegistryKey.of(RegistryKeys.BIOME, id))
.collect(Collectors.toCollection(LinkedHashSet::new)));
Biolith.LOGGER.debug("{}: Resolved replacements list from NBT: {} -> {}", stateId, target.getValue(), biomeReplacements.get(target).stream().map(RegistryKey::getValue).toList());
}
});
}
state.biomeReplacements.clear();
biomeReplacementsList.forEach(list -> {
RegistryKey<Biome> key = list.removeFirst();
state.biomeReplacements.put(key, new LinkedHashSet<>(list));
});

// Re-write the state in v1 format
state.markDirty();

return state;
}

@Override
public NbtCompound writeNbt(NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) {
NbtList biomeReplacementsNbt = new NbtList();
biomeReplacements.forEach((target, replacements) -> {
NbtList replacementsNbt = new NbtList();
replacementsNbt.add(NbtString.of(target.getValue().toString()));
replacementsNbt.addAll(replacements.stream().map(replacement -> NbtString.of(replacement.getValue().toString())).toList());
biomeReplacementsNbt.add(replacementsNbt);
});
Biolith.LOGGER.debug("{}: Describing biome replacemnts NBT:\n{}", stateId, biomeReplacementsNbt);
nbt.put("BiomeReplacementsList", biomeReplacementsNbt);
private static BiolithState unmarshall_v1(PersistentState.Context context, Map<RegistryKey<Biome>, LinkedHashSet<RegistryKey<Biome>>> replacements) {
BiolithState state = new BiolithState(context);

state.biomeReplacements.clear();
state.biomeReplacements.putAll(replacements);

return nbt;
return state;
}

public void write() {
this.markDirty();
world.getPersistentStateManager().save();
}

public Stream<RegistryKey<Biome>> getBiomeReplacements(RegistryKey<Biome> target) {
Expand Down
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@
"depends": {
"fabricloader": ">=0.15.3",
"fabric-api": "*",
"minecraft": ">=1.21.2 <1.22"
"minecraft": ">1.21.4 <1.22"
}
}
2 changes: 1 addition & 1 deletion forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ side = "BOTH"
[[dependencies.biolith]]
modId = "minecraft"
mandatory = true
versionRange = "[1.21.3,1.22)"
versionRange = "[1.21.5,1.22)"
ordering = "NONE"
side = "BOTH"
19 changes: 10 additions & 9 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ org.gradle.daemon=false
archives_base_name=biolith
mod_version=dev
maven_group=com.terraformersmc
enabled_platforms=fabric,forge,neoforge
#enabled_platforms=fabric,forge,neoforge
enabled_platforms=fabric

# Common
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
minecraft_version=25w05a
yarn_mappings=25w05a+build.4

# Fabric
fabric_api_version=0.107.0+1.21.3
fabric_loader_version=0.16.7
fabric_api_version=0.115.2+1.21.5
fabric_loader_version=0.16.10

# Forge
forge_version=1.21.3-53.0.5
Expand All @@ -30,10 +31,10 @@ neoforge_version=21.3.4-beta
mixinextras_version=0.4.1

# TerraBlender so we can use its API to access its region data
terrablender_version=1.21.3-4.2.0.0
terrablender_version=1.21.4-4.3.0.2

# Terraform API for simplex noise implementation
terraform_surfaces_api_version=12.0.0-alpha.2
terraform_surfaces_api_version=13.0.0-alpha.2

##
## Ferry configuration
Expand All @@ -52,14 +53,14 @@ default_release_type=alpha
# CurseForge Metadata
curseforge_slug=biolith
curseforge_id=852512
curseforge_game_versions=1.21.3, 1.21.4-Snapshot
curseforge_game_versions=1.21.5-Snapshot
curseforge_required_dependencies=
curseforge_optional_dependencies=

# Modrinth Metadata
modrinth_slug=biolith
modrinth_id=iGEl6Crx
modrinth_game_versions=1.21.3, 24w44a, 24w45a, 24w46a
modrinth_game_versions=25w05a
modrinth_mod_loaders=
modrinth_required_dependencies=

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
41 changes: 28 additions & 13 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,18 +198,28 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
Loading

0 comments on commit 0381a3c

Please sign in to comment.