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

chore: Port to 1.20.5/1.20.6 #44

Merged
merged 25 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
0dc8bec
chore: Port to 1.20.5 and probably break something important
Awakened-Redstone Apr 23, 2024
9d1617e
chore: Fix logger message
Awakened-Redstone Apr 23, 2024
f25fa59
chore: Fix logger message
Awakened-Redstone Apr 23, 2024
556189c
Merge remote-tracking branch 'origin/1.20.4' into 1.20.5
Awakened-Redstone Apr 23, 2024
09b8b2b
chore: Fix commented line
Awakened-Redstone Apr 23, 2024
c210487
chore: Undo static removal
Awakened-Redstone Apr 23, 2024
4b002c8
chore: Uncomment and port recipe manager
Awakened-Redstone Apr 24, 2024
f4f2583
chore: Remove try catch
Awakened-Redstone Apr 24, 2024
b2a0500
chore: Better handle test command errors
Awakened-Redstone Apr 24, 2024
d0a3603
chore: Use overworld dimension to get proper world height
Awakened-Redstone Apr 24, 2024
5c64990
chore: Use 1.20.5
Awakened-Redstone Apr 24, 2024
c940acd
chore: Remove unused imports
Awakened-Redstone Apr 24, 2024
6505e4b
chore: Sort actions the same order as on SimpleRegistry#add and remov…
Awakened-Redstone Apr 24, 2024
e0894a4
fix: Don't remove the value twice
Awakened-Redstone Apr 24, 2024
9b97c3b
chore: Cleanup code
Awakened-Redstone Apr 24, 2024
37467f1
chore: Finally get this mixin to work, mod compat unknown
Awakened-Redstone Apr 25, 2024
2255be4
chore: Remove comment
Awakened-Redstone Apr 25, 2024
d9810b0
chore: Remove polymer-reg-sync-manipulator
Awakened-Redstone Apr 25, 2024
5ecd7f7
chore: Use fabric-api for an easier to understand mod resolution error
Awakened-Redstone Apr 25, 2024
502e06d
chore: Bump mod version
Awakened-Redstone Apr 29, 2024
0bb3104
fix: Require MC 1.20.5+
Awakened-Redstone Apr 29, 2024
768b687
chore: Java 21
Awakened-Redstone Apr 29, 2024
fd4784d
chore: 1.20.6
Awakened-Redstone Apr 29, 2024
4f5cc0f
fix SAVE_PROPERTIES_PREDICATE dimension option encoding of runtime wo…
LCLPYT May 4, 2024
8905683
Merge pull request #1 from LCLPYT/fix-dimension-save-predicate
Awakened-Redstone May 4, 2024
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 .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);
Awakened-Redstone marked this conversation as resolved.
Show resolved Hide resolved
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