Skip to content

Commit 556aa47

Browse files
committed
1.18.1 port
1 parent 08901de commit 556aa47

9 files changed

Lines changed: 48 additions & 87 deletions

File tree

build.gradle

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,8 @@ plugins {
44
id 'org.ajoberstar.grgit' version '4.1.0'
55
}
66

7-
def getVersionMetadata() {
8-
// CI builds version numbers
9-
def build_id = System.getenv("RELEASE_NUMBER")
10-
if (build_id != null) {
11-
return build_id + ".0.0"
12-
}
13-
14-
// Development builds
15-
if (grgit == null) {
16-
return "dev"
17-
}
18-
19-
// Named development builds
20-
def id = grgit.head().abbreviatedId
21-
if (!grgit.status().clean) {
22-
id += "-dirty"
23-
}
24-
25-
return "rev.${id}"
26-
}
27-
28-
archivesBaseName = "${project.mod_id}-${project.supported_versions}"
29-
version = "${getVersionMetadata()}"
7+
archivesBaseName = "$project.mod_id"
8+
version = "$project.mod_version+$project.supported_versions"
309
group = project.maven_group
3110

3211
repositories {

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
org.gradle.jvmargs=-Xmx1G
33
# Fabric Properties
44
# check these on https://modmuss50.me/fabric.html
5-
minecraft_version=1.18.2
6-
yarn_mappings=1.18.2+build.4
5+
minecraft_version=1.18.1
6+
yarn_mappings=1.18.1+build.22
77
loader_version=0.14.9
88
# Mod Properties
9-
mod_version=1.3.1+1.18+
9+
mod_version=1.3.1
1010
maven_group=me.char321
1111
archives_base_name=chunkcacher
1212
# MCSR
1313
mod_id=chunkcacher
14-
supported_versions=1.18-1.18.2
14+
supported_versions=1.18-1.18.1

src/main/java/me/char321/chunkcacher/WorldCache.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
import net.minecraft.server.world.ServerWorld;
77
import net.minecraft.util.math.ChunkPos;
88
import net.minecraft.util.registry.RegistryKey;
9-
import net.minecraft.world.ChunkSerializer;
10-
import net.minecraft.world.World;
9+
import net.minecraft.world.*;
1110
import net.minecraft.world.chunk.Chunk;
1211
import net.minecraft.world.gen.GeneratorOptions;
1312

14-
import java.util.HashMap;
15-
import java.util.List;
16-
import java.util.Map;
17-
import java.util.concurrent.CompletableFuture;
13+
import java.util.*;
1814

1915
public class WorldCache {
16+
private static final Map<RegistryKey<World>, Long2ObjectLinkedOpenHashMap<NbtCompound>> cache = new HashMap<>();
2017
public static boolean isGenerating = false;
18+
public static List<ChunkPos> strongholdCache;
2119
private static GeneratorOptions lastGeneratorOptions;
22-
private static final Map<RegistryKey<World>, Long2ObjectLinkedOpenHashMap<NbtCompound>> cache = new HashMap<>();
23-
public static CompletableFuture<List<ChunkPos>> strongholdCache;
2420

2521
public static void addChunk(ChunkPos chunkPos, Chunk chunk, ServerWorld world) {
2622
cache.computeIfAbsent(world.getRegistryKey(), k -> new Long2ObjectLinkedOpenHashMap<>()).put(chunkPos.toLong(), ChunkSerializer.serialize(world, chunk));
@@ -39,7 +35,7 @@ public static NbtCompound getChunkNbt(ChunkPos chunkPos, ServerWorld world) {
3935
/**
4036
* Checks if the generator options have changed, if so, clear the cache
4137
* dude github copilot is so cool it auto generated these comments
42-
38+
* <p>
4339
* kept as fallback just in case some Atum update messes anything up
4440
* not perfect but good enough for that purpose
4541
*/
@@ -58,4 +54,4 @@ public static void clearCache() {
5854
cache.clear();
5955
strongholdCache = null;
6056
}
61-
}
57+
}

src/main/java/me/char321/chunkcacher/mixin/ChunkGeneratorMixin.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
import me.char321.chunkcacher.WorldCache;
44
import net.minecraft.util.math.ChunkPos;
55
import net.minecraft.world.gen.chunk.ChunkGenerator;
6-
import org.spongepowered.asm.mixin.Mixin;
7-
import org.spongepowered.asm.mixin.injection.At;
8-
import org.spongepowered.asm.mixin.injection.Inject;
9-
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
6+
import org.spongepowered.asm.mixin.*;
7+
import org.spongepowered.asm.mixin.injection.*;
8+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
109

1110
import java.util.List;
12-
import java.util.concurrent.CompletableFuture;
1311

1412
@Mixin(ChunkGenerator.class)
1513
public class ChunkGeneratorMixin {
1614

17-
@Inject(method = "generateStrongholdPositions", at = @At("HEAD"), cancellable = true)
18-
private void applyCachedStrongholds(CallbackInfoReturnable<CompletableFuture<List<ChunkPos>>> cir) {
19-
if (WorldCache.shouldCache() && WorldCache.strongholdCache != null) {
20-
cir.setReturnValue(WorldCache.strongholdCache);
15+
@Shadow @Final private List<ChunkPos> strongholds;
16+
17+
@Inject(method = "generateStrongholdPositions", at = @At("HEAD"))
18+
private void applyCachedStrongholds(CallbackInfo ci) {
19+
if (WorldCache.shouldCache() && WorldCache.strongholdCache != null && this.strongholds.isEmpty()) {
20+
this.strongholds.addAll(WorldCache.strongholdCache);
2121
}
2222
}
2323

2424
@Inject(method = "generateStrongholdPositions", at = @At("TAIL"))
25-
private void cacheStrongholds(CallbackInfoReturnable<CompletableFuture<List<ChunkPos>>> cir) {
25+
private void cacheStrongholds(CallbackInfo ci) {
2626
if (WorldCache.shouldCache() && WorldCache.strongholdCache == null) {
27-
WorldCache.strongholdCache = cir.getReturnValue();
27+
WorldCache.strongholdCache = this.strongholds;
2828
}
2929
}
30-
}
30+
}

src/main/java/me/char321/chunkcacher/mixin/ChunkSerializerMixin.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
package me.char321.chunkcacher.mixin;
22

3-
import net.minecraft.nbt.NbtCompound;
4-
import net.minecraft.nbt.NbtLongArray;
3+
import net.minecraft.nbt.*;
54
import net.minecraft.server.world.ServerWorld;
6-
import net.minecraft.world.ChunkSerializer;
7-
import net.minecraft.world.Heightmap;
8-
import net.minecraft.world.chunk.Chunk;
9-
import net.minecraft.world.chunk.ChunkStatus;
10-
import net.minecraft.world.chunk.ProtoChunk;
5+
import net.minecraft.world.*;
6+
import net.minecraft.world.chunk.*;
117
import org.spongepowered.asm.mixin.Mixin;
12-
import org.spongepowered.asm.mixin.injection.At;
13-
import org.spongepowered.asm.mixin.injection.ModifyVariable;
14-
import org.spongepowered.asm.mixin.injection.Redirect;
8+
import org.spongepowered.asm.mixin.injection.*;
159

1610
import java.util.EnumSet;
1711

@@ -31,4 +25,4 @@ private static NbtCompound serializeHeightmaps2(NbtCompound nbtCompound, ServerW
3125
private static EnumSet<Heightmap.Type> deserializeHeightmaps(ChunkStatus status) {
3226
return EnumSet.allOf(Heightmap.Type.class);
3327
}
34-
}
28+
}

src/main/java/me/char321/chunkcacher/mixin/MinecraftServerMixin.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
import me.char321.chunkcacher.WorldCache;
44
import net.minecraft.server.MinecraftServer;
55
import net.minecraft.world.SaveProperties;
6-
import org.spongepowered.asm.mixin.Final;
7-
import org.spongepowered.asm.mixin.Mixin;
8-
import org.spongepowered.asm.mixin.Shadow;
9-
import org.spongepowered.asm.mixin.injection.At;
10-
import org.spongepowered.asm.mixin.injection.Inject;
6+
import org.spongepowered.asm.mixin.*;
7+
import org.spongepowered.asm.mixin.injection.*;
118
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
129

1310
@Mixin(MinecraftServer.class)
1411
public class MinecraftServerMixin {
1512

16-
@Shadow @Final protected SaveProperties saveProperties;
13+
@Shadow
14+
@Final
15+
protected SaveProperties saveProperties;
1716

1817
@Inject(method = "createWorlds", at = @At("HEAD"))
1918
private void isGenerating(CallbackInfo ci) {
@@ -25,4 +24,4 @@ private void isGenerating(CallbackInfo ci) {
2524
private void isNotGenerating(CallbackInfo ci) {
2625
WorldCache.isGenerating = false;
2726
}
28-
}
27+
}

src/main/java/me/char321/chunkcacher/mixin/ThreadedAnvilChunkStorageMixin.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,20 @@
33
import com.mojang.datafixers.util.Either;
44
import me.char321.chunkcacher.WorldCache;
55
import net.minecraft.nbt.NbtCompound;
6-
import net.minecraft.server.world.ChunkHolder;
7-
import net.minecraft.server.world.ServerWorld;
8-
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
6+
import net.minecraft.server.world.*;
97
import net.minecraft.util.math.ChunkPos;
10-
import net.minecraft.world.chunk.Chunk;
11-
import net.minecraft.world.chunk.ChunkStatus;
12-
import org.spongepowered.asm.mixin.Final;
13-
import org.spongepowered.asm.mixin.Mixin;
14-
import org.spongepowered.asm.mixin.Shadow;
15-
import org.spongepowered.asm.mixin.injection.At;
16-
import org.spongepowered.asm.mixin.injection.Inject;
17-
import org.spongepowered.asm.mixin.injection.ModifyVariable;
8+
import net.minecraft.world.chunk.*;
9+
import org.spongepowered.asm.mixin.*;
10+
import org.spongepowered.asm.mixin.injection.*;
1811
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1912

2013
import java.util.concurrent.CompletableFuture;
2114

2215
@Mixin(ThreadedAnvilChunkStorage.class)
2316
public class ThreadedAnvilChunkStorageMixin {
24-
25-
@Shadow @Final ServerWorld world;
17+
@Shadow
18+
@Final
19+
ServerWorld world;
2620

2721
@Inject(method = "method_17225", at = @At("RETURN"), remap = false)
2822
private void addToCache(CallbackInfoReturnable<CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>>> cir) {
@@ -35,9 +29,9 @@ private void addToCache(CallbackInfoReturnable<CompletableFuture<Either<Chunk, C
3529
}
3630
}
3731

38-
/*
39-
1.19 changes the return type of getUpdatedChunkNbt to a CompletableFuture, so instead we
40-
modify the nbtCompound a bit later in loadChunk to keep compatibility
32+
/**
33+
* 1.18 changes the return type of getUpdatedChunkNbt to a CompletableFuture, so instead we
34+
* modify the nbtCompound a bit later in loadChunk to keep compatibility
4135
*/
4236
@ModifyVariable(method = "method_17256", at = @At("STORE"), remap = false)
4337
private NbtCompound loadFromCache(NbtCompound nbtCompound, ChunkPos pos) {
@@ -46,4 +40,4 @@ private NbtCompound loadFromCache(NbtCompound nbtCompound, ChunkPos pos) {
4640
}
4741
return nbtCompound;
4842
}
49-
}
43+
}

src/main/java/me/char321/chunkcacher/mixin/TitleScreenMixin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010

1111
@Mixin(TitleScreen.class)
1212
public class TitleScreenMixin {
13-
1413
@Inject(method = "init", at = @At("HEAD"))
1514
private void clearCacheOnAtumQuit(CallbackInfo ci) {
1615
if (!Atum.isRunning || Atum.seed == null || Atum.seed.isEmpty()) {
1716
WorldCache.clearCache();
1817
}
1918
}
20-
}
19+
}

src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"depends": {
1515
"fabricloader": ">=0.12.2",
16-
"minecraft": "1.18.x",
16+
"minecraft": ">=1.18 <1.18.2",
1717
"atum": "*"
1818
},
1919
"breaks": {

0 commit comments

Comments
 (0)