Skip to content

Commit 9c7c6fe

Browse files
CursedFlamesNotStirred
authored andcommitted
address PR review comments
1 parent d1ba919 commit 9c7c6fe

File tree

7 files changed

+30
-31
lines changed

7 files changed

+30
-31
lines changed

src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/MixinViewArea.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ private void cc_onSetViewDistance(int renderDistanceChunks, CallbackInfo ci) {
3636
if (!((CanBeCubic) level).cc_isCubic()) return;
3737
ci.cancel();
3838
int i = renderDistanceChunks * 2 + 1;
39-
i *= CubicConstants.DIAMETER_IN_SECTIONS; // TODO is this correct?
4039
this.sectionGridSizeX = i;
4140
this.sectionGridSizeY = i;
4241
this.sectionGridSizeZ = i;

src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/client/renderer/chunk/MixinSectionRenderDispatcher$RenderSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ private void cc_onDoesChunkExistAt(long sectionPosLong, CallbackInfoReturnable<B
4040
if (!((CanBeCubic) ((SectionRenderDispatcherAccess) this$0).cc_getLevel()).cc_isCubic()) {
4141
return;
4242
}
43+
// TODO (P2) lighting: also check the cubic equivalent of LevelLightEngine.lightOnInColumn here (see vanilla doesChunkExistAt method) - sections currently sometimes fail to render due to this missing check
4344
cir.setReturnValue(((CubicLevel) ((SectionRenderDispatcherAccess) this$0).cc_getLevel()).cc_getCube(Coords.sectionToCube(SectionPos.x(sectionPosLong)), Coords.sectionToCube(SectionPos.y(sectionPosLong)), Coords.sectionToCube(SectionPos.z(sectionPosLong)), ChunkStatus.FULL, false) != null);
4445
}
4546

@@ -54,7 +55,6 @@ private void cc_onHasAllNeighbors(CallbackInfoReturnable<Boolean> cir) {
5455
for (int dy = -1; dy <= 1; dy++) {
5556
for (int dz = -1; dz <= 1; dz++) {
5657
if (dx == 0 && dy == 0 && dz == 0) continue;
57-
// TODO this checks neighboring sections rather than neighboring cubes; not sure if we should be checking neighboring cubes instead?
5858
if (!this.doesChunkExistAt(SectionPos.offset(this.sectionNode, dx, dy, dz))) {
5959
cir.setReturnValue(false);
6060
return;

src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/level/MixinChunkGenerationTask.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ private void cc_onScheduleLayer(ChunkStatus status, boolean needsGeneration, Cal
275275

276276
@Inject(method = "scheduleChunkInLayer", at = @At("HEAD"), cancellable = true)
277277
private void cc_onScheduleChunkInLayer(ChunkStatus status, boolean needsGeneration, GenerationChunkHolder chunk, CallbackInfoReturnable<Boolean> cir) {
278-
var cloPos = ((GenerationCloHolder) chunk).cc_getCloPos();
279-
if (cloPos != null && cloPos.isCube()) cir.setReturnValue(cc_scheduleCubeInLayer(status, needsGeneration, chunk));
278+
if (((GenerationCloHolder) chunk).cc_getCubePos() != null) {
279+
cir.setReturnValue(cc_scheduleCubeInLayer(status, needsGeneration, chunk));
280+
}
280281
}
281282

282283
@TransformFromMethod(useRedirectSets = ChunkToCubeSet.class, owner = @Ref(ChunkGenerationTask.class), value = @MethodSig("scheduleChunkInLayer(Lnet/minecraft/world/level/chunk/status/ChunkStatus;ZLnet/minecraft/server/level/GenerationChunkHolder;)Z"))

src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/level/MixinChunkHolder.java

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,24 @@
2727
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.LevelClo;
2828
import io.github.opencubicchunks.cubicchunks.world.level.cube.CubeAccess;
2929
import io.github.opencubicchunks.cubicchunks.world.level.cube.LevelCube;
30-
import it.unimi.dsi.fastutil.shorts.ShortOpenHashSet;
3130
import it.unimi.dsi.fastutil.shorts.ShortSet;
3231
import net.minecraft.core.BlockPos;
33-
import net.minecraft.core.SectionPos;
3432
import net.minecraft.server.level.ChunkHolder;
3533
import net.minecraft.server.level.ChunkMap;
3634
import net.minecraft.server.level.FullChunkStatus;
3735
import net.minecraft.server.level.GenerationChunkHolder;
3836
import net.minecraft.world.level.ChunkPos;
37+
import net.minecraft.world.level.LevelHeightAccessor;
3938
import net.minecraft.world.level.LightLayer;
4039
import net.minecraft.world.level.chunk.LevelChunk;
4140
import net.minecraft.world.level.chunk.status.ChunkStatus;
41+
import org.spongepowered.asm.mixin.Dynamic;
4242
import org.spongepowered.asm.mixin.Final;
4343
import org.spongepowered.asm.mixin.Mixin;
4444
import org.spongepowered.asm.mixin.Shadow;
4545
import org.spongepowered.asm.mixin.injection.At;
4646
import org.spongepowered.asm.mixin.injection.Inject;
47+
import org.spongepowered.asm.mixin.injection.Redirect;
4748
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
4849

4950
/**
@@ -93,27 +94,23 @@ public MixinChunkHolder() {
9394
return (LevelClo) getChunkToSend();
9495
}
9596

96-
// TODO dasm + mixin?
9797
@Inject(method = "blockChanged", at = @At("HEAD"), cancellable = true)
9898
public void cc_onBlockChanged(BlockPos pos, CallbackInfoReturnable<Boolean> cir) {
9999
if (cc_cubePos != null) {
100-
LevelCube levelCube = this.cc_getTickingCube();
101-
if (levelCube == null) {
102-
cir.setReturnValue(false);
103-
} else {
104-
boolean alreadyHadChangedSections = this.hasChangedSections;
105-
int sectionIndex = Coords.sectionToIndex(Coords.blockToSection(pos.getX()), Coords.blockToSection(pos.getY()), Coords.blockToSection(pos.getZ()));
106-
if (this.changedBlocksPerSection[sectionIndex] == null) {
107-
this.hasChangedSections = true;
108-
this.changedBlocksPerSection[sectionIndex] = new ShortOpenHashSet();
109-
}
110-
111-
this.changedBlocksPerSection[sectionIndex].add(SectionPos.sectionRelativePos(pos));
112-
cir.setReturnValue(!alreadyHadChangedSections);
113-
}
100+
cir.setReturnValue(cc_blockChanged(pos));
114101
}
115102
}
116103

104+
// region [cc_blockChanged dasm + mixin]
105+
@TransformFromMethod(@MethodSig("blockChanged(Lnet/minecraft/core/BlockPos;)Z"))
106+
private native boolean cc_blockChanged(BlockPos pos);
107+
108+
@Dynamic @Redirect(method = "cc_dasm$cc_blockChanged", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/LevelHeightAccessor;getSectionIndex(I)I"))
109+
private int cc_onBlockChanged_sectionIndex(LevelHeightAccessor instance, int y, BlockPos pos) {
110+
return Coords.sectionToIndex(Coords.blockToSection(pos.getX()), Coords.blockToSection(pos.getY()), Coords.blockToSection(pos.getZ()));
111+
}
112+
// endregion
113+
117114
@Inject(method = "sectionLightChanged", at = @At("HEAD"), cancellable = true)
118115
public void cc_onSectionLightChanged(LightLayer lightLayer, int sectionY, CallbackInfoReturnable<Boolean> cir) {
119116
if (cc_cubePos != null) {

src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/server/level/MixinChunkMap.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,17 @@ public abstract class MixinChunkMap extends MixinChunkStorage implements Generat
102102
@Shadow @Final ServerLevel level;
103103
@Shadow @Final private ChunkMap.DistanceManager distanceManager;
104104

105-
private static CompletableFuture<ChunkResult<CloAccess>> UNLOADED_CHUNK_FUTURE = CompletableFuture.completedFuture(
106-
ChunkResult.error("Unloaded chunk")
107-
);
108-
109105
@Shadow @Final private static CompletableFuture<ChunkResult<List<CloAccess>>> UNLOADED_CHUNK_LIST_FUTURE;
110106
@Shadow @Final private static ChunkResult<List<CloAccess>> UNLOADED_CHUNK_LIST_RESULT;
111107

112108
@Shadow private static double euclideanDistanceSquared(ChunkPos chunkPos, Vec3 pos) {
113109
throw new IllegalStateException();
114110
}
115111

112+
// TODO this one being on GlobalSet is a bit jank
116113
@AddFieldToSets(sets = GlobalSet.class, owner = @Ref(ChunkMap.class), field = @FieldSig(type = @Ref(ChunkProgressListener.class), name = "progressListener"))
117114
private CloProgressListener cc_progressListener;
118-
@AddFieldToSets(sets = GlobalSet.class, owner = @Ref(ChunkMap.class), field = @FieldSig(type = @Ref(ChunkStatusUpdateListener.class), name = "chunkStatusListener"))
115+
@AddFieldToSets(sets = ChunkToCloSet.class, owner = @Ref(ChunkMap.class), field = @FieldSig(type = @Ref(ChunkStatusUpdateListener.class), name = "chunkStatusListener"))
119116
private CloStatusUpdateListener cc_cloStatusListener;
120117

121118
// TODO once we can target non-return locations in constructors, do this when the vanilla field is set
@@ -259,12 +256,12 @@ private void cc_onGetChunkRangeFuture(ChunkHolder cloHolder, int radius, IntFunc
259256

260257
//region [cc_updateCubeScheduling dasm + mixin]
261258
@AddTransformToSets(ChunkToCubeSet.class) @TransformFromMethod(useRedirectSets = ChunkToCubeSet.class, value = @MethodSig("updateChunkScheduling(JILnet/minecraft/server/level/ChunkHolder;I)Lnet/minecraft/server/level/ChunkHolder;"))
262-
@Nullable public native ChunkHolder cc_updateCubeScheduling(long chunkPos, int newLevel, @Nullable ChunkHolder holder, int oldLevel);
259+
@Nullable public native ChunkHolder cc_updateCubeScheduling(long cubePos, int newLevel, @Nullable ChunkHolder holder, int oldLevel);
263260

264261
@Inject(method = "updateChunkScheduling", at = @At("HEAD"), cancellable = true)
265-
private void cc_onUpdateChunkScheduling(long chunkPos, int newLevel, ChunkHolder holder, int oldLevel, CallbackInfoReturnable<ChunkHolder> cir) {
266-
if (((CanBeCubic) level).cc_isCubic() && CloPos.isCube(chunkPos)) {
267-
cir.setReturnValue(cc_updateCubeScheduling(chunkPos, newLevel, holder, oldLevel));
262+
private void cc_onUpdateChunkScheduling(long cloPos, int newLevel, ChunkHolder holder, int oldLevel, CallbackInfoReturnable<ChunkHolder> cir) {
263+
if (((CanBeCubic) level).cc_isCubic() && CloPos.isCube(cloPos)) {
264+
cir.setReturnValue(cc_updateCubeScheduling(cloPos, newLevel, holder, oldLevel));
268265
}
269266
}
270267
//endregion
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package io.github.opencubicchunks.cubicchunks.server.level;
22

3+
import javax.annotation.Nullable;
4+
5+
import io.github.opencubicchunks.cc_core.api.CubePos;
36
import io.github.opencubicchunks.cc_core.world.level.CloPos;
47
import io.github.opencubicchunks.cubicchunks.world.level.cube.ImposterProtoCube;
58

69
public interface GenerationCloHolder {
710
CloPos cc_getCloPos();
811

12+
@Nullable CubePos cc_getCubePos();
13+
914
void cc_replaceProtoCube(ImposterProtoCube cube);
1015
}

src/main/java/io/github/opencubicchunks/cubicchunks/world/level/cube/LevelCube.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void setUnsavedListener(LevelCube.UnsavedListener unsavedListener) {
185185
@Override public native TickContainerAccess<Fluid> getFluidTicks();
186186

187187
@TransformFromMethod(value = @MethodSig("getTicksForSerialization(J)Lnet/minecraft/world/level/chunk/ChunkAccess$PackedTicks;"), owner = @Ref(LevelChunk.class))
188-
@Override public native ChunkAccess.PackedTicks getTicksForSerialization(long todoNameThis);
188+
@Override public native ChunkAccess.PackedTicks getTicksForSerialization(long gameTime);
189189

190190
// TODO should this actually be dasm'd?
191191
@TransformFromMethod(value = @MethodSig("getListenerRegistry(I)Lnet/minecraft/world/level/gameevent/GameEventListenerRegistry;"), owner = @Ref(LevelChunk.class))

0 commit comments

Comments
 (0)