Skip to content

Commit ff303f5

Browse files
committed
MetaWorlds compat
1 parent 9b11cb5 commit ff303f5

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/main/java/com/falsepattern/chunk/internal/mixin/mixins/common/vanilla/AnvilChunkLoaderMixin.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
import lombok.val;
3030
import org.apache.logging.log4j.Level;
3131
import org.spongepowered.asm.mixin.Mixin;
32-
import org.spongepowered.asm.mixin.Overwrite;
32+
import org.spongepowered.asm.mixin.injection.At;
33+
import org.spongepowered.asm.mixin.injection.Inject;
34+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
35+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
3336

3437
import net.minecraft.block.Block;
3538
import net.minecraft.entity.Entity;
@@ -53,9 +56,13 @@ public abstract class AnvilChunkLoaderMixin {
5356
*
5457
* @author FalsePattern
5558
* @reason Replace functionality
59+
* @implNote Inject-cancel instead of overwrite for compat with Metaworlds-Mixins
5660
*/
57-
@Overwrite
58-
private void writeChunkToNBT(Chunk chunk, World world, NBTTagCompound nbt) {
61+
@Inject(method = "writeChunkToNBT",
62+
at = @At("HEAD"),
63+
cancellable = true,
64+
require = 1)
65+
private void writeChunkToNBT(Chunk chunk, World world, NBTTagCompound nbt, CallbackInfo ci) {
5966
nbt.setByte("V", (byte) 1);
6067
nbt.setInteger("xPos", chunk.xPosition);
6168
nbt.setInteger("zPos", chunk.zPosition);
@@ -65,6 +72,7 @@ private void writeChunkToNBT(Chunk chunk, World world, NBTTagCompound nbt) {
6572
writeSubChunks(chunk, nbt);
6673
writeCustomData(chunk, nbt);
6774
writeEntities(chunk, world, nbt);
75+
ci.cancel();
6876
}
6977

7078
/**
@@ -73,9 +81,13 @@ private void writeChunkToNBT(Chunk chunk, World world, NBTTagCompound nbt) {
7381
*
7482
* @author FalsePattern
7583
* @reason Replace functionality
84+
* @implNote Inject-cancel instead of overwrite for compat with Metaworlds-Mixins
7685
*/
77-
@Overwrite
78-
private Chunk readChunkFromNBT(World world, NBTTagCompound nbt) {
86+
@Inject(method = "readChunkFromNBT",
87+
at = @At("HEAD"),
88+
cancellable = true,
89+
require = 1)
90+
private void readChunkFromNBT(World world, NBTTagCompound nbt, CallbackInfoReturnable<Chunk> cir) {
7991
int x = nbt.getInteger("xPos");
8092
int z = nbt.getInteger("zPos");
8193
Chunk chunk = new Chunk(world, x, z);
@@ -85,7 +97,7 @@ private Chunk readChunkFromNBT(World world, NBTTagCompound nbt) {
8597
readCustomData(chunk, nbt);
8698

8799
// End this method here and split off entity loading to another method
88-
return chunk;
100+
cir.setReturnValue(chunk);
89101
}
90102

91103
private void readCustomData(Chunk chunk, NBTTagCompound nbt) {

0 commit comments

Comments
 (0)