MetaWorlds compat

This commit is contained in:
FalsePattern committed 2025-05-06 20:37:15 +02:00
1 parent 9b11cb5794
commit ff303f52c0
1 file changed
+18 -6
@@ -29,7 +29,10 @@ import com.falsepattern.chunk.internal.DataRegistryImpl;
import lombok.val;
import org.apache.logging.log4j.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
@@ -53,9 +56,13 @@ public abstract class AnvilChunkLoaderMixin {
*
* @author FalsePattern
* @reason Replace functionality
* @implNote Inject-cancel instead of overwrite for compat with Metaworlds-Mixins
*/
@Overwrite
private void writeChunkToNBT(Chunk chunk, World world, NBTTagCompound nbt) {
@Inject(method = "writeChunkToNBT",
at = @At("HEAD"),
cancellable = true,
require = 1)
private void writeChunkToNBT(Chunk chunk, World world, NBTTagCompound nbt, CallbackInfo ci) {
nbt.setByte("V", (byte) 1);
nbt.setInteger("xPos", chunk.xPosition);
nbt.setInteger("zPos", chunk.zPosition);
@@ -65,6 +72,7 @@ public abstract class AnvilChunkLoaderMixin {
writeSubChunks(chunk, nbt);
writeCustomData(chunk, nbt);
writeEntities(chunk, world, nbt);
ci.cancel();
}
/**
@@ -73,9 +81,13 @@ public abstract class AnvilChunkLoaderMixin {
*
* @author FalsePattern
* @reason Replace functionality
* @implNote Inject-cancel instead of overwrite for compat with Metaworlds-Mixins
*/
@Overwrite
private Chunk readChunkFromNBT(World world, NBTTagCompound nbt) {
@Inject(method = "readChunkFromNBT",
at = @At("HEAD"),
cancellable = true,
require = 1)
private void readChunkFromNBT(World world, NBTTagCompound nbt, CallbackInfoReturnable<Chunk> cir) {
int x = nbt.getInteger("xPos");
int z = nbt.getInteger("zPos");
Chunk chunk = new Chunk(world, x, z);
@@ -85,7 +97,7 @@ public abstract class AnvilChunkLoaderMixin {
readCustomData(chunk, nbt);
// End this method here and split off entity loading to another method
return chunk;
cir.setReturnValue(chunk);
}
private void readCustomData(Chunk chunk, NBTTagCompound nbt) {