Skip to content

Commit 13ed6e9

Browse files
CursedFlamesNotStirred
authored andcommitted
use CubePos in places that don't require CloPos
1 parent bad813c commit 13ed6e9

File tree

20 files changed

+203
-105
lines changed

20 files changed

+203
-105
lines changed

src/main/java/io/github/opencubicchunks/cubicchunks/mixin/core/common/client/multiplayer/MixinClientChunkCache.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddFieldToSets;
1212
import io.github.notstirred.dasm.api.annotations.selector.FieldSig;
1313
import io.github.notstirred.dasm.api.annotations.selector.Ref;
14-
import io.github.opencubicchunks.cc_core.world.level.CloPos;
1514
import io.github.opencubicchunks.cc_core.api.CubePos;
1615
import io.github.opencubicchunks.cc_core.api.CubicConstants;
1716
import io.github.opencubicchunks.cubicchunks.CanBeCubic;
@@ -57,7 +56,7 @@ public abstract class MixinClientChunkCache extends MixinChunkSource implements
5756
private void cc_onConstruct(ClientLevel level, int viewDistance, CallbackInfo ci) {
5857
if (((CanBeCubic) level).cc_isCubic()) {
5958
cc_emptyCube = new EmptyLevelCube(
60-
level, CloPos.cube(0, 0, 0), level.registryAccess().registryOrThrow(Registries.BIOME).getHolderOrThrow(Biomes.PLAINS)
59+
level, CubePos.of(0, 0, 0), level.registryAccess().registryOrThrow(Registries.BIOME).getHolderOrThrow(Biomes.PLAINS)
6160
);
6261
cc_cubeStorage = new ClientCubeCache.Storage(calculateStorageRange(viewDistance), level);
6362
// TODO we could redirect the initial construction instead of immediately resizing. doesn't really matter
@@ -132,7 +131,7 @@ public void cc_replaceBiomes(int x, int y, int z, FriendlyByteBuf buffer) {
132131
LevelCube levelCube = this.cc_cubeStorage.chunks.get(i);
133132
CubePos cubePos = CubePos.of(x, y, z);
134133
if (!cc_isValidCube(levelCube, x, y, z)) {
135-
levelCube = new LevelCube(this.level, CloPos.cube(cubePos));
134+
levelCube = new LevelCube(this.level, cubePos);
136135
levelCube.replaceWithPacketData(buffer, tag, consumer);
137136
this.cc_cubeStorage.replace(i, levelCube);
138137
} else {

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

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
66
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
77
import io.github.notstirred.dasm.api.annotations.Dasm;
8+
import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddMethodToSets;
89
import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddTransformToSets;
910
import io.github.notstirred.dasm.api.annotations.selector.MethodSig;
11+
import io.github.notstirred.dasm.api.annotations.selector.Ref;
1012
import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod;
1113
import io.github.opencubicchunks.cc_core.annotation.UsedFromASM;
14+
import io.github.opencubicchunks.cc_core.api.CubePos;
1215
import io.github.opencubicchunks.cc_core.world.level.CloPos;
1316
import io.github.opencubicchunks.cubicchunks.MarkableAsCubic;
1417
import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCloSet;
18+
import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet;
1519
import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.GlobalSet;
1620
import io.github.opencubicchunks.cubicchunks.server.level.CubicDistanceManager;
1721
import io.github.opencubicchunks.cubicchunks.server.level.CubicTicketType;
@@ -72,38 +76,81 @@ public void cc_setCubic() {
7276

7377
@Override
7478
@UsedFromASM
75-
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("addTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
79+
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("addTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
7680
public abstract <T> void cc_addTicket(TicketType<T> type, CloPos pos, int level, T value);
7781

7882
@Override
7983
@UsedFromASM
80-
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("removeTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
84+
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("removeTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
8185
public abstract <T> void cc_removeTicket(TicketType<T> type, CloPos pos, int level, T value);
8286

8387
@Override
8488
@UsedFromASM
85-
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
89+
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
8690
public abstract <T> void cc_addRegionTicket(TicketType<T> type, CloPos pos, int distance, T value);
8791

8892
@Override
8993
@UsedFromASM
90-
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;Z)V"))
94+
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;Z)V"))
9195
public abstract <T> void cc_addRegionTicket(TicketType<T> type, CloPos pos, int distance, T value, boolean forceTicks);
9296

9397
@Override
9498
@UsedFromASM
95-
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
99+
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
96100
public abstract <T> void cc_removeRegionTicket(TicketType<T> type, CloPos pos, int distance, T value);
97101

98102
@Override
99103
@UsedFromASM
100-
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;Z)V"))
104+
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;Z)V"))
101105
public abstract <T> void cc_removeRegionTicket(TicketType<T> type, CloPos pos, int distance, T value, boolean forceTicks);
102106

103107
@UsedFromASM
104-
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("updateChunkForced(Lnet/minecraft/world/level/ChunkPos;Z)V"))
108+
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("updateChunkForced(Lnet/minecraft/world/level/ChunkPos;Z)V"))
105109
public abstract void cc_updateCubeForced(CloPos pos, boolean add);
106110

111+
// CubePos equivalents that delegate to their corresponding CloPos method
112+
@UsedFromASM
113+
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(DistanceManager.class), method = @MethodSig("addTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
114+
public <T> void cc_addTicket(TicketType<T> type, CubePos pos, int level, T value) {
115+
cc_addTicket(type, CloPos.cube(pos), level, value);
116+
}
117+
118+
@UsedFromASM
119+
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(DistanceManager.class), method = @MethodSig("removeTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
120+
public <T> void cc_removeTicket(TicketType<T> type, CubePos pos, int level, T value) {
121+
cc_removeTicket(type, CloPos.cube(pos), level, value);
122+
}
123+
124+
@UsedFromASM
125+
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(DistanceManager.class), method = @MethodSig("addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
126+
public <T> void cc_addRegionTicket(TicketType<T> type, CubePos pos, int distance, T value) {
127+
cc_addRegionTicket(type, CloPos.cube(pos), distance, value);
128+
}
129+
130+
@UsedFromASM
131+
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(DistanceManager.class), method = @MethodSig("addRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;Z)V"))
132+
public <T> void cc_addRegionTicket(TicketType<T> type, CubePos pos, int distance, T value, boolean forceTicks) {
133+
cc_addRegionTicket(type, CloPos.cube(pos), distance, value, forceTicks);
134+
}
135+
136+
@UsedFromASM
137+
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(DistanceManager.class), method = @MethodSig("removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;)V"))
138+
public <T> void cc_removeRegionTicket(TicketType<T> type, CubePos pos, int distance, T value) {
139+
cc_removeRegionTicket(type, CloPos.cube(pos), distance, value);
140+
}
141+
142+
@UsedFromASM
143+
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(DistanceManager.class), method = @MethodSig("removeRegionTicket(Lnet/minecraft/server/level/TicketType;Lnet/minecraft/world/level/ChunkPos;ILjava/lang/Object;Z)V"))
144+
public <T> void cc_removeRegionTicket(TicketType<T> type, CubePos pos, int distance, T value, boolean forceTicks) {
145+
cc_removeRegionTicket(type, CloPos.cube(pos), distance, value, forceTicks);
146+
}
147+
148+
@UsedFromASM
149+
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(DistanceManager.class), method = @MethodSig("updateChunkForced(Lnet/minecraft/world/level/ChunkPos;Z)V"))
150+
public void cc_updateCubeForced(CubePos pos, boolean add) {
151+
cc_updateCubeForced(CloPos.cube(pos), add);
152+
}
153+
107154
/**
108155
* This function replaces a TicketType with a CubicTicketType.
109156
*/

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.github.notstirred.dasm.api.annotations.selector.Ref;
2424
import io.github.notstirred.dasm.api.annotations.transform.AddUnusedParam;
2525
import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod;
26+
import io.github.opencubicchunks.cc_core.api.CubePos;
2627
import io.github.opencubicchunks.cc_core.utils.Coords;
2728
import io.github.opencubicchunks.cc_core.world.level.CloPos;
2829
import io.github.opencubicchunks.cubicchunks.CanBeCubic;
@@ -130,7 +131,7 @@ private void cc_getCube_supplyAsync(int pChunkX, int pChunkY, int pChunkZ, Chunk
130131
}
131132

132133
// The first two params are the x and z coordinates inside the call being redirected; the next three params are the x/y/z coordinates in the params of getCube
133-
@Dynamic @Redirect(method = "cc_dasm$cc_getCube", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/world/level/CloPos;chunkAsLong(II)J"))
134+
@Dynamic @Redirect(method = "cc_dasm$cc_getCube", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/api/CubePos;dummy_chunkAsLong(II)J"))
134135
private long cc_getCube_posAsLong(int pX, int pZ, int pXRepeated, int pY, int pZRepeated) {
135136
return CloPos.cubeAsLong(pX, pY, pZ);
136137
}
@@ -145,7 +146,7 @@ private CompletableFuture cc_getCube_getChunkFutureMainThread(ServerChunkCache i
145146
@Override @Nullable public native LevelCube cc_getCubeNow(int pChunkX, @AddUnusedParam int chunkY, int pChunkZ);
146147

147148
// The first two params are the x and z coordinates inside the call being redirected; the next three params are the x/y/z coordinates in the params of getCubeNow
148-
@Dynamic @Redirect(method = "cc_dasm$cc_getCubeNow", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/world/level/CloPos;chunkAsLong(II)J"))
149+
@Dynamic @Redirect(method = "cc_dasm$cc_getCubeNow", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/api/CubePos;dummy_chunkAsLong(II)J"))
149150
private long cc_getCubeNow_posAsLong(int pX, int pZ, int pXRepeated, int pY, int pZRepeated) {
150151
return CloPos.cubeAsLong(pX, pY, pZ);
151152
}
@@ -196,18 +197,18 @@ private native CompletableFuture<Either<CubeAccess, ChunkHolder.ChunkLoadingFail
196197
);
197198

198199
// The first two params are the x and z coordinates inside the call being redirected; the next three params are the x/y/z coordinates in the params of cc_getCubeFutureMainThread
199-
@Dynamic @Redirect(method = "cc_dasm$cc_getCubeFutureMainThread", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/world/level/CloPos;chunk(II)Lio/github/opencubicchunks/cc_core/world/level/CloPos;"))
200-
private CloPos cc_getCubeFutureMainThread_chunkPosConstruct(int pX, int pZ, int pXRepeated, int pY, int pZRepeated) {
201-
return CloPos.cube(pX, pY, pZ);
200+
@Dynamic @Redirect(method = "cc_dasm$cc_getCubeFutureMainThread", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/api/CubePos;dummy_fromChunkCoords(II)Lio/github/opencubicchunks/cc_core/api/CubePos;"))
201+
private CubePos cc_getCubeFutureMainThread_chunkPosConstruct(int pX, int pZ, int pXRepeated, int pY, int pZRepeated) {
202+
return CubePos.of(pX, pY, pZ);
202203
}
203204

204205
@TransformFromMethod(@MethodSig("hasChunk(II)Z"))
205206
public native boolean cc_hasCube(int pX, @AddUnusedParam int y, int pZ);
206207

207208
// The first two params are the x and z coordinates inside the call being redirected; the next three params are the x/y/z coordinates in the params of cc_hasCube
208-
@Dynamic @Redirect(method = "cc_dasm$cc_hasCube", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/world/level/CloPos;chunk(II)Lio/github/opencubicchunks/cc_core/world/level/CloPos;"))
209-
private CloPos cc_hasCube_posAsLong(int pX, int pZ, int pXRepeated, int pY, int pZRepeated) {
210-
return CloPos.cube(pX, pY, pZ);
209+
@Dynamic @Redirect(method = "cc_dasm$cc_hasCube", at = @At(value = "INVOKE", target = "Lio/github/opencubicchunks/cc_core/api/CubePos;dummy_fromChunkCoords(II)Lio/github/opencubicchunks/cc_core/api/CubePos;"))
210+
private CubePos cc_hasCube_posAsLong(int pX, int pZ, int pXRepeated, int pY, int pZRepeated) {
211+
return CubePos.of(pX, pY, pZ);
211212
}
212213

213214
// TODO (P2) - lighting; currently unused. can probably be done with dasm and @AddUnusedParam
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.github.opencubicchunks.cubicchunks.mixin.core.common.world.level;
2+
3+
import io.github.opencubicchunks.cc_core.annotation.Public;
4+
import io.github.opencubicchunks.cc_core.api.CubePos;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
7+
/**
8+
* When DASM redirects ChunkPos to CubePos, some methods do not have reasonable equivalents that can be automatically redirected to.
9+
* In these cases, we call dummy methods that throw errors, and require that mixins are used to manually replace these method calls with whatever the correct method is.
10+
*/
11+
@Mixin(CubePos.class)
12+
public class MixinCubePos {
13+
@Public private static CubePos dummy_fromChunkCoords(int x, int z) {
14+
throw new IllegalStateException(
15+
"This method should never be called, and indicates that something has been transformed incorrectly"
16+
+ " - all calls to this method should be manually redirected to CubePos.of(x, y, z)");
17+
}
18+
19+
@Public private static long dummy_chunkAsLong(int x, int z) {
20+
throw new IllegalStateException(
21+
"This method should never be called, and indicates that something has been transformed incorrectly"
22+
+ " - all calls to this method should be manually redirected to CubePos.asLong(x, y, z)");
23+
}
24+
}

src/main/java/io/github/opencubicchunks/cubicchunks/mixin/dasmsets/ChunkToCloSet.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import javax.annotation.Nullable;
44

55
import io.github.notstirred.dasm.api.annotations.redirect.redirects.ConstructorToFactoryRedirect;
6+
import io.github.notstirred.dasm.api.annotations.redirect.redirects.FieldRedirect;
7+
import io.github.notstirred.dasm.api.annotations.redirect.redirects.FieldToMethodRedirect;
68
import io.github.notstirred.dasm.api.annotations.redirect.redirects.MethodRedirect;
79
import io.github.notstirred.dasm.api.annotations.redirect.redirects.TypeRedirect;
810
import io.github.notstirred.dasm.api.annotations.redirect.sets.RedirectSet;
911
import io.github.notstirred.dasm.api.annotations.selector.ConstructorMethodSig;
12+
import io.github.notstirred.dasm.api.annotations.selector.FieldSig;
1013
import io.github.notstirred.dasm.api.annotations.selector.MethodSig;
1114
import io.github.notstirred.dasm.api.annotations.selector.Ref;
1215
import io.github.opencubicchunks.cc_core.world.level.CloPos;
@@ -45,6 +48,28 @@
4548
*/
4649
@RedirectSet
4750
public interface ChunkToCloSet extends GlobalSet {
51+
@TypeRedirect(from = @Ref(ChunkPos.class), to = @Ref(CloPos.class))
52+
abstract class ChunkPos_to_CloPos_redirects {
53+
@FieldRedirect(@FieldSig(type = @Ref(long.class), name = "INVALID_CHUNK_POS"))
54+
static final long INVALID_CLO_POS = Long.MAX_VALUE;
55+
56+
@FieldToMethodRedirect(@FieldSig(type = @Ref(int.class), name = "x"))
57+
native int getX();
58+
59+
@FieldToMethodRedirect(@FieldSig(type = @Ref(int.class), name = "z"))
60+
native int getZ();
61+
62+
// Note that this relies on ChunkPos and CloPos encoding to longs in the same way
63+
@ConstructorToFactoryRedirect(@ConstructorMethodSig(args = { @Ref(long.class) }))
64+
static native CloPos fromLong(long cloPos);
65+
66+
@ConstructorToFactoryRedirect(@ConstructorMethodSig(args = { @Ref(int.class), @Ref(int.class) }))
67+
static native CloPos chunk(int x, int z);
68+
69+
@MethodRedirect(@MethodSig("asLong(II)J"))
70+
static native long chunkAsLong(int x, int z);
71+
}
72+
4873
@TypeRedirect(from = @Ref(ChunkAccess.class), to = @Ref(CloAccess.class))
4974
interface ChunkAccess_to_CloAccess_redirects {
5075
@MethodRedirect(@MethodSig("getPos()Lnet/minecraft/world/level/ChunkPos;"))

0 commit comments

Comments
 (0)