From 74cdc561e6de6801b4d54ec213087cc4d1840014 Mon Sep 17 00:00:00 2001 From: FalsePattern Date: Sat, 30 Dec 2023 19:26:03 +0100 Subject: [PATCH] Preliminary ChunkAPI/EndlessIDs compatibility (#94) * Preliminary ChunkAPI compatibility * endlessids biome array crash fix * Ensure skylight array is not null when hasSky is set --------- Co-authored-by: Darren Eberly --- dependencies.gradle | 2 + repositories.gradle | 4 ++ .../gtnewhorizons/angelica/AngelicaMod.java | 6 ++ .../compat/ExtendedBlockStorageExt.java | 72 +++++++++++-------- .../world/cloned/ClonedChunkSection.java | 12 +++- 5 files changed, 63 insertions(+), 33 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index b7c9ea728..7c9c1b787 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -75,6 +75,8 @@ dependencies { compileOnly("com.github.GTNewHorizons:twilightforest:2.5.1:dev") {transitive = false } compileOnly(rfg.deobf('curse.maven:witchery-69673:2234410')) + compileOnly("com.falsepattern:chunkapi-mc1.7.10:0.5.0:api") + compileOnly("com.falsepattern:endlessids-mc1.7.10:1.5-beta0002:dev") compileOnly(rfg.deobf("curse.maven:extrautils-225561:2264383")) compileOnly(rfg.deobf("curse.maven:dynamiclights-227874:2337326")) diff --git a/repositories.gradle b/repositories.gradle index ce179e75b..bb4cb92cf 100644 --- a/repositories.gradle +++ b/repositories.gradle @@ -9,5 +9,9 @@ repositories { artifact() } } + maven { + name = 'mavenpattern' + url = 'https://mvn.falsepattern.com/releases' + } mavenLocal() } diff --git a/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java b/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java index 0bdcf8753..516444f41 100644 --- a/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java +++ b/src/main/java/com/gtnewhorizons/angelica/AngelicaMod.java @@ -24,6 +24,10 @@ public class AngelicaMod { public static boolean isNEIDLoaded; /** ASM Version */ public static boolean isOldNEIDLoaded; + + public static boolean isChunkAPILoaded; + + public static boolean isEIDBiomeLoaded; public static final boolean lwjglDebug = Boolean.parseBoolean(System.getProperty("org.lwjgl.util.Debug", "false")); public static final ManagedEnum animationsMode = new ManagedEnum<>(AnimationMode.VISIBLE_ONLY); @@ -32,6 +36,8 @@ public class AngelicaMod { public void preInit(FMLPreInitializationEvent event) { isNEIDLoaded = Loader.isModLoaded("neid"); isOldNEIDLoaded = Loader.isModLoaded("notenoughIDs"); + isChunkAPILoaded = Loader.isModLoaded("chunkapi"); + isEIDBiomeLoaded = Loader.isModLoaded("endlessids_biome"); proxy.preInit(event); } diff --git a/src/main/java/com/gtnewhorizons/angelica/compat/ExtendedBlockStorageExt.java b/src/main/java/com/gtnewhorizons/angelica/compat/ExtendedBlockStorageExt.java index 15993bc9d..28ac40dc8 100644 --- a/src/main/java/com/gtnewhorizons/angelica/compat/ExtendedBlockStorageExt.java +++ b/src/main/java/com/gtnewhorizons/angelica/compat/ExtendedBlockStorageExt.java @@ -1,9 +1,12 @@ package com.gtnewhorizons.angelica.compat; +import com.falsepattern.chunk.api.DataRegistry; import com.gtnewhorizons.angelica.AngelicaMod; import com.gtnewhorizons.angelica.mixins.early.sodium.MixinExtendedBlockStorage; import com.gtnewhorizons.angelica.mixins.interfaces.ExtendedNibbleArray; import com.gtnewhorizons.neid.mixins.interfaces.IExtendedBlockStorageMixin; + +import net.minecraft.world.chunk.Chunk; import net.minecraft.world.chunk.NibbleArray; import net.minecraft.world.chunk.storage.ExtendedBlockStorage; import ru.fewizz.idextender.Hooks; @@ -16,44 +19,51 @@ public class ExtendedBlockStorageExt extends ExtendedBlockStorage { this.hasSky = hasSky; } - public ExtendedBlockStorageExt(ExtendedBlockStorage storage) { + public ExtendedBlockStorageExt(Chunk chunk, ExtendedBlockStorage storage) { super(((MixinExtendedBlockStorage) storage).getYBase(), storage.getSkylightArray() != null); - int arrayLen; - if (AngelicaMod.isNEIDLoaded){ - final short[] block16BArray = ((IExtendedBlockStorageMixin)(Object)this).getBlock16BArray(); - System.arraycopy(((IExtendedBlockStorageMixin)(Object)storage).getBlock16BArray(), 0, block16BArray, 0, block16BArray.length); - if(storage.getBlockMSBArray() != null) { - this.setBlockMSBArray(new NibbleArray(block16BArray.length, 4)); - copyNibbleArray((ExtendedNibbleArray) storage.getBlockMSBArray(), (ExtendedNibbleArray) this.getBlockMSBArray()); + if (AngelicaMod.isChunkAPILoaded) { + if (storage.getSkylightArray() != null) { + hasSky = true; } - arrayLen = block16BArray.length; - } - else if (AngelicaMod.isOldNEIDLoaded){ - final short[] blockLSBArray = Hooks.get(this); - System.arraycopy(Hooks.get(storage), 0, blockLSBArray, 0, blockLSBArray.length); - // getBlockMSBArray is nuked in asm version - arrayLen = blockLSBArray.length; - } - else { - final byte[] blockLSBArray = this.getBlockLSBArray(); - System.arraycopy(storage.getBlockLSBArray(), 0, blockLSBArray, 0, blockLSBArray.length); - if(storage.getBlockMSBArray() != null) { - this.setBlockMSBArray(new NibbleArray(blockLSBArray.length, 4)); - copyNibbleArray((ExtendedNibbleArray) storage.getBlockMSBArray(), (ExtendedNibbleArray) this.getBlockMSBArray()); + DataRegistry.cloneSubChunk(chunk, storage, this); + } else { + int arrayLen; + if (AngelicaMod.isNEIDLoaded){ + final short[] block16BArray = ((IExtendedBlockStorageMixin)(Object)this).getBlock16BArray(); + System.arraycopy(((IExtendedBlockStorageMixin)(Object)storage).getBlock16BArray(), 0, block16BArray, 0, block16BArray.length); + if(storage.getBlockMSBArray() != null) { + this.setBlockMSBArray(new NibbleArray(block16BArray.length, 4)); + copyNibbleArray((ExtendedNibbleArray) storage.getBlockMSBArray(), (ExtendedNibbleArray) this.getBlockMSBArray()); + } + arrayLen = block16BArray.length; + } + else if (AngelicaMod.isOldNEIDLoaded){ + final short[] blockLSBArray = Hooks.get(this); + System.arraycopy(Hooks.get(storage), 0, blockLSBArray, 0, blockLSBArray.length); + // getBlockMSBArray is nuked in asm version + arrayLen = blockLSBArray.length; + } + else { + final byte[] blockLSBArray = this.getBlockLSBArray(); + System.arraycopy(storage.getBlockLSBArray(), 0, blockLSBArray, 0, blockLSBArray.length); + if(storage.getBlockMSBArray() != null) { + this.setBlockMSBArray(new NibbleArray(blockLSBArray.length, 4)); + copyNibbleArray((ExtendedNibbleArray) storage.getBlockMSBArray(), (ExtendedNibbleArray) this.getBlockMSBArray()); + } + arrayLen = blockLSBArray.length; } - arrayLen = blockLSBArray.length; - } - copyNibbleArray((ExtendedNibbleArray) storage.getMetadataArray(), (ExtendedNibbleArray)this.getMetadataArray()); - copyNibbleArray((ExtendedNibbleArray) storage.getBlocklightArray(), (ExtendedNibbleArray)this.getBlocklightArray()); - if(storage.getSkylightArray() != null) { - hasSky = true; - if(this.getSkylightArray() == null) { - this.setSkylightArray(new NibbleArray(arrayLen, 4)); + copyNibbleArray((ExtendedNibbleArray) storage.getMetadataArray(), (ExtendedNibbleArray)this.getMetadataArray()); + copyNibbleArray((ExtendedNibbleArray) storage.getBlocklightArray(), (ExtendedNibbleArray)this.getBlocklightArray()); + if(storage.getSkylightArray() != null) { + hasSky = true; + if(this.getSkylightArray() == null) { + this.setSkylightArray(new NibbleArray(arrayLen, 4)); + } + copyNibbleArray((ExtendedNibbleArray) storage.getSkylightArray(), (ExtendedNibbleArray) this.getSkylightArray()); } - copyNibbleArray((ExtendedNibbleArray) storage.getSkylightArray(), (ExtendedNibbleArray) this.getSkylightArray()); } ((MixinExtendedBlockStorage) this).setBlockRefCount(((MixinExtendedBlockStorage) storage).getBlockRefCount()); } diff --git a/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java b/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java index e47db970c..3ad3052ad 100644 --- a/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java +++ b/src/main/java/me/jellysquid/mods/sodium/client/world/cloned/ClonedChunkSection.java @@ -1,5 +1,7 @@ package me.jellysquid.mods.sodium.client.world.cloned; +import com.falsepattern.endlessids.mixin.helpers.ChunkBiomeHook; +import com.gtnewhorizons.angelica.AngelicaMod; import com.gtnewhorizons.angelica.compat.ExtendedBlockStorageExt; import com.gtnewhorizons.angelica.compat.mojang.BlockPos; import com.gtnewhorizons.angelica.compat.mojang.ChunkSectionPos; @@ -56,9 +58,15 @@ public class ClonedChunkSection { } this.pos = pos; - this.data = new ExtendedBlockStorageExt(section); + this.data = new ExtendedBlockStorageExt(chunk, section); - this.biomeData = new BiomeGenBase[chunk.getBiomeArray().length]; + int bArrLength; + if (AngelicaMod.isEIDBiomeLoaded) { + bArrLength = ((ChunkBiomeHook)chunk).getBiomeShortArray().length; + } else { + bArrLength = chunk.getBiomeArray().length; + } + this.biomeData = new BiomeGenBase[bArrLength]; StructureBoundingBox box = new StructureBoundingBox(pos.getMinX(), pos.getMinY(), pos.getMinZ(), pos.getMaxX(), pos.getMaxY(), pos.getMaxZ());