-
Notifications
You must be signed in to change notification settings - Fork 14
Port to 1.21.6 #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Port to 1.21.6 #77
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/chunk/CCSectionCopy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
...ks/client/renderer/cube/package-info.java → ...s/client/renderer/chunk/package-info.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
...va/io/github/opencubicchunks/cubicchunks/client/renderer/cube/CubicRenderRegionCache.java
This file was deleted.
Oops, something went wrong.
30 changes: 0 additions & 30 deletions
30
src/main/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCube.java
This file was deleted.
Oops, something went wrong.
63 changes: 0 additions & 63 deletions
63
...ain/java/io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderCubeRegion.java
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
...io/github/opencubicchunks/cubicchunks/client/renderer/cube/RenderRegionCacheCubeInfo.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...thub/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinCCSectionCopy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 {} |
78 changes: 23 additions & 55 deletions
78
.../opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinRenderRegionCache.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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}. | ||
| * <p/> | ||
| * 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<RenderRegionCacheCubeInfo> 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<SectionCopy> 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)))); | ||
| } | ||
| } |
34 changes: 34 additions & 0 deletions
34
...github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionCopy.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
NotStirred marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @AddTransformToSets(ChunkToCubeSet.SectionCopy_redirects.class) | ||
| @TransformFromMethod(@MethodSig("<init>(Lnet/minecraft/world/level/chunk/LevelChunk;I)V")) | ||
| public MixinSectionCopy(LevelCube wrapped, int sectionIndex) { | ||
| throw new DasmFailedToApply(); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need the @dasm, maybe remove or leave as
@Dasm({})?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yep, forgot to remove when switching to
@FactoryFromConstructor