Skip to content

Commit

Permalink
chore: Port to 1.20.5/1.20.6 (#44)
Browse files Browse the repository at this point in the history
* chore: Port to 1.20.5 and probably break something important

* chore: Fix logger message

* chore: Fix logger message

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Fix commented line

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Undo static removal

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Uncomment and port recipe manager

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Remove try catch

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Better handle test command errors

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Use overworld dimension to get proper world height

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Use 1.20.5

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Remove unused imports

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Sort actions the same order as on SimpleRegistry#add and remove from entryToRawId

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* fix: Don't remove the value twice

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Cleanup code

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Finally get this mixin to work, mod compat unknown

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Remove comment

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Remove polymer-reg-sync-manipulator

No difference was noticed with and without it

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Use fabric-api for an easier to understand mod resolution error

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Bump mod version

Bump the mod version as the PR has a small behavior change (RuntimeWorldConfig.java:78)

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* fix: Require MC 1.20.5+

Oops, I forgot about this

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: Java 21

I missed some stuff

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* chore: 1.20.6

Update to 1.20.6, bumping mc ver as modders should use it over 1.20.5, not bumping required mc ver for compatibility

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>

* fix SAVE_PROPERTIES_PREDICATE dimension option encoding of runtime worlds

---------

Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com>
Co-authored-by: LCLP <lukas@lclpnet.work>
  • Loading branch information
Awakened-Redstone and LCLPYT authored May 12, 2024
1 parent 0f61f4d commit 7fe6963
Show file tree
Hide file tree
Showing 21 changed files with 151 additions and 126 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 17
java-version: 21

- name: Grant execute permission for gradlew
run: chmod +x gradlew
Expand Down
10 changes: 4 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'fabric-loom' version '1.4.+'
id 'fabric-loom' version '1.6.+'
id 'maven-publish'
}

sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

archivesBaseName = project.archives_base_name
version = project.mod_version + "+" + project.minecraft_version
Expand Down Expand Up @@ -47,8 +47,6 @@ dependencies {

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"

modLocalRuntime "eu.pb4:polymer-reg-sync-manipulator:0.7.0+1.20.3-rc1"

testmodImplementation sourceSets.main.output
}

Expand All @@ -62,7 +60,7 @@ processResources {

tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 17
it.options.release = 21
}

java {
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ org.gradle.jvmargs=-Xmx2G

# Fabric Properties

minecraft_version=1.20.4
yarn_mappings=1.20.4+build.1
loader_version=0.15.0
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.1
loader_version=0.15.10

# Mod Properties
mod_version=0.5.0
mod_version=0.5.1
maven_group=xyz.nucleoid
archives_base_name=fantasy

# Dependencies
fabric_version=0.91.1+1.20.4
fabric_version=0.97.8+1.20.6
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions src/main/java/xyz/nucleoid/fantasy/RuntimeWorldConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ public RuntimeWorldConfig setGenerator(ChunkGenerator generator) {
this.generator = generator;
return this;
}

public RuntimeWorldConfig setShouldTickTime(boolean shouldTickTime) {
this.shouldTickTime = shouldTickTime;
this.gameRules.set(GameRules.DO_DAYLIGHT_CYCLE, shouldTickTime);
return this;
}

Expand Down Expand Up @@ -167,7 +168,7 @@ public ChunkGenerator getGenerator() {
public RuntimeWorld.Constructor getWorldConstructor() {
return this.worldConstructor;
}

public boolean shouldTickTime() {
return this.shouldTickTime;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/xyz/nucleoid/fantasy/RuntimeWorldManager.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package xyz.nucleoid.fantasy;

import com.mojang.serialization.Lifecycle;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerWorldEvents;
import net.minecraft.registry.DynamicRegistryManager;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.SimpleRegistry;
import net.minecraft.registry.entry.RegistryEntryInfo;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ProgressListener;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionOptions;
import net.minecraft.world.level.storage.LevelStorage;
Expand Down Expand Up @@ -43,7 +42,7 @@ RuntimeWorld add(RegistryKey<World> worldKey, RuntimeWorldConfig config, Runtime

var key = RegistryKey.of(RegistryKeys.DIMENSION, worldKey.getValue());
if(!dimensionsRegistry.contains(key)) {
dimensionsRegistry.add(key, options, Lifecycle.stable());
dimensionsRegistry.add(key, options, RegistryEntryInfo.DEFAULT);
}
((RemoveFromRegistry<?>) dimensionsRegistry).fantasy$setFrozen(isFrozen);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class ServerChunkManagerMixin {
@Shadow
@Final
private ServerWorld world;
ServerWorld world;

@Inject(method = "executeQueuedTasks", at = @At("HEAD"), cancellable = true)
private void executeQueuedTasks(CallbackInfoReturnable<Boolean> ci) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin implements FantasyWorldAccess {
@Unique
private static final int TICK_TIMEOUT = 20 * 15;

@Unique
Expand Down Expand Up @@ -53,6 +54,7 @@ private void tick(BooleanSupplier shouldKeepTicking, CallbackInfo ci) {
return shouldTick || this.fantasy$tickTimeout > 0;
}

@Unique
private boolean isWorldEmpty() {
return this.getPlayers().isEmpty() && this.getChunkManager().getLoadedChunkCount() <= 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorSettings;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -14,7 +13,6 @@
@Mixin(ThreadedAnvilChunkStorage.class)
public class ThreadedAnvilChunkStorageMixin {
@Shadow
@Final
private ChunkGenerator chunkGenerator;

@WrapOperation(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;createMissingSettings()Lnet/minecraft/world/gen/chunk/ChunkGeneratorSettings;"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

@Mixin(DimensionOptions.class)
public class DimensionOptionsMixin implements FantasyDimensionOptions {
@Unique
private boolean fantasy$save = true;
@Unique
private boolean fantasy$saveProperties = true;
@Unique private boolean fantasy$save = true;
@Unique private boolean fantasy$saveProperties = true;

@Override
public void fantasy$setSave(boolean value) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
package xyz.nucleoid.fantasy.mixin.registry;

import com.mojang.serialization.Lifecycle;
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.mojang.logging.LogUtils;
import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.Reference2IntMap;
import net.minecraft.registry.MutableRegistry;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.SimpleRegistry;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryEntryInfo;
import net.minecraft.registry.entry.RegistryEntryOwner;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import xyz.nucleoid.fantasy.RemoveFromRegistry;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Stream;

@Mixin(SimpleRegistry.class)
public abstract class SimpleRegistryMixin<T> implements RemoveFromRegistry<T> {
public abstract class SimpleRegistryMixin<T> implements RemoveFromRegistry<T>, MutableRegistry<T> {
@Unique private static final Logger fantasy$LOGGER = LogUtils.getLogger();

@Shadow @Final private Map<T, RegistryEntry.Reference<T>> valueToEntry;

@Shadow @Final private Map<Identifier, RegistryEntry.Reference<T>> idToEntry;

@Shadow @Final private Map<RegistryKey<T>, RegistryEntry.Reference<T>> keyToEntry;

@Shadow @Final private Map<T, Lifecycle> entryToLifecycle;

@Shadow @Final private Map<RegistryKey<T>, RegistryEntryInfo> keyToEntryInfo;
@Shadow @Final private ObjectList<RegistryEntry.Reference<T>> rawIdToEntry;

@Shadow @Final private Reference2IntMap<T> entryToRawId;

@Shadow public abstract Optional<RegistryEntry<T>> getEntry(int rawId);

@Shadow @Final RegistryKey<? extends Registry<T>> key;
@Shadow private boolean frozen;

@Shadow @Nullable private List<RegistryEntry.Reference<T>> cachedEntries;

@Override
public boolean fantasy$remove(T entry) {
var registryEntry = this.valueToEntry.get(entry);
Expand All @@ -47,18 +48,15 @@ public abstract class SimpleRegistryMixin<T> implements RemoveFromRegistry<T> {
}

try {
this.rawIdToEntry.set(rawId, null);
this.idToEntry.remove(registryEntry.registryKey().getValue());
this.keyToEntry.remove(registryEntry.registryKey());
this.entryToLifecycle.remove(entry);
this.idToEntry.remove(registryEntry.registryKey().getValue());
this.valueToEntry.remove(entry);
if (this.cachedEntries != null) {
this.cachedEntries.remove(registryEntry);
}
this.rawIdToEntry.set(rawId, null);
this.keyToEntryInfo.remove(this.key);

return true;
} catch (Throwable e) {
e.printStackTrace();
fantasy$LOGGER.error("Could not remove entry", e);
return false;
}
}
Expand All @@ -78,4 +76,9 @@ public abstract class SimpleRegistryMixin<T> implements RemoveFromRegistry<T> {
public boolean fantasy$isFrozen() {
return this.frozen;
}

@ModifyReturnValue(method = "streamEntries", at = @At("RETURN"))
public Stream<RegistryEntry.Reference<T>> fixEntryStream(Stream<RegistryEntry.Reference<T>> original) {
return original.filter(Objects::nonNull);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package xyz.nucleoid.fantasy.mixin.registry;

import com.google.common.collect.Maps;
import net.minecraft.world.dimension.DimensionOptionsRegistryHolder;
import net.minecraft.world.level.WorldGenSettings;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import xyz.nucleoid.fantasy.FantasyDimensionOptions;

@Mixin(WorldGenSettings.class)
public class WorldGenSettingsMixin {

@ModifyArg(method = "encode(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/world/gen/GeneratorOptions;Lnet/minecraft/world/dimension/DimensionOptionsRegistryHolder;)Lcom/mojang/serialization/DataResult;", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/WorldGenSettings;<init>(Lnet/minecraft/world/gen/GeneratorOptions;Lnet/minecraft/world/dimension/DimensionOptionsRegistryHolder;)V"), index = 1)
private static DimensionOptionsRegistryHolder fantasy$wrapWorldGenSettings(DimensionOptionsRegistryHolder original) {
var dimensions = original.dimensions();
var saveDimensions = Maps.filterEntries(dimensions, entry -> FantasyDimensionOptions.SAVE_PROPERTIES_PREDICATE.test(entry.getValue()));

return new DimensionOptionsRegistryHolder(saveDimensions);
}
}
17 changes: 6 additions & 11 deletions src/main/java/xyz/nucleoid/fantasy/util/FilteredRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public Registry<T> getSource() {
@Nullable
@Override
public Identifier getId(T value) {
return check.test(value) ? this.source.getId(value) : null;
return this.check.test(value) ? this.source.getId(value) : null;
}

@Override
public Optional<RegistryKey<T>> getKey(T entry) {
return check.test(entry) ? this.source.getKey(entry) : Optional.empty();
return this.check.test(entry) ? this.source.getKey(entry) : Optional.empty();
}

@Override
public int getRawId(@Nullable T value) {
return check.test(value) ? this.source.getRawId(value) : -1;
return this.check.test(value) ? this.source.getRawId(value) : -1;
}

@Nullable
Expand All @@ -67,12 +67,7 @@ public T get(@Nullable RegistryKey<T> key) {
@Nullable
@Override
public T get(@Nullable Identifier id) {
return this.get(id);
}

@Override
public Lifecycle getEntryLifecycle(T entry) {
return this.source.getEntryLifecycle(entry);
return this.source.get(id);
}

@Override
Expand All @@ -82,7 +77,7 @@ public Lifecycle getLifecycle() {

@Override
public Set<Identifier> getIds() {
return this.getIds();
return this.source.getIds();
}

@Override
Expand Down Expand Up @@ -174,6 +169,6 @@ public void populateTags(Map<TagKey<T>, List<RegistryEntry<T>>> tagEntries) {
@NotNull
@Override
public Iterator<T> iterator() {
return Iterators.filter(this.source.iterator(), e -> this.check.test(e));
return Iterators.filter(this.source.iterator(), this.check::test);
}
}
Loading

0 comments on commit 7fe6963

Please sign in to comment.