diff --git a/README.md b/README.md index 8a0fe062..580631d9 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Not yet usable or functional, don't try. -Rewrite of the previous rewrite, targeting NeoForge/MC 1.21.5. +Rewrite of the previous rewrite, targeting NeoForge/MC 1.21.6. This Minecraft mod extends Minecraft height and depth to be nearly infinite (at least a million blocks). @@ -10,7 +10,7 @@ For the most up-to-date information about this mod and its related mods, as well ### Cubic Chunks (CC) - Links: -Github - [Cubic Chunks - 1.21.5 and above](https://github.com/OpenCubicChunks/CubicChunks3) +Github - [Cubic Chunks - 1.21.6 and above](https://github.com/OpenCubicChunks/CubicChunks3) Github - [Cubic Chunks - 1.12.2 and lower](https://github.com/OpenCubicChunks/CubicChunks) ### Cloning the repository diff --git a/gradle.properties b/gradle.properties index abfb9d20..1d625d5d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,20 +6,20 @@ org.gradle.debug=false ## Environment Properties # You can find the latest versions here: https://projects.neoforged.net/neoforged/neoforge # The Minecraft version must agree with the Neo version to get a valid artifact -minecraft_version=1.21.5 +minecraft_version=1.21.6 # The Minecraft version range can use any release version of Minecraft as bounds. # Snapshots, pre-releases, and release candidates are not guaranteed to sort properly # as they do not follow standard versioning conventions. -minecraft_version_range=[1.21.5,1.21.6) +minecraft_version_range=[1.21.6,1.21.7) # The Neo version must agree with the Minecraft version to get a valid artifact -neo_version=21.5.75 +neo_version=21.6.4-beta # The Neo version range can use any version of Neo as bounds -neo_version_range=[21.5,) +neo_version_range=[21.6,) # The loader version range can only use the major version of FML as bounds loader_version_range=[4,) parchment_minecraft_version=1.21.5 -parchment_mappings_version=2025.04.19 +parchment_mappings_version=2025.06.15 ## Mod Properties diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/CCSectionCopy.java b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/CCSectionCopy.java new file mode 100644 index 00000000..ad6c46c2 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/CCSectionCopy.java @@ -0,0 +1,16 @@ +package io.github.opencubicchunks.cubicchunks.client.renderer.chunk; + +import io.github.notstirred.dasm.api.annotations.Dasm; +import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet; +import io.github.opencubicchunks.cubicchunks.util.asm.FactoryFromConstructor; +import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube; +import net.minecraft.client.renderer.chunk.SectionCopy; + +@Dasm(ChunkToCubeSet.class) +public interface CCSectionCopy { + // Factory method for constructor that's added to SectionCopy by DASM + @FactoryFromConstructor + static SectionCopy cc_create(LevelCube wrapped, int sectionIndex) { + throw new IllegalStateException("FactoryFromConstructor failed to apply"); + } +} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/package-info.java b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/package-info.java similarity index 74% rename from src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/package-info.java rename to src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/package-info.java index a0663100..982a3f6d 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/package-info.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/package-info.java @@ -1,6 +1,6 @@ @ParametersAreNonnullByDefault @MethodsReturnNonnullByDefault -package io.github.opencubicchunks.cubicchunks.client.renderer.cube; +package io.github.opencubicchunks.cubicchunks.client.renderer.chunk; import javax.annotation.ParametersAreNonnullByDefault; diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/CubicRenderRegionCache.java b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/CubicRenderRegionCache.java deleted file mode 100644 index fdb504a8..00000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/CubicRenderRegionCache.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.github.opencubicchunks.cubicchunks.client.renderer.cube; - -import javax.annotation.Nullable; - -import net.minecraft.core.SectionPos; -import net.minecraft.world.level.Level; - -public interface CubicRenderRegionCache { - @Nullable RenderCubeRegion cc_createRegion(Level level, SectionPos sectionPos, boolean nullForEmpty); -} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCube.java b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCube.java deleted file mode 100644 index c7dfd5b4..00000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCube.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.github.opencubicchunks.cubicchunks.client.renderer.cube; - -import io.github.notstirred.dasm.api.annotations.selector.Ref; -import io.github.notstirred.dasm.api.annotations.transform.TransformFromClass; -import io.github.opencubicchunks.cubicchunks.exception.DasmFailedToApply; -import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet; -import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube; -import net.minecraft.client.renderer.chunk.RenderChunk; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.LevelChunk; - -/** - * The vanilla {@link RenderChunk} wraps a {@link LevelChunk} and is used to get data for rendering that chunk. - * Similarly, {@code RenderCube} wraps a {@link LevelCube} and is used to get data for rendering that cube. - */ -// Whole class redirect -@TransformFromClass(value = @Ref(RenderChunk.class), sets = ChunkToCubeSet.class) -public class RenderCube { - // Methods copied by DASM - public RenderCube(LevelCube wrapped) { - throw new DasmFailedToApply(); - } - - public native BlockEntity getBlockEntity(BlockPos pos); - - // This method is modified with mixin - public native BlockState getBlockState(BlockPos pos); -} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCubeRegion.java b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCubeRegion.java deleted file mode 100644 index d955ff90..00000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCubeRegion.java +++ /dev/null @@ -1,63 +0,0 @@ -package io.github.opencubicchunks.cubicchunks.client.renderer.cube; - -import javax.annotation.Nullable; - -import io.github.opencubicchunks.cc_core.utils.Coords; -import net.minecraft.client.renderer.chunk.RenderChunk; -import net.minecraft.client.renderer.chunk.RenderChunkRegion; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.chunk.LevelChunkSection; -import net.minecraft.world.level.material.FluidState; - -/** - * The vanilla {@link RenderChunkRegion} stores a 3x3 of {@link RenderChunk}s and is used to get data for rendering a single {@link LevelChunkSection} - * in the center of the 3x3. - * Similarly, {@code RenderCubeRegion} stores a 3x3x3 of {@link RenderCube}s and is used to get data for rendering a single {@link LevelChunkSection} - * in the center of the 3x3x3. - */ -public class RenderCubeRegion extends RenderChunkRegion { - private static final int DIAMETER = 3; - private static final int DIAMETER_SQUARED = DIAMETER * DIAMETER; - public static final int CUBE_COUNT = DIAMETER * DIAMETER * DIAMETER; - - private final int minCubeX; - private final int minCubeY; - private final int minCubeZ; - protected final RenderCube[] cubes; - - public RenderCubeRegion( - Level level, int minCubeX, int minCubeY, int minCubeZ, RenderCube[] cubes, - @Nullable it.unimi.dsi.fastutil.longs.Long2ObjectFunction modelDataSnapshot - ) { - super(level, 0, 0, null); - // TODO set modelDataManager on parent - requires an accessor mixin since we can't AT the NF constructor or field - this.minCubeX = minCubeX; - this.minCubeY = minCubeY; - this.minCubeZ = minCubeZ; - this.cubes = cubes; - } - - @Override public BlockState getBlockState(BlockPos pos) { - return this.getCube(Coords.blockToCube(pos.getX()), Coords.blockToCube(pos.getY()), Coords.blockToCube(pos.getZ())).getBlockState(pos); - } - - @Override public FluidState getFluidState(BlockPos pos) { - return this.getCube(Coords.blockToCube(pos.getX()), Coords.blockToCube(pos.getY()), Coords.blockToCube(pos.getZ())).getBlockState(pos) - .getFluidState(); - } - - @Override public @Nullable BlockEntity getBlockEntity(BlockPos pos) { - return this.getCube(Coords.blockToCube(pos.getX()), Coords.blockToCube(pos.getY()), Coords.blockToCube(pos.getZ())).getBlockEntity(pos); - } - - private RenderCube getCube(int cubeX, int cubeY, int cubeZ) { - return this.cubes[index(this.minCubeX, this.minCubeY, this.minCubeZ, cubeX, cubeY, cubeZ)]; - } - - public static int index(int minCubeX, int minCubeY, int minCubeZ, int cubeX, int cubeY, int cubeZ) { - return cubeX - minCubeX + (cubeZ - minCubeZ) * DIAMETER + (cubeY - minCubeY) * DIAMETER_SQUARED; - } -} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderRegionCacheCubeInfo.java b/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderRegionCacheCubeInfo.java deleted file mode 100644 index cd19b1f7..00000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderRegionCacheCubeInfo.java +++ /dev/null @@ -1,24 +0,0 @@ -package io.github.opencubicchunks.cubicchunks.client.renderer.cube; - -import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddMethodToSets; -import io.github.notstirred.dasm.api.annotations.selector.MethodSig; -import io.github.notstirred.dasm.api.annotations.selector.Ref; -import io.github.notstirred.dasm.api.annotations.transform.TransformFromClass; -import io.github.opencubicchunks.cubicchunks.exception.DasmFailedToApply; -import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet; -import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube; - -// Cubic equivalent to RenderRegionCache$ChunkInfo, since we can't add inner classes with mixin -// Whole class redirect -@TransformFromClass(value = @Ref(string = "net.minecraft.client.renderer.chunk.RenderRegionCache$ChunkInfo"), sets = ChunkToCubeSet.class) -public class RenderRegionCacheCubeInfo { - public RenderRegionCacheCubeInfo(LevelCube cube) { - throw new DasmFailedToApply(); - } - - @AddMethodToSets(containers = ChunkToCubeSet.RenderRegionCache$ChunkInfo_to_RenderRegionCacheCubeInfo_redirects.class, method = @MethodSig("chunk()Lnet/minecraft/world/level/chunk/LevelChunk;")) - public native LevelCube cube(); - - @AddMethodToSets(containers = ChunkToCubeSet.RenderRegionCache$ChunkInfo_to_RenderRegionCacheCubeInfo_redirects.class, method = @MethodSig("renderChunk()Lnet/minecraft/client/renderer/chunk/RenderChunk;")) - public native RenderCube renderCube(); -} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinCCSectionCopy.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinCCSectionCopy.java new file mode 100644 index 00000000..ea71280a --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinCCSectionCopy.java @@ -0,0 +1,8 @@ +package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.chunk; + +import io.github.opencubicchunks.cubicchunks.client.renderer.chunk.CCSectionCopy; +import org.spongepowered.asm.mixin.Mixin; + +// Needed for FactoryFromConstructor to apply +@Mixin(CCSectionCopy.class) +public interface MixinCCSectionCopy {} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinRenderRegionCache.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinRenderRegionCache.java index 6a2e4b6e..18413ac8 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinRenderRegionCache.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinRenderRegionCache.java @@ -1,73 +1,41 @@ package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.chunk; -import javax.annotation.Nullable; - -import io.github.opencubicchunks.cc_core.api.CubePos; import io.github.opencubicchunks.cc_core.utils.Coords; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.CubicRenderRegionCache; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCube; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCubeRegion; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderRegionCacheCubeInfo; +import io.github.opencubicchunks.cubicchunks.CanBeCubic; +import io.github.opencubicchunks.cubicchunks.client.renderer.chunk.CCSectionCopy; import io.github.opencubicchunks.cubicchunks.world.level.CubicLevel; -import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube; -import it.unimi.dsi.fastutil.longs.Long2ObjectMap; -import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; -import net.minecraft.client.renderer.chunk.RenderChunk; -import net.minecraft.client.renderer.chunk.RenderChunkRegion; import net.minecraft.client.renderer.chunk.RenderRegionCache; +import net.minecraft.client.renderer.chunk.RenderSectionRegion; +import net.minecraft.client.renderer.chunk.SectionCopy; import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.core.SectionPos; import net.minecraft.world.level.Level; -import net.minecraft.world.level.chunk.LevelChunk; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +// TODO rewrite javadoc for 1.21.6 /** - * The vanilla {@link RenderRegionCache} caches {@link LevelChunk}s and {@link RenderChunk}s while rebuilding + * The vanilla {@link RenderRegionCache} caches {@link SectionCopy}s while rebuilding * {@link SectionRenderDispatcher.RenderSection}s - * and has a method for creating a {@link RenderChunkRegion} for a given {@link SectionPos}. + * and has a method for creating a {@link RenderSectionRegion} for a given {@link SectionPos}. *

- * We modify it by additionally caching {@link LevelCube}s and {@link RenderCube}s, and adding an equivalent method to create a - * {@link RenderCubeRegion} for a given {@link SectionPos}. + * We simply modify it to get section data from cubes instead of chunks in cubic levels. */ @Mixin(RenderRegionCache.class) -public abstract class MixinRenderRegionCache implements CubicRenderRegionCache { - @Shadow private final Long2ObjectMap chunkInfoCache = new Long2ObjectOpenHashMap<>(); - - // TODO can we possibly do this with DASM + mixin? probably not? - @Override public @Nullable RenderCubeRegion cc_createRegion(Level level, SectionPos sectionPos, boolean nullForEmpty) { - int centerCubeX = Coords.sectionToCube(sectionPos.getX()); - int centerCubeY = Coords.sectionToCube(sectionPos.getY()); - int centerCubeZ = Coords.sectionToCube(sectionPos.getZ()); - var centerCubeInfo = this.cc_getChunkInfo(level, centerCubeX, centerCubeY, centerCubeZ); -// if (nullForEmpty && centerCubeInfo.cube().isSectionEmpty(sectionPos.y())) { // TODO need a proper isSectionEmpty on CubeAccess -// return null; -// } - int cubeStartX = centerCubeX - 1; - int cubeStartY = centerCubeY - 1; - int cubeStartZ = centerCubeZ - 1; - int cubeEndX = centerCubeX + 1; - int cubeEndY = centerCubeY + 1; - int cubeEndZ = centerCubeZ + 1; - RenderCube[] renderCubes = new RenderCube[RenderCubeRegion.CUBE_COUNT]; - - for (int cubeX = cubeStartX; cubeX <= cubeEndX; ++cubeX) { - for (int cubeY = cubeStartY; cubeY <= cubeEndY; ++cubeY) { - for (int cubeZ = cubeStartZ; cubeZ <= cubeEndZ; ++cubeZ) { - int cubeIndex = RenderCubeRegion.index(cubeStartX, cubeStartY, cubeStartZ, cubeX, cubeY, cubeZ); - var cubeInfo = cubeX == centerCubeX && cubeY == centerCubeY && cubeZ == centerCubeZ ? centerCubeInfo - : this.cc_getChunkInfo(level, cubeX, cubeY, cubeZ); - renderCubes[cubeIndex] = cubeInfo.renderCube(); - } - } +public abstract class MixinRenderRegionCache { + // Note the order of the individual sectionPos axes is weird (x,z,y) due to it being based on usage order within the vanilla lambda + // To avoid brittleness we ignore these parameters and use the captured sectionPos long instead. + @Inject(method = "lambda$getSectionDataCopy$0", at = @At("HEAD"), cancellable = true) + private static void cc_onGetSectionDataCopy( + Level level, int unusedSectionX, int unusedSectionZ, int unusedSectionY, long sectionPosLong, CallbackInfoReturnable cir + ) { + if (((CanBeCubic) level).cc_isCubic()) { + var sectionPos = SectionPos.of(sectionPosLong); + var cube = ((CubicLevel) level).cc_getCube(Coords.sectionToCube(sectionPos.getX()), Coords.sectionToCube(sectionPos.getY()), + Coords.sectionToCube(sectionPos.getZ())); + cir.setReturnValue(CCSectionCopy.cc_create(cube, Coords.sectionToIndex(sectionPos.getX(), sectionPos.getY(), sectionPos.getZ()))); } - - var modelDataManager = level.getModelDataManager().snapshotSectionRegion(cubeStartX, cubeStartY, cubeStartZ, cubeEndX, cubeEndY, cubeEndZ); - return new RenderCubeRegion(level, cubeStartX, cubeStartY, cubeStartZ, renderCubes, modelDataManager); - } - - private RenderRegionCacheCubeInfo cc_getChunkInfo(Level level, int cubeX, int cubeY, int cubeZ) { - return this.chunkInfoCache.computeIfAbsent(CubePos.asLong(cubeX, cubeY, cubeZ), cubePosLong -> new RenderRegionCacheCubeInfo( - ((CubicLevel) level).cc_getCube(CubePos.extractX(cubePosLong), CubePos.extractY(cubePosLong), CubePos.extractZ(cubePosLong)))); } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionCopy.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionCopy.java new file mode 100644 index 00000000..5d5ae755 --- /dev/null +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionCopy.java @@ -0,0 +1,34 @@ +package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.chunk; + +import io.github.notstirred.dasm.api.annotations.Dasm; +import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddFieldToSets; +import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddTransformToSets; +import io.github.notstirred.dasm.api.annotations.selector.FieldSig; +import io.github.notstirred.dasm.api.annotations.selector.MethodSig; +import io.github.notstirred.dasm.api.annotations.selector.Ref; +import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod; +import io.github.opencubicchunks.cubicchunks.exception.DasmFailedToApply; +import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet; +import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube; +import net.minecraft.client.renderer.chunk.SectionCopy; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.world.level.chunk.LevelChunkSection; +import org.spongepowered.asm.mixin.Mixin; + +/** + * The vanilla {@link SectionCopy} stores block data of a {@link LevelChunkSection} and is used for rendering that section. + * We simply add a constructor that creates the {@code SectionCopy} from a cube instead of a chunk. + */ +@Dasm(value = ChunkToCubeSet.class, target = @Ref(SectionCopy.class)) +@Mixin(SectionCopy.class) +public class MixinSectionCopy { + // TODO is this field on the vanilla class actually used anywhere? based on snowblower output not having it, it seems like neoforge is adding it? + @AddFieldToSets(containers = ChunkToCubeSet.SectionCopy_redirects.class, field = @FieldSig(type = @Ref(LevelChunk.class), name = "wrapped")) + final LevelCube cc_wrapped; + + @AddTransformToSets(ChunkToCubeSet.SectionCopy_redirects.class) + @TransformFromMethod(@MethodSig("(Lnet/minecraft/world/level/chunk/LevelChunk;I)V")) + public MixinSectionCopy(LevelCube wrapped, int sectionIndex) { + throw new DasmFailedToApply(); + } +} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionRenderDispatcher$RenderSection.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionRenderDispatcher$RenderSection.java index f44c4ccd..98622e26 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionRenderDispatcher$RenderSection.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionRenderDispatcher$RenderSection.java @@ -1,20 +1,11 @@ package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.chunk; -import javax.annotation.Nullable; - -import com.llamalad7.mixinextras.injector.wrapoperation.Operation; -import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import io.github.opencubicchunks.cc_core.utils.Coords; import io.github.opencubicchunks.cubicchunks.CanBeCubic; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.CubicRenderRegionCache; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCubeRegion; import io.github.opencubicchunks.cubicchunks.mixin.access.client.SectionRenderDispatcherAccess; import io.github.opencubicchunks.cubicchunks.world.level.CubicLevel; -import net.minecraft.client.renderer.chunk.RenderChunkRegion; -import net.minecraft.client.renderer.chunk.RenderRegionCache; import net.minecraft.client.renderer.chunk.SectionRenderDispatcher; import net.minecraft.core.SectionPos; -import net.minecraft.world.level.Level; import net.minecraft.world.level.chunk.LevelChunkSection; import net.minecraft.world.level.chunk.status.ChunkStatus; import org.spongepowered.asm.mixin.Final; @@ -26,13 +17,12 @@ /** * {@code RenderSection} represents a single {@link LevelChunkSection} to be rendered. - * We modify it to check cubes instead of chunks when validating the presence of neighboring sections in cubic levels, and to use - * {@link RenderCubeRegion} instead of {@link RenderChunkRegion}. + * We modify it to check cubes instead of chunks when validating the presence of neighboring sections in cubic levels. */ @Mixin(SectionRenderDispatcher.RenderSection.class) public abstract class MixinSectionRenderDispatcher$RenderSection { @Shadow @Final SectionRenderDispatcher this$0; - @Shadow private volatile long sectionNode; + @Shadow volatile long sectionNode; @Shadow protected abstract boolean doesChunkExistAt(long sectionPosLong); @@ -51,7 +41,7 @@ private void cc_onDoesChunkExistAt(long sectionPosLong, CallbackInfoReturnable cir) { if (!((CanBeCubic) ((SectionRenderDispatcherAccess) this$0).cc_getLevel()).cc_isCubic()) { return; @@ -71,18 +61,4 @@ private void cc_onHasAllNeighbors(CallbackInfoReturnable cir) { } cir.setReturnValue(true); } - - /** - * Wrap creation of RenderChunkRegion to create a RenderCubeRegion in cubic worlds (return type stays the same because RenderCubeRegion extends - * RenderChunkRegion) - */ - @WrapOperation(method = "createCompileTask", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/chunk/RenderRegionCache;createRegion(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/SectionPos;Z)Lnet/minecraft/client/renderer/chunk/RenderChunkRegion;")) - private @Nullable RenderChunkRegion cc_onCreateCompileTask_createRegion( - RenderRegionCache instance, Level level, SectionPos sectionPos, boolean bool, Operation original - ) { - if (!((CanBeCubic) ((SectionRenderDispatcherAccess) this$0).cc_getLevel()).cc_isCubic()) { - return original.call(instance, level, sectionPos, bool); - } - return ((CubicRenderRegionCache) instance).cc_createRegion(level, sectionPos, bool); - } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/MixinRenderCube.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/MixinRenderCube.java deleted file mode 100644 index 00eb0ac9..00000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/MixinRenderCube.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.cube; - -import io.github.opencubicchunks.cc_core.utils.Coords; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCube; -import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube; -import net.minecraft.core.BlockPos; -import org.spongepowered.asm.mixin.Dynamic; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -// Needed for DASM to apply -@Mixin(RenderCube.class) -public abstract class MixinRenderCube { - /** - * Redirect to use cube section indexing instead of chunk section indexing - */ - @Dynamic @Redirect(method = "getBlockState", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cubicchunks/world/level/cube/LevelCube;getSectionIndex(I)I")) - private int cc_onGetBlockState_SectionIndex(LevelCube instance, int y, BlockPos pos) { - return Coords.blockToIndex(pos); - } -} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/MixinRenderRegionCacheCubeInfo.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/MixinRenderRegionCacheCubeInfo.java deleted file mode 100644 index f56fc24c..00000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/MixinRenderRegionCacheCubeInfo.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.cube; - -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderRegionCacheCubeInfo; -import org.spongepowered.asm.mixin.Mixin; - -// Needed for DASM to apply -@Mixin(RenderRegionCacheCubeInfo.class) -public abstract class MixinRenderRegionCacheCubeInfo {} diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/package-info.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/package-info.java deleted file mode 100644 index 6805c4cb..00000000 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/cube/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -@ParametersAreNonnullByDefault -@MethodsReturnNonnullByDefault -package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.cube; - -import javax.annotation.ParametersAreNonnullByDefault; - -import io.github.opencubicchunks.cc_core.annotation.MethodsReturnNonnullByDefault; diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/level/MixinServerLevel.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/level/MixinServerLevel.java index b4fc9412..cc5c834f 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/level/MixinServerLevel.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/level/MixinServerLevel.java @@ -96,6 +96,8 @@ public void cc_tickCube(LevelCube levelCube, int randomTickSpeed) { // TODO (P2) cube ticking } + // TODO (P2) waitForChunkAndEntities + // TODO: comments below don't account for 1.20.4->1.21.5 changes; will need to check for other methods that need CC changes // TODO: phase 3 - isNaturalSpawningAllowed diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/network/MixinPlayerChunkSender.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/network/MixinPlayerChunkSender.java index 35571df7..2d0f6a7b 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/network/MixinPlayerChunkSender.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/network/MixinPlayerChunkSender.java @@ -76,7 +76,7 @@ private void cc_onSendNextChunks(ServerPlayer player, CallbackInfo ci) { this.batchQuota = Math.min(this.batchQuota + this.desiredChunksPerTick, f); if (!(this.batchQuota < 1.0F)) { if (!this.pendingChunks.isEmpty()) { - ServerLevel serverlevel = player.serverLevel(); + ServerLevel serverlevel = player.level(); ChunkMap chunkmap = serverlevel.getChunkSource().chunkMap; List list = this.cc_collectChunksToSend(chunkmap, CloPos.cube(((EntityCubePosGetter) player).cc_cubePosition())); if (!list.isEmpty()) { diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/dasmsets/ChunkToCubeSet.java b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/dasmsets/ChunkToCubeSet.java index 32e38e63..3180ed31 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/dasmsets/ChunkToCubeSet.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/mixin/dasmsets/ChunkToCubeSet.java @@ -19,8 +19,6 @@ import io.github.notstirred.dasm.api.annotations.selector.Ref; import io.github.opencubicchunks.cc_core.api.CubePos; import io.github.opencubicchunks.cubicchunks.client.multiplayer.ClientCubeCache; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCube; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderRegionCacheCubeInfo; import io.github.opencubicchunks.cubicchunks.movetoforgesourcesetlater.CCCommonHooks; import io.github.opencubicchunks.cubicchunks.movetoforgesourcesetlater.EventConstructorDelegates; import io.github.opencubicchunks.cubicchunks.server.level.CubeHolder; @@ -39,7 +37,7 @@ import net.minecraft.client.multiplayer.ClientChunkCache; import net.minecraft.client.renderer.LevelRenderer; import net.minecraft.client.renderer.SectionOcclusionGraph; -import net.minecraft.client.renderer.chunk.RenderChunk; +import net.minecraft.client.renderer.chunk.SectionCopy; import net.minecraft.server.level.ChunkGenerationTask; import net.minecraft.server.level.ChunkHolder; import net.minecraft.server.level.ChunkLevel; @@ -111,6 +109,11 @@ abstract class ChunkAccess_to_CubeAccess_redirects { public native CubePos cc_getCubePos(); } + @TypeRedirect(from = @Ref(string = "net.minecraft.world.level.chunk.ChunkAccess$ChunkPathElement"), to = @Ref(string = "io.github.opencubicchunks.cubicchunks.world.level.cube.CubeAccess$CubePathElement")) + abstract class ChunkAccess$ChunkPathElement_to_CubeAccess$CubePathElement_redirects { + + } + @TypeRedirect(from = @Ref(LevelChunk.class), to = @Ref(LevelCube.class)) abstract class LevelChunk_to_LevelCube_redirects { @FieldRedirect(@FieldSig(type = @Ref(ChunkPos.class), name = "chunkPos")) @@ -139,12 +142,6 @@ abstract class ImposterProtoChunk_to_ImposterProtoCube_redirects {} abstract class EmptyLevelChunk_to_EmptyLevelCube_redirects {} // FIXME probably need to move to a client-only set - @TypeRedirect(from = @Ref(RenderChunk.class), to = @Ref(RenderCube.class)) - abstract class RenderChunk_to_RenderCube_redirects {} - - @TypeRedirect(from = @Ref(string = "net.minecraft.client.renderer.chunk.RenderRegionCache$ChunkInfo"), to = @Ref(RenderRegionCacheCubeInfo.class)) - abstract class RenderRegionCache$ChunkInfo_to_RenderRegionCacheCubeInfo_redirects {} - @TypeRedirect(from = @Ref(ClientChunkCache.Storage.class), to = @Ref(ClientCubeCache.Storage.class)) abstract class ClientChunkCache$Storage_to_ClientCubeCache$Storage_redirects {} @@ -267,4 +264,7 @@ class ServerLevel_redirects extends Level_redirects {} @IntraOwnerContainer(@Ref(LevelRenderer.class)) class LevelRenderer_redirects {} + + @IntraOwnerContainer(@Ref(SectionCopy.class)) + class SectionCopy_redirects {} } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/network/CCClientboundLevelCubePacketData.java b/src/main/java/io/github/opencubicchunks/cubicchunks/network/CCClientboundLevelCubePacketData.java index 5365c030..00824dcb 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/network/CCClientboundLevelCubePacketData.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/network/CCClientboundLevelCubePacketData.java @@ -63,10 +63,15 @@ private static int calculateChunkSize(LevelCube cube) { return i; } + // TODO could dasm-copy this from ClientboundLevelChunkPacketData public static void extractChunkData(FriendlyByteBuf buffer, LevelCube cube) { for (LevelChunkSection levelchunksection : cube.getSections()) { levelchunksection.write(buffer); } + + if (buffer.writerIndex() != buffer.capacity()) { + throw new IllegalStateException("Didn't fill cube buffer: expected " + buffer.capacity() + " bytes, got " + buffer.writerIndex()); + } } public FriendlyByteBuf getReadBuffer() { diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunk/status/CCChunkStatusTasks.java b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunk/status/CCChunkStatusTasks.java index 1958572d..54a36ee7 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunk/status/CCChunkStatusTasks.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunk/status/CCChunkStatusTasks.java @@ -1,17 +1,18 @@ package io.github.opencubicchunks.cubicchunks.world.level.chunk.status; -import java.util.List; import java.util.concurrent.CompletableFuture; +import com.mojang.logging.LogUtils; import io.github.notstirred.dasm.api.annotations.Dasm; +import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddFieldToSets; import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddMethodToSets; import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddTransformToSets; +import io.github.notstirred.dasm.api.annotations.selector.FieldSig; import io.github.notstirred.dasm.api.annotations.selector.MethodSig; import io.github.notstirred.dasm.api.annotations.selector.Ref; import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod; import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkInCubicContextSet; import io.github.opencubicchunks.cubicchunks.world.level.cube.status.CubeStatusTasks; -import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.GenerationChunkHolder; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.StaticCache2D; @@ -19,6 +20,8 @@ import net.minecraft.world.level.chunk.status.ChunkStatusTasks; import net.minecraft.world.level.chunk.status.ChunkStep; import net.minecraft.world.level.chunk.status.WorldGenContext; +import net.minecraft.world.level.storage.ValueInput; +import org.slf4j.Logger; /** * Equivalent of {@link ChunkStatusTasks} for chunks in cubic worlds. @@ -29,6 +32,9 @@ public class CCChunkStatusTasks { private CCChunkStatusTasks() {} + @AddFieldToSets(containers = ChunkInCubicContextSet.ChunkStatusTasks_to_CCChunkStatusTasks_redirects.class, field = @FieldSig(type = @Ref(Logger.class), name = "LOGGER")) + private static final Logger LOGGER = LogUtils.getLogger(); + @AddTransformToSets(ChunkInCubicContextSet.ChunkStatusTasks_to_CCChunkStatusTasks_redirects.class) @TransformFromMethod(owner = @Ref(ChunkStatusTasks.class), value = @MethodSig("isLighted(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z")) private static native boolean isLighted(ChunkAccess chunk); @@ -125,8 +131,8 @@ public static native CompletableFuture full( WorldGenContext worldGenContext, ChunkStep step, StaticCache2D cache, ChunkAccess chunk ); - @AddMethodToSets(containers = ChunkInCubicContextSet.ChunkStatusTasks_to_CCChunkStatusTasks_redirects.class, method = @MethodSig("postLoadProtoChunk(Lnet/minecraft/server/level/ServerLevel;Ljava/util/List;)V")) - private static void postLoadProtoChunk(ServerLevel level, List entityTags) { + @AddMethodToSets(containers = ChunkInCubicContextSet.ChunkStatusTasks_to_CCChunkStatusTasks_redirects.class, method = @MethodSig("postLoadProtoChunk(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/storage/ValueInput$ValueInputList;)V")) + private static void postLoadProtoChunk(ServerLevel level, ValueInput.ValueInputList entityTags) { // Entities should be handled on the cube, not the chunk } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunklike/CloAccess.java b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunklike/CloAccess.java index 2abb95d6..5050ffef 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunklike/CloAccess.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/chunklike/CloAccess.java @@ -15,6 +15,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.core.HolderLookup; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.LevelHeightAccessor; @@ -155,6 +156,8 @@ void findBlocks( void initializeLightSources(); + ProblemReporter.PathElement problemPath(); + // TODO static methods // static ShortList getOrCreateOffsetList(ShortList[] p_62096_, int p_62097_); // diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/CubeAccess.java b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/CubeAccess.java index 735deced..91b3ea52 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/CubeAccess.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/CubeAccess.java @@ -29,6 +29,7 @@ import net.minecraft.core.Registry; import net.minecraft.core.SectionPos; import net.minecraft.nbt.CompoundTag; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.LevelHeightAccessor; import net.minecraft.world.level.biome.Biome; @@ -357,4 +358,18 @@ public CubePos cc_getCubePos() { @Override public ChunkSkyLightSources getSkyLightSources() { throw new UnsupportedOperationException(); // TODO P2 } + + public static ProblemReporter.PathElement problemPath(CubePos cubePos) { + return new CubePathElement(cubePos); + } + + public ProblemReporter.PathElement problemPath() { + return problemPath(this.cc_getCubePos()); + } + + record CubePathElement(CubePos pos) implements ProblemReporter.PathElement { + @Override public String get() { + return "cube@" + this.pos; + } + } } diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/LevelCube.java b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/LevelCube.java index 0086de8c..989e82f8 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/LevelCube.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/LevelCube.java @@ -34,6 +34,7 @@ import net.minecraft.network.protocol.game.ClientboundLevelChunkPacketData; import net.minecraft.server.level.FullChunkStatus; import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.ProblemReporter; import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseRailBlock; @@ -54,6 +55,7 @@ import net.minecraft.world.level.lighting.LightEngine; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.level.storage.TagValueInput; import net.minecraft.world.ticks.LevelChunkTicks; import net.minecraft.world.ticks.TickContainerAccess; import org.jetbrains.annotations.NotNull; @@ -313,6 +315,7 @@ public void setUnsavedListener(LevelCube.UnsavedListener unsavedListener) { @TransformFromMethod(value = @MethodSig("isEmpty()Z"), owner = @Ref(LevelChunk.class)) public native boolean isEmpty(); + // TODO this should maybe be dasm + mixin, there's a lot of vanilla code duplication here public void replaceWithPacketData( FriendlyByteBuf buffer, Map map, Consumer outputTagConsumer ) { @@ -326,12 +329,15 @@ public void replaceWithPacketData( // TODO (P2) lighting // this.initializeLightSources(); - outputTagConsumer.accept((pos, blockEntityType, tag) -> { - BlockEntity blockentity = this.getBlockEntity(pos, LevelChunk.EntityCreationType.IMMEDIATE); - if (blockentity != null && tag != null && blockentity.getType() == blockEntityType) { - blockentity.loadWithComponents(tag, this.level.registryAccess()); - } - }); + try (ProblemReporter.ScopedCollector problemreporter$scopedcollector = new ProblemReporter.ScopedCollector(this.problemPath(), LOGGER)) { + outputTagConsumer.accept((pos, blockEntityType, tag) -> { + BlockEntity blockentity = this.getBlockEntity(pos, LevelChunk.EntityCreationType.IMMEDIATE); + if (blockentity != null && tag != null && blockentity.getType() == blockEntityType) { + blockentity.handleUpdateTag(TagValueInput.create(problemreporter$scopedcollector.forChild(blockentity.problemPath()), + this.level.registryAccess(), tag)); + } + }); + } } @TransformFromMethod(value = @MethodSig("replaceBiomes(Lnet/minecraft/network/FriendlyByteBuf;)V"), owner = @Ref(LevelChunk.class)) diff --git a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/status/CubeStatusTasks.java b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/status/CubeStatusTasks.java index eb89c007..f811067e 100644 --- a/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/status/CubeStatusTasks.java +++ b/src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/status/CubeStatusTasks.java @@ -1,11 +1,13 @@ package io.github.opencubicchunks.cubicchunks.world.level.cube.status; -import java.util.List; import java.util.concurrent.CompletableFuture; +import com.mojang.logging.LogUtils; import io.github.notstirred.dasm.api.annotations.Dasm; +import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddFieldToSets; import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddMethodToSets; import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddTransformToSets; +import io.github.notstirred.dasm.api.annotations.selector.FieldSig; import io.github.notstirred.dasm.api.annotations.selector.MethodSig; import io.github.notstirred.dasm.api.annotations.selector.Ref; import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod; @@ -16,12 +18,13 @@ import io.github.opencubicchunks.cubicchunks.world.level.chunk.status.CCChunkStatusTasks; import io.github.opencubicchunks.cubicchunks.world.level.cube.CubeAccess; import net.minecraft.core.BlockPos; -import net.minecraft.nbt.CompoundTag; import net.minecraft.server.level.GenerationChunkHolder; import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.chunk.status.ChunkStatusTasks; import net.minecraft.world.level.chunk.status.WorldGenContext; +import net.minecraft.world.level.storage.ValueInput; +import org.slf4j.Logger; /** * Equivalent of {@link ChunkStatusTasks} for cube generation. @@ -32,6 +35,9 @@ public class CubeStatusTasks { private CubeStatusTasks() {} + @AddFieldToSets(containers = ChunkToCubeSet.ChunkStatusTasks_to_CubeStatusTasks_redirects.class, field = @FieldSig(type = @Ref(Logger.class), name = "LOGGER")) + private static final Logger LOGGER = LogUtils.getLogger(); + @AddTransformToSets(ChunkToCubeSet.ChunkStatusTasks_to_CubeStatusTasks_redirects.class) @TransformFromMethod(owner = @Ref(ChunkStatusTasks.class), value = @MethodSig("isLighted(Lnet/minecraft/world/level/chunk/ChunkAccess;)Z")) private static native boolean isLighted(CubeAccess cube); @@ -149,6 +155,6 @@ public static native CompletableFuture full( ); @AddTransformToSets(ChunkToCubeSet.ChunkStatusTasks_to_CubeStatusTasks_redirects.class) - @TransformFromMethod(owner = @Ref(ChunkStatusTasks.class), value = @MethodSig("postLoadProtoChunk(Lnet/minecraft/server/level/ServerLevel;Ljava/util/List;)V")) - private static native void postLoadProtoCube(ServerLevel level, List entityTags); + @TransformFromMethod(owner = @Ref(ChunkStatusTasks.class), value = @MethodSig("postLoadProtoChunk(Lnet/minecraft/server/level/ServerLevel;Lnet/minecraft/world/level/storage/ValueInput$ValueInputList;)V")) + private static native void postLoadProtoCube(ServerLevel level, ValueInput.ValueInputList entityTags); } diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index e795ba96..e252eafa 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -12,12 +12,7 @@ public net.minecraft.world.level.levelgen.VerticalAnchor$AboveBottom public net.minecraft.world.level.levelgen.VerticalAnchor$Absolute public net.minecraft.world.level.lighting.SkyLightSectionStorage$SkyDataLayerStorageMap public net.minecraft.world.ticks.LevelTicks$PosAndContainerConsumer -public net.minecraft.client.renderer.chunk.RenderChunk -# TODO ATing RenderChunk is unnecessary if we can make the DASM-transformed constructor widen access instead -public net.minecraft.client.renderer.chunk.RenderChunk (Lnet/minecraft/world/level/chunk/LevelChunk;)V -public net.minecraft.client.renderer.chunk.RenderChunkRegion (Lnet/minecraft/world/level/Level;II[Lnet/minecraft/client/renderer/chunk/RenderChunk;)V -# TODO ATing RenderRegionCache$ChunkInfo is unnecessary if we can make the DASM-transformed constructor widen access instead -public net.minecraft.client.renderer.chunk.RenderRegionCache$ChunkInfo (Lnet/minecraft/world/level/chunk/LevelChunk;)V +public net.minecraft.client.renderer.chunk.SectionCopy public net.minecraft.client.renderer.SectionOcclusionGraph$GraphEvents # since SectionOcclusionGraph$GraphEvents is a record, NeoForge requires that we widen its constructor as well public net.minecraft.client.renderer.SectionOcclusionGraph$GraphEvents (Lit/unimi/dsi/fastutil/longs/LongSet;Ljava/util/concurrent/BlockingQueue;)V diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/test/client/renderer/cube/TestRenderCubeRegion.java b/src/test/java/io/github/opencubicchunks/cubicchunks/test/client/renderer/cube/TestRenderCubeRegion.java deleted file mode 100644 index 8a47ff1b..00000000 --- a/src/test/java/io/github/opencubicchunks/cubicchunks/test/client/renderer/cube/TestRenderCubeRegion.java +++ /dev/null @@ -1,85 +0,0 @@ -package io.github.opencubicchunks.cubicchunks.test.client.renderer.cube; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.mock; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Random; -import java.util.Set; - -import io.github.opencubicchunks.cc_core.api.CubePos; -import io.github.opencubicchunks.cc_core.api.CubicConstants; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCube; -import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCubeRegion; -import io.github.opencubicchunks.cubicchunks.testutils.BaseTest; -import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Blocks; -import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.block.state.properties.BlockStateProperties; -import net.minecraft.world.level.material.Fluids; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.mockito.Answers; - -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -public class TestRenderCubeRegion extends BaseTest { - // These two tests are mostly just a copy of the tests in TestLevelCube - private void singleCubeGetBlockState(Random random) { - CubePos cubePos = CubePos.of(random.nextInt(20000) - 10000, random.nextInt(20000) - 10000, random.nextInt(20000) - 10000); - Level levelMock = mock(Answers.RETURNS_DEEP_STUBS); - var cube = new LevelCube(levelMock, cubePos); - Map states = new HashMap<>(); - for (int i = 0; i < 1000; i++) { - var pos = cubePos.asBlockPos(random.nextInt(CubicConstants.DIAMETER_IN_BLOCKS), random.nextInt(CubicConstants.DIAMETER_IN_BLOCKS), - random.nextInt(CubicConstants.DIAMETER_IN_BLOCKS)); - var state = random.nextBoolean() ? Blocks.STONE.defaultBlockState() : Blocks.DIRT.defaultBlockState(); - states.put(pos, state); - cube.setBlockState(pos, state); - } - var arr = new RenderCube[27]; - arr[RenderCubeRegion.index(-1, -1, -1, 0, 0, 0)] = new RenderCube(cube); - var renderCubeRegion = new RenderCubeRegion(levelMock, cubePos.getX() - 1, cubePos.getY() - 1, cubePos.getZ() - 1, arr, null); - - for (var pos : states.keySet()) { - assertEquals(states.get(pos), renderCubeRegion.getBlockState(pos)); - } - } - - private void singleCubeGetFluidState(Random random) { - CubePos cubePos = CubePos.of(random.nextInt(20000) - 10000, random.nextInt(20000) - 10000, random.nextInt(20000) - 10000); - Level levelMock = mock(Answers.RETURNS_DEEP_STUBS); - var cube = new LevelCube(levelMock, cubePos); - Set positions = new HashSet<>(); - var state = Blocks.ANDESITE_SLAB.defaultBlockState().setValue(BlockStateProperties.WATERLOGGED, true); - for (int i = 0; i < 100; i++) { - var pos = cubePos.asBlockPos(random.nextInt(CubicConstants.DIAMETER_IN_BLOCKS), random.nextInt(CubicConstants.DIAMETER_IN_BLOCKS), - random.nextInt(CubicConstants.DIAMETER_IN_BLOCKS)); - positions.add(pos); - cube.setBlockState(pos, state); - } - - var arr = new RenderCube[27]; - arr[RenderCubeRegion.index(-1, -1, -1, 0, 0, 0)] = new RenderCube(cube); - var renderCubeRegion = new RenderCubeRegion(levelMock, cubePos.getX() - 1, cubePos.getY() - 1, cubePos.getZ() - 1, arr, null); - - for (var pos : positions) { - assertEquals(state, renderCubeRegion.getBlockState(pos)); - assertEquals(Fluids.WATER.getSource(false), renderCubeRegion.getFluidState(pos)); - } - } - - @Disabled // TODO disabled until we can apply client-side mixins in tests properly - @Test - public void testSingleCubeGetBlockAndFluidState() { - var random = new Random(-511); - for (int i = 0; i < 100; i++) { - singleCubeGetBlockState(random); - singleCubeGetFluidState(random); - } - } -} diff --git a/src/test/java/io/github/opencubicchunks/cubicchunks/test/client/renderer/cube/package-info.java b/src/test/java/io/github/opencubicchunks/cubicchunks/test/client/renderer/cube/package-info.java deleted file mode 100644 index 282687eb..00000000 --- a/src/test/java/io/github/opencubicchunks/cubicchunks/test/client/renderer/cube/package-info.java +++ /dev/null @@ -1,7 +0,0 @@ -@ParametersAreNonnullByDefault -@MethodsReturnNonnullByDefault -package io.github.opencubicchunks.cubicchunks.test.client.renderer.cube; - -import javax.annotation.ParametersAreNonnullByDefault; - -import io.github.opencubicchunks.cc_core.annotation.MethodsReturnNonnullByDefault;