Skip to content
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

Rework CloPos and add tests #5

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.opencubicchunks.cubicchunks.mixin.core.common.server.level;

import com.llamalad7.mixinextras.sugar.Local;
import io.github.opencubicchunks.cc_core.utils.Coords;
import io.github.opencubicchunks.cubicchunks.MarkableAsCubic;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.CloPos;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
Expand Down Expand Up @@ -58,7 +59,7 @@ private long cc_sentinelValue() {

@ModifyConstant(method = "computeLevelFromNeighbor", constant = @Constant(intValue = 1))
private int cc_dontIncrementLevelOnCubeChunkEdge(int constant, @Local(ordinal = 0, argsOnly = true) long fromPos, @Local(ordinal = 1, argsOnly = true) long toPos) {
if (cc_isCubic && CloPos.isCube(fromPos) && CloPos.isColumn(toPos)) return 0;
if (cc_isCubic && CloPos.isCube(fromPos) && CloPos.isChunk(toPos)) return 0;
return constant;
}

Expand All @@ -82,7 +83,7 @@ private void cc_onCheckNeighborsAfterUpdate(long pos, int level, boolean isDecre
@Inject(method = "getComputedLevel", at=@At("HEAD"), cancellable = true)
private void cc_onGetComputedLevel(long pos, long excludedSourcePos, int level, CallbackInfoReturnable<Integer> cir) {
if (!cc_isCubic) return;
if (CloPos.isColumn(pos)) {
if (CloPos.isChunk(pos)) {
int out = level;

int x = CloPos.extractX(pos);
Expand All @@ -108,10 +109,11 @@ private void cc_onGetComputedLevel(long pos, long excludedSourcePos, int level,
}
}
// This is propagating the level from neighboring cubes to this column.
IntSet neighborCubeYSet = this.cc_existingCubesForCubeColumns.get(CloPos.setRawY(pos, 0));
long cubeColumnKey = CloPos.asLong(Coords.sectionToCube(x), 0, Coords.sectionToCube(z));
IntSet neighborCubeYSet = this.cc_existingCubesForCubeColumns.get(cubeColumnKey);
if (neighborCubeYSet != null) {
for (Integer cubeY : neighborCubeYSet) {
long neighbor = CloPos.setRawY(pos, cubeY);
long neighbor = CloPos.setY(cubeColumnKey, cubeY);
assert neighbor != pos;
if (neighbor != excludedSourcePos) {
int k1 = this.computeLevelFromNeighbor(neighbor, pos, this.getLevel(neighbor));
Expand All @@ -130,9 +132,9 @@ private void cc_onGetComputedLevel(long pos, long excludedSourcePos, int level,
} else {
int out = level;

int x = CloPos.extractRawX(pos);
int y = CloPos.extractRawY(pos);
int z = CloPos.extractRawZ(pos);
int x = CloPos.extractX(pos);
int y = CloPos.extractY(pos);
int z = CloPos.extractZ(pos);
for (int dx = -1; dx <= 1; dx++) {
for (int dz = -1; dz <= 1; dz++) {
for (int dy = -1; dy <= 1; dy++) {
Expand Down Expand Up @@ -167,11 +169,11 @@ private void cc_onGetComputedLevel(long pos, long excludedSourcePos, int level,
*/
protected void cc_onSetLevel(long pos, int level) {
if (cc_isCubic && CloPos.isCube(pos)) {
long key = CloPos.setRawY(pos, 0);
long key = CloPos.setY(pos, 0);
IntSet cubes = cc_existingCubesForCubeColumns.get(key);
if (level >= cc_noChunkLevel) {
if (cubes != null) {
cubes.remove(CloPos.extractRawY(pos));
cubes.remove(CloPos.extractY(pos));
if (cubes.isEmpty()) {
cc_existingCubesForCubeColumns.remove(key);
}
Expand All @@ -180,7 +182,7 @@ protected void cc_onSetLevel(long pos, int level) {
if (cubes == null) {
cc_existingCubesForCubeColumns.put(key, cubes = new IntOpenHashSet());
}
cubes.add(CloPos.extractRawY(pos));
cubes.add(CloPos.extractY(pos));
}
}
}
Expand Down
Loading
Loading