Skip to content

Update to dasm 2.3.0, fix all method visibility issues in cc #48

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 1 commit into from
May 22, 2025
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
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ runs {
sourceSets.main.resources { srcDir 'src/generated/resources' }

repositories {
mavenLocal()
maven { setUrl("https://oss.sonatype.org/content/repositories/snapshots/") }
maven { setUrl("https://jitpack.io") }
maven { setUrl("https://maven.fabricmc.net/") }
Expand All @@ -238,7 +237,7 @@ dependencies {
targetConfiguration = "testArchivesOutput"
}

libraries("io.github.notstirred:dasm:2.2.1") {
libraries("io.github.notstirred:dasm:2.3.0") {
transitive = false
}
libraries("io.github.opencubicchunks:regionlib:0.63.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.opencubicchunks.cubicchunks.client.multiplayer;

import static io.github.notstirred.dasm.api.annotations.transform.Visibility.*;

import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.function.Consumer;

Expand All @@ -9,6 +11,7 @@
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.notstirred.dasm.api.annotations.transform.Visibility;
import io.github.opencubicchunks.cc_core.api.CubePos;
import io.github.opencubicchunks.cubicchunks.mixin.dasmsets.ChunkToCubeSet;
import io.github.opencubicchunks.cubicchunks.world.level.cube.CubeSource;
Expand Down Expand Up @@ -92,14 +95,9 @@ public boolean inRange(int x, int y, int z) {
}

@Nullable
@TransformFromMethod(owner = @Ref(ClientChunkCache.Storage.class), value = @MethodSig("getChunk(I)Lnet/minecraft/world/level/chunk/LevelChunk;"))
@TransformFromMethod(owner = @Ref(ClientChunkCache.Storage.class), value = @MethodSig("getChunk(I)Lnet/minecraft/world/level/chunk/LevelChunk;"), visibility = PUBLIC)
public native LevelCube getChunk(int chunkIndex);

// TODO dasm copying getChunk currently changes the access modifier from public to protected, so we need a dummy public method
@Nullable public LevelCube temp_getChunk(int index) {
return getChunk(index);
}

public void dumpChunks(String filePath) {
// TODO reimplement debug code
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.opencubicchunks.cubicchunks.mixin;

import static org.objectweb.asm.Opcodes.*;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand All @@ -22,16 +24,17 @@
import io.github.notstirred.dasm.api.annotations.transform.ApplicationStage;
import io.github.notstirred.dasm.api.provider.MappingsProvider;
import io.github.notstirred.dasm.exception.DasmException;
import io.github.notstirred.dasm.exception.wrapped.DasmWrappedExceptions;
import io.github.notstirred.dasm.transformer.Transformer;
import io.github.notstirred.dasm.transformer.data.ClassTransform;
import io.github.notstirred.dasm.transformer.data.MethodTransform;
import io.github.notstirred.dasm.util.CachingClassProvider;
import io.github.notstirred.dasm.util.ClassNodeProvider;
import io.github.notstirred.dasm.util.Either;
import io.github.opencubicchunks.cc_core.annotation.Public;
import io.github.opencubicchunks.cubicchunks.CubicChunks;
import net.neoforged.fml.loading.FMLEnvironment;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
Expand Down Expand Up @@ -113,7 +116,7 @@ public ASMConfigPlugin() {
}
});
}
} catch (ClassNotFoundException | IOException | DasmWrappedExceptions e) {
} catch (ClassNotFoundException | IOException | DasmException e) {
throw new RuntimeException(e);
}
return true;
Expand Down Expand Up @@ -155,18 +158,15 @@ public ASMConfigPlugin() {
}

@Override public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) {
doPublicAnnotation(targetClass);

// Apply POST_APPLY dasm transforms
boolean wasTransformed;
try {
wasTransformed = transformClass(targetClassName, targetClass, mixinClassName, ApplicationStage.POST_APPLY);
} catch (DasmException e) {
throw new RuntimeException(e);
}
for (MethodNode methodNode : targetClass.methods) {
if (methodNode.name.contains("cc_dasm$")) {
int asd = 0;
}
}
// If no DASM transformation happened to this class, we can skip removing the prefixed methods
if (!(wasTransformed | dasmTransformedInPreApply.get(mixinClassName + "|" + targetClassName)))
return;
Expand All @@ -192,6 +192,12 @@ record PrefixMethodPair(MethodNode dasmAddedMethod, MethodNode mixinAddedMethod)
methodPairs.forEach(prefixMethodPair -> {
if (prefixMethodPair.mixinAddedMethod != null) {
targetClass.methods.remove(prefixMethodPair.mixinAddedMethod);

// Copy annotations and visibility from mixin method
prefixMethodPair.dasmAddedMethod.visibleAnnotations = prefixMethodPair.mixinAddedMethod.visibleAnnotations;
prefixMethodPair.dasmAddedMethod.invisibleAnnotations = prefixMethodPair.mixinAddedMethod.invisibleAnnotations;
prefixMethodPair.dasmAddedMethod.access &= ~(ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED);
prefixMethodPair.dasmAddedMethod.access |= (ACC_PUBLIC | ACC_PRIVATE | ACC_PROTECTED) & prefixMethodPair.mixinAddedMethod.access;
}

prefixMethodPair.dasmAddedMethod.name = prefixMethodPair.dasmAddedMethod.name
Expand All @@ -213,6 +219,19 @@ record PrefixMethodPair(MethodNode dasmAddedMethod, MethodNode mixinAddedMethod)
}
}

private void doPublicAnnotation(ClassNode targetClass) {
// Making any methods annotated as @Public public
for (MethodNode method : targetClass.methods) {
List<AnnotationNode> visibleAnnotations = method.visibleAnnotations;
if (visibleAnnotations != null) {
if (visibleAnnotations.stream().anyMatch(annotationNode -> annotationNode.desc.equals("L" + Public.class.getName().replace('.', '/') + ";"))) {
method.access &= ~(ACC_PRIVATE | ACC_PROTECTED);
method.access |= ACC_PUBLIC;
}
}
}
}

/**
* @return Whether any transformation was done to the targetClass
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private static boolean cc_isValidCube(@Nullable LevelCube chunk, int x, int y, i
public void cc_drop(CubePos chunkPos) {
if (this.cc_cubeStorage.inRange(chunkPos.getX(), chunkPos.getY(), chunkPos.getZ())) {
int i = this.cc_cubeStorage.getIndex(chunkPos.getX(), chunkPos.getY(), chunkPos.getZ());
LevelCube levelCube = this.cc_cubeStorage.temp_getChunk(i);
LevelCube levelCube = this.cc_cubeStorage.getChunk(i);
if (cc_isValidCube(levelCube, chunkPos.getX(), chunkPos.getY(), chunkPos.getZ())) {
// TODO event hook
// net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.level.ChunkEvent.Unload(levelCube));
Expand All @@ -90,7 +90,7 @@ public void cc_drop(CubePos chunkPos) {
@Override
public @Nullable LevelCube cc_getCube(int chunkX, int chunkY, int chunkZ, ChunkStatus requiredStatus, boolean load) {
if (this.cc_cubeStorage.inRange(chunkX, chunkY,chunkZ)) {
LevelCube levelCube = this.cc_cubeStorage.temp_getChunk(this.cc_cubeStorage.getIndex(chunkX, chunkY,chunkZ));
LevelCube levelCube = this.cc_cubeStorage.getChunk(this.cc_cubeStorage.getIndex(chunkX, chunkY,chunkZ));
if (cc_isValidCube(levelCube, chunkX, chunkY,chunkZ)) {
return levelCube;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private native void cc_scheduleFullChunkPromotion(

@AddTransformToSets(GlobalSet.class) @TransformFromMethod(
value = @MethodSig("updateFutures(Lnet/minecraft/server/level/ChunkMap;Ljava/util/concurrent/Executor;)V"))
protected native void cc_updateFutures(ChunkMap chunkMap, Executor executor);
public native void cc_updateFutures(ChunkMap chunkMap, Executor executor);

@AddTransformToSets(GlobalSet.class) @TransformFromMethod(
value = @MethodSig("replaceProtoChunk(Lnet/minecraft/world/level/chunk/ImposterProtoChunk;)V"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public String toString() {

// dasm + mixin
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("updateChunkScheduling(JILnet/minecraft/server/level/ChunkHolder;I)Lnet/minecraft/server/level/ChunkHolder;"))
@Nullable native ChunkHolder cc_updateChunkScheduling(long chunkPos, int newLevel, @Nullable ChunkHolder holder, int oldLevel);
@Nullable public native ChunkHolder cc_updateChunkScheduling(long chunkPos, int newLevel, @Nullable ChunkHolder holder, int oldLevel);

// TODO this is a bit jank; maybe things that call this method should be altered instead?
@Inject(method = "updateChunkScheduling", at = @At("HEAD"), cancellable = true)
Expand All @@ -289,7 +289,7 @@ private boolean cc_updateChunkScheduling_onForgeHook(ServerLevel level, long pos
}

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("saveAllChunks(Z)V"))
protected native void cc_saveAllChunks(boolean flush);
public native void cc_saveAllChunks(boolean flush);

// P4: scheduleUnload lambda we'll want to mirror the forge API for cubes
// FIXME remove call to forge hook in copied method
Expand Down Expand Up @@ -406,7 +406,7 @@ public String toString() {
private native CompletableFuture<Either<CloAccess, ChunkHolder.ChunkLoadingFailure>> cc_scheduleChunkGeneration(ChunkHolder chunkHolder, ChunkStatus chunkStatus);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("releaseLightTicket(Lnet/minecraft/world/level/ChunkPos;)V"))
protected native void cc_releaseLightTicket(CloPos cloPos);
public native void cc_releaseLightTicket(CloPos cloPos);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("getDependencyStatus(Lnet/minecraft/world/level/chunk/ChunkStatus;I)Lnet/minecraft/world/level/chunk/ChunkStatus;"))
private native ChunkStatus cc_getDependencyStatus(ChunkStatus chunkStatus, int p_140264_);
Expand Down Expand Up @@ -467,7 +467,7 @@ private void cc_onSave_errorLog(CloAccess cloAccess, CallbackInfoReturnable<Bool
private native CompletableFuture<Optional<CompoundTag>> cc_readChunk(CloPos cloPos);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("anyPlayerCloseEnoughForSpawning(Lnet/minecraft/world/level/ChunkPos;)Z"))
native boolean cc_anyPlayerCloseEnoughForSpawning(CloPos cloPos);
public native boolean cc_anyPlayerCloseEnoughForSpawning(CloPos cloPos);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("getPlayersCloseForSpawning(Lnet/minecraft/world/level/ChunkPos;)Ljava/util/List;"))
public native List<ServerPlayer> cc_getPlayersCloseForSpawning(CloPos cloPos);
Expand All @@ -476,7 +476,7 @@ private void cc_onSave_errorLog(CloAccess cloAccess, CallbackInfoReturnable<Bool
private native boolean cc_playerIsCloseEnoughForSpawning(ServerPlayer player, CloPos cloPos);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("updatePlayerStatus(Lnet/minecraft/server/level/ServerPlayer;Z)V"))
native void cc_updatePlayerStatus(ServerPlayer player, boolean track);
public native void cc_updatePlayerStatus(ServerPlayer player, boolean track);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("move(Lnet/minecraft/server/level/ServerPlayer;)V"))
public native void cc_move(ServerPlayer player);
Expand Down Expand Up @@ -504,12 +504,12 @@ private boolean cc_getPlayers_isChunkTracked(ChunkMap instance, ServerPlayer pla

// Replace `SectionPos.chunk()` with `SectionPos.cc_cube()` unconditionally here
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(value = @MethodSig("tick()V"), useRedirectSets = { ChunkToCloSet.class, SectionPosToCubeSet.class })
protected native void cc_tick();
public native void cc_tick();

// TODO resendBiomesForChunks - only used for FillBiomeCommand

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("onFullChunkStatusChange(Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/server/level/FullChunkStatus;)V"))
native void cc_onFullChunkStatusChange(CloPos cloPos, FullChunkStatus fullChunkStatus);
public native void cc_onFullChunkStatusChange(CloPos cloPos, FullChunkStatus fullChunkStatus);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(@MethodSig("waitForLightBeforeSending(Lnet/minecraft/world/level/ChunkPos;I)V"))
public native void cc_waitForLightBeforeSending(CloPos cloPos, int p_301130_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ private void cc_onResortChunkTasks(int queueLevel, ChunkPos chunkPos, int ticket

@UsedFromASM
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("resortChunkTasks(ILnet/minecraft/world/level/ChunkPos;I)V"))
protected native void cc_resortCubicTasks(int queueLevel, CloPos cloPos, int ticketLevel);
public native void cc_resortCubicTasks(int queueLevel, CloPos cloPos, int ticketLevel);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.opencubicchunks.cubicchunks.mixin.core.common.server.level;

import static io.github.notstirred.dasm.api.annotations.transform.Visibility.PRIVATE;

import java.util.function.Function;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier;
Expand All @@ -11,6 +13,7 @@
import io.github.notstirred.dasm.api.annotations.redirect.redirects.AddTransformToSets;
import io.github.notstirred.dasm.api.annotations.selector.MethodSig;
import io.github.notstirred.dasm.api.annotations.transform.TransformFromMethod;
import io.github.opencubicchunks.cc_core.annotation.Public;
import io.github.opencubicchunks.cc_core.annotation.UsedFromASM;
import io.github.opencubicchunks.cc_core.world.level.CloPos;
import io.github.opencubicchunks.cubicchunks.MarkableAsCubic;
Expand Down Expand Up @@ -40,13 +43,13 @@ public abstract class MixinChunkTaskPriorityQueueSorter implements CloTaskPriori
return cc_isCubic;
}

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(
@MethodSig("message(Lnet/minecraft/server/level/ChunkHolder;Ljava/lang/Runnable;)Lnet/minecraft/server/level/ChunkTaskPriorityQueueSorter$Message;"))
private static native ChunkTaskPriorityQueueSorter.Message<Runnable> cc_message(ChunkHolder chunkHolder, Runnable task);
// This is private because mixin requires static methods to be private, @Public sets it after mixin applies
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(value = @MethodSig("message(Lnet/minecraft/server/level/ChunkHolder;Ljava/lang/Runnable;)Lnet/minecraft/server/level/ChunkTaskPriorityQueueSorter$Message;"), visibility = PRIVATE)
@Public private static native ChunkTaskPriorityQueueSorter.Message<Runnable> cc_message(ChunkHolder chunkHolder, Runnable task);

@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(
@MethodSig("message(Lnet/minecraft/server/level/ChunkHolder;Ljava/util/function/Function;)Lnet/minecraft/server/level/ChunkTaskPriorityQueueSorter$Message;"))
private static native <T> ChunkTaskPriorityQueueSorter.Message<T> cc_message(ChunkHolder chunkHolder, Function<ProcessorHandle<Unit>, T> task);
// This is private because mixin requires static methods to be private, @Public sets it after mixin applies
@AddTransformToSets(ChunkToCloSet.class) @TransformFromMethod(value = @MethodSig("message(Lnet/minecraft/server/level/ChunkHolder;Ljava/util/function/Function;)Lnet/minecraft/server/level/ChunkTaskPriorityQueueSorter$Message;"), visibility = PRIVATE)
@Public private static native <T> ChunkTaskPriorityQueueSorter.Message<T> cc_message(ChunkHolder chunkHolder, Function<ProcessorHandle<Unit>, T> task);

/**
* This is a method that is only used for debugging, so we don't currently test it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void cc_setCubic() {

@UsedFromASM
@AddTransformToSets(GlobalSet.class) @TransformFromMethod(@MethodSig("updateChunkForced(Lnet/minecraft/world/level/ChunkPos;Z)V"))
protected abstract void cc_updateCubeForced(CloPos pos, boolean add);
public abstract void cc_updateCubeForced(CloPos pos, boolean add);

/**
* This function replaces a TicketType with a CubicTicketType.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.opencubicchunks.cubicchunks.world.level.cube;

import static io.github.notstirred.dasm.api.annotations.transform.Visibility.PUBLIC;

import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Supplier;
Expand Down Expand Up @@ -246,7 +248,7 @@ public LevelCube(ServerLevel level, ProtoCube cube, @Nullable LevelClo.PostLoadP
@TransformFromMethod(value = @MethodSig("isInLevel()Z"), owner = @Ref(LevelChunk.class))
private native boolean isInLevel();

@TransformFromMethod(value = @MethodSig("isTicking(Lnet/minecraft/core/BlockPos;)Z"), owner = @Ref(LevelChunk.class))
@TransformFromMethod(value = @MethodSig("isTicking(Lnet/minecraft/core/BlockPos;)Z"), owner = @Ref(LevelChunk.class), visibility = PUBLIC)
public native boolean isTicking(BlockPos pos);

@TransformFromMethod(value = @MethodSig("setBlockEntity(Lnet/minecraft/world/level/block/entity/BlockEntity;)V"), owner = @Ref(LevelChunk.class))
Expand Down