Skip to content

Commit 5c34aa8

Browse files
CursedFlamesNotStirred
authored andcommitted
port to 1.21.6
1 parent bcc62ce commit 5c34aa8

26 files changed

Lines changed: 155 additions & 371 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
## Not yet usable or functional, don't try.
44

5-
Rewrite of the previous rewrite, targeting NeoForge/MC 1.21.5.
5+
Rewrite of the previous rewrite, targeting NeoForge/MC 1.21.6.
66

77
This Minecraft mod extends Minecraft height and depth to be nearly infinite (at least a million blocks).
88

99
For the most up-to-date information about this mod and its related mods, as well as the newest downloads, please join us on the [**Cubic Chunks Discord**](https://discord.gg/kMfWg9m).
1010

1111
### Cubic Chunks (CC) - Links:
1212

13-
Github - [Cubic Chunks - 1.21.5 and above](https://github.com/OpenCubicChunks/CubicChunks3)
13+
Github - [Cubic Chunks - 1.21.6 and above](https://github.com/OpenCubicChunks/CubicChunks3)
1414
Github - [Cubic Chunks - 1.12.2 and lower](https://github.com/OpenCubicChunks/CubicChunks)
1515

1616
### Cloning the repository
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.github.opencubicchunks.cubicchunks.client.renderer.chunk;
2+
3+
import io.github.notstirred.dasm.api.annotations.Dasm;
4+
import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet;
5+
import io.github.opencubicchunks.cubicchunks.util.asm.FactoryFromConstructor;
6+
import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube;
7+
import net.minecraft.client.renderer.chunk.SectionCopy;
8+
9+
@Dasm(ChunkToCubeSet.class)
10+
public interface CCSectionCopy {
11+
// Factory method for constructor that's added to SectionCopy by DASM
12+
@FactoryFromConstructor
13+
static SectionCopy cc_create(LevelCube wrapped, int sectionIndex) {
14+
throw new IllegalStateException("FactoryFromConstructor failed to apply");
15+
}
16+
}

src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/package-info.java renamed to src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/package-info.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@ParametersAreNonnullByDefault
22
@MethodsReturnNonnullByDefault
3-
package io.github.opencubicchunks.cubicchunks.client.renderer.cube;
3+
package io.github.opencubicchunks.cubicchunks.client.renderer.chunk;
44

55
import javax.annotation.ParametersAreNonnullByDefault;
66

src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/CubicRenderRegionCache.java

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCube.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCubeRegion.java

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderRegionCacheCubeInfo.java

Lines changed: 0 additions & 24 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.chunk;
2+
3+
import io.github.opencubicchunks.cubicchunks.client.renderer.chunk.CCSectionCopy;
4+
import org.spongepowered.asm.mixin.Mixin;
5+
6+
// Needed for FactoryFromConstructor to apply
7+
@Mixin(CCSectionCopy.class)
8+
public interface MixinCCSectionCopy {}
Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,41 @@
11
package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.chunk;
22

3-
import javax.annotation.Nullable;
4-
5-
import io.github.opencubicchunks.cc_core.api.CubePos;
63
import io.github.opencubicchunks.cc_core.utils.Coords;
7-
import io.github.opencubicchunks.cubicchunks.client.renderer.cube.CubicRenderRegionCache;
8-
import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCube;
9-
import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderCubeRegion;
10-
import io.github.opencubicchunks.cubicchunks.client.renderer.cube.RenderRegionCacheCubeInfo;
4+
import io.github.opencubicchunks.cubicchunks.CanBeCubic;
5+
import io.github.opencubicchunks.cubicchunks.client.renderer.chunk.CCSectionCopy;
116
import io.github.opencubicchunks.cubicchunks.world.level.CubicLevel;
12-
import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube;
13-
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
14-
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
15-
import net.minecraft.client.renderer.chunk.RenderChunk;
16-
import net.minecraft.client.renderer.chunk.RenderChunkRegion;
177
import net.minecraft.client.renderer.chunk.RenderRegionCache;
8+
import net.minecraft.client.renderer.chunk.RenderSectionRegion;
9+
import net.minecraft.client.renderer.chunk.SectionCopy;
1810
import net.minecraft.client.renderer.chunk.SectionRenderDispatcher;
1911
import net.minecraft.core.SectionPos;
2012
import net.minecraft.world.level.Level;
21-
import net.minecraft.world.level.chunk.LevelChunk;
2213
import org.spongepowered.asm.mixin.Mixin;
23-
import org.spongepowered.asm.mixin.Shadow;
14+
import org.spongepowered.asm.mixin.injection.At;
15+
import org.spongepowered.asm.mixin.injection.Inject;
16+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
2417

18+
// TODO rewrite javadoc for 1.21.6
2519
/**
26-
* The vanilla {@link RenderRegionCache} caches {@link LevelChunk}s and {@link RenderChunk}s while rebuilding
20+
* The vanilla {@link RenderRegionCache} caches {@link SectionCopy}s while rebuilding
2721
* {@link SectionRenderDispatcher.RenderSection}s
28-
* and has a method for creating a {@link RenderChunkRegion} for a given {@link SectionPos}.
22+
* and has a method for creating a {@link RenderSectionRegion} for a given {@link SectionPos}.
2923
* <p/>
30-
* We modify it by additionally caching {@link LevelCube}s and {@link RenderCube}s, and adding an equivalent method to create a
31-
* {@link RenderCubeRegion} for a given {@link SectionPos}.
24+
* We simply modify it to get section data from cubes instead of chunks in cubic levels.
3225
*/
3326
@Mixin(RenderRegionCache.class)
34-
public abstract class MixinRenderRegionCache implements CubicRenderRegionCache {
35-
@Shadow private final Long2ObjectMap<RenderRegionCacheCubeInfo> chunkInfoCache = new Long2ObjectOpenHashMap<>();
36-
37-
// TODO can we possibly do this with DASM + mixin? probably not?
38-
@Override public @Nullable RenderCubeRegion cc_createRegion(Level level, SectionPos sectionPos, boolean nullForEmpty) {
39-
int centerCubeX = Coords.sectionToCube(sectionPos.getX());
40-
int centerCubeY = Coords.sectionToCube(sectionPos.getY());
41-
int centerCubeZ = Coords.sectionToCube(sectionPos.getZ());
42-
var centerCubeInfo = this.cc_getChunkInfo(level, centerCubeX, centerCubeY, centerCubeZ);
43-
// if (nullForEmpty && centerCubeInfo.cube().isSectionEmpty(sectionPos.y())) { // TODO need a proper isSectionEmpty on CubeAccess
44-
// return null;
45-
// }
46-
int cubeStartX = centerCubeX - 1;
47-
int cubeStartY = centerCubeY - 1;
48-
int cubeStartZ = centerCubeZ - 1;
49-
int cubeEndX = centerCubeX + 1;
50-
int cubeEndY = centerCubeY + 1;
51-
int cubeEndZ = centerCubeZ + 1;
52-
RenderCube[] renderCubes = new RenderCube[RenderCubeRegion.CUBE_COUNT];
53-
54-
for (int cubeX = cubeStartX; cubeX <= cubeEndX; ++cubeX) {
55-
for (int cubeY = cubeStartY; cubeY <= cubeEndY; ++cubeY) {
56-
for (int cubeZ = cubeStartZ; cubeZ <= cubeEndZ; ++cubeZ) {
57-
int cubeIndex = RenderCubeRegion.index(cubeStartX, cubeStartY, cubeStartZ, cubeX, cubeY, cubeZ);
58-
var cubeInfo = cubeX == centerCubeX && cubeY == centerCubeY && cubeZ == centerCubeZ ? centerCubeInfo
59-
: this.cc_getChunkInfo(level, cubeX, cubeY, cubeZ);
60-
renderCubes[cubeIndex] = cubeInfo.renderCube();
61-
}
62-
}
27+
public abstract class MixinRenderRegionCache {
28+
// 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
29+
// To avoid brittleness we ignore these parameters and use the captured sectionPos long instead.
30+
@Inject(method = "lambda$getSectionDataCopy$0", at = @At("HEAD"), cancellable = true)
31+
private static void cc_onGetSectionDataCopy(
32+
Level level, int unusedSectionX, int unusedSectionZ, int unusedSectionY, long sectionPosLong, CallbackInfoReturnable<SectionCopy> cir
33+
) {
34+
if (((CanBeCubic) level).cc_isCubic()) {
35+
var sectionPos = SectionPos.of(sectionPosLong);
36+
var cube = ((CubicLevel) level).cc_getCube(Coords.sectionToCube(sectionPos.getX()), Coords.sectionToCube(sectionPos.getY()),
37+
Coords.sectionToCube(sectionPos.getZ()));
38+
cir.setReturnValue(CCSectionCopy.cc_create(cube, Coords.sectionToIndex(sectionPos.getX(), sectionPos.getY(), sectionPos.getZ())));
6339
}
64-
65-
var modelDataManager = level.getModelDataManager().snapshotSectionRegion(cubeStartX, cubeStartY, cubeStartZ, cubeEndX, cubeEndY, cubeEndZ);
66-
return new RenderCubeRegion(level, cubeStartX, cubeStartY, cubeStartZ, renderCubes, modelDataManager);
67-
}
68-
69-
private RenderRegionCacheCubeInfo cc_getChunkInfo(Level level, int cubeX, int cubeY, int cubeZ) {
70-
return this.chunkInfoCache.computeIfAbsent(CubePos.asLong(cubeX, cubeY, cubeZ), cubePosLong -> new RenderRegionCacheCubeInfo(
71-
((CubicLevel) level).cc_getCube(CubePos.extractX(cubePosLong), CubePos.extractY(cubePosLong), CubePos.extractZ(cubePosLong))));
7240
}
7341
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.github.opencubicchunks.cubicchunks.mixin.core.client.renderer.chunk;
2+
3+
import io.github.notstirred.dasm.api.annotations.Dasm;
4+
import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddFieldToSets;
5+
import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddTransformToSets;
6+
import io.github.notstirred.dasm.api.annotations.selector.FieldSig;
7+
import io.github.notstirred.dasm.api.annotations.selector.MethodSig;
8+
import io.github.notstirred.dasm.api.annotations.selector.Ref;
9+
import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod;
10+
import io.github.opencubicchunks.cubicchunks.exception.DasmFailedToApply;
11+
import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet;
12+
import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube;
13+
import net.minecraft.client.renderer.chunk.SectionCopy;
14+
import net.minecraft.world.level.chunk.LevelChunk;
15+
import net.minecraft.world.level.chunk.LevelChunkSection;
16+
import org.spongepowered.asm.mixin.Mixin;
17+
18+
/**
19+
* The vanilla {@link SectionCopy} stores block data of a {@link LevelChunkSection} and is used for rendering that section.
20+
* We simply add a constructor that creates the {@code SectionCopy} from a cube instead of a chunk.
21+
*/
22+
@Dasm(value = ChunkToCubeSet.class, target = @Ref(SectionCopy.class))
23+
@Mixin(SectionCopy.class)
24+
public class MixinSectionCopy {
25+
// 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?
26+
@AddFieldToSets(containers = ChunkToCubeSet.SectionCopy_redirects.class, field = @FieldSig(type = @Ref(LevelChunk.class), name = "wrapped"))
27+
final LevelCube cc_wrapped;
28+
29+
@AddTransformToSets(ChunkToCubeSet.SectionCopy_redirects.class)
30+
@TransformFromMethod(@MethodSig("<init>(Lnet/minecraft/world/level/chunk/LevelChunk;I)V"))
31+
public MixinSectionCopy(LevelCube wrapped, int sectionIndex) {
32+
throw new DasmFailedToApply();
33+
}
34+
}

0 commit comments

Comments
 (0)