Skip to content
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/*
!.idea/codeStyles/
!.idea/inspectionProfiles
# eclipse
bin
*.launch
Expand Down
6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ dependencies {
targetConfiguration = "testArchivesOutput"
}

libraries("io.github.notstirred:dasm:2.3.1") {
libraries("io.github.notstirred:dasm:2.5.2") {
transitive = false
}
libraries("io.github.opencubicchunks:regionlib:0.63.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public RenderRegionCacheCubeInfo(LevelCube cube) {
throw new DasmFailedToApply();
}

@AddMethodToSets(owner = @Ref(string = "net.minecraft.client.renderer.chunk.RenderRegionCache$ChunkInfo"), sets = ChunkToCubeSet.class, method = @MethodSig("chunk()Lnet/minecraft/world/level/chunk/LevelChunk;"))
@AddMethodToSets(containers = ChunkToCubeSet.RenderRegionCache$ChunkInfo_to_RenderRegionCacheCubeInfo_redirects.class, method = @MethodSig("chunk()Lnet/minecraft/world/level/chunk/LevelChunk;"))
public native LevelCube cube();

@AddMethodToSets(owner = @Ref(string = "net.minecraft.client.renderer.chunk.RenderRegionCache$ChunkInfo"), sets = ChunkToCubeSet.class, method = @MethodSig("renderChunk()Lnet/minecraft/client/renderer/chunk/RenderChunk;"))
@AddMethodToSets(containers = ChunkToCubeSet.RenderRegionCache$ChunkInfo_to_RenderRegionCacheCubeInfo_redirects.class, method = @MethodSig("renderChunk()Lnet/minecraft/client/renderer/chunk/RenderChunk;"))
public native RenderCube renderCube();
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,24 @@

import javax.annotation.Nullable;

import com.mojang.datafixers.util.Either;
import io.github.notstirred.dasm.annotation.AnnotationParser;
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.notify.Notification;
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.notstirred.dasm.util.NotifyStack;
import io.github.notstirred.dasm.util.Pair;
import io.github.opencubicchunks.cc_core.annotation.Public;
import io.github.opencubicchunks.cubicchunks.CubicChunks;
import net.minecraft.Util;
import net.neoforged.fml.loading.FMLEnvironment;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
Expand All @@ -50,6 +55,8 @@ public class ASMConfigPlugin implements IMixinConfigPlugin {
private final Map<String, Either<ClassTransform, Collection<MethodTransform>>> preApplyTargets = new HashMap<>();
private final Map<String, Either<ClassTransform, Collection<MethodTransform>>> postApplyTargets = new HashMap<>();

private final Logger logger = LogManager.getLogger("dasm");

public ASMConfigPlugin() {
boolean developmentEnvironment = false;
try {
Expand All @@ -59,7 +66,7 @@ public ASMConfigPlugin() {
MappingsProvider mappings = MappingsProvider.IDENTITY;

// TODO: breaks on fabric (remapped at runtime)
ClassNodeProvider classProvider = new CachingClassProvider(s -> {
var classProvider = new CachingClassProvider(s -> {
try (var classStream = ASMConfigPlugin.class.getClassLoader().getResourceAsStream(s.replace(".", "/") + ".class")) {
return Optional.ofNullable(classStream.readAllBytes());
} catch (IOException e) {
Expand All @@ -81,15 +88,14 @@ public ASMConfigPlugin() {
try {
ClassNode targetClass = MixinService.getService().getBytecodeProvider().getClassNode(targetClassName);
ClassNode mixinClass = MixinService.getService().getBytecodeProvider().getClassNode(mixinClassName);
// rename the mixin class to get dasm to generate owners correctly
mixinClass.name = targetClass.name;

// PRE_APPLY
this.annotationParser.findRedirectSets(mixinClass);
var methodTransformsMixin = this.annotationParser.buildMethodTargets(mixinClass, "cc_dasm$");
this.annotationParser.findRedirectSets(targetClass);
var classTransform = this.annotationParser.buildClassTarget(targetClass);
var methodTransformsTarget = this.annotationParser.buildMethodTargets(targetClass, "cc_dasm$");
handleError(this.annotationParser.findDasmAnnotations(mixinClass));
var methodTransformsMixin = handleError(this.annotationParser.buildContext().buildMethodTargets(mixinClass, "cc_dasm$"));
handleError(this.annotationParser.findDasmAnnotations(targetClass));
var classTransform = handleError(this.annotationParser.buildContext().buildClassTarget(targetClass));
var methodTransformsTarget = handleError(this.annotationParser.buildContext().buildMethodTargets(targetClass, "cc_dasm$"));

var methodTransforms = Stream.of(methodTransformsTarget, methodTransformsMixin)
.filter(Optional::isPresent).map(Optional::get)
Expand All @@ -116,7 +122,11 @@ public ASMConfigPlugin() {
}
});
}
} catch (ClassNotFoundException | IOException | DasmException e) {
} catch (DasmException e) {
throw new RuntimeException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
Expand Down Expand Up @@ -245,7 +255,7 @@ private boolean transformClass(String targetClassName, ClassNode targetClass, St
return false;
}

if (target.isLeft()) {
if (target.left().isPresent()) {
this.transformer.transform(targetClass, target.left().get());
} else {
this.transformer.transform(targetClass, target.right().get());
Expand All @@ -262,4 +272,31 @@ private boolean transformClass(String targetClassName, ClassNode targetClass, St

return true;
}

private <T> T handleError(Pair<T, List<Notification>> result) {
handleError(result.second());
return result.first();
}

private void handleError(NotifyStack notifyStack) {
handleError(notifyStack.notifications());
}

private void handleError(List<Notification> notifications) {
for (var notification : notifications) {
switch (notification.kind) {
case INFO:
logger.info(notification.message);
break;
case WARNING:
logger.warn(notification.message);
break;
case ERROR:
logger.error(notification.message);
break;
}
}
if (notifications.stream().anyMatch(n -> n.kind == Notification.Kind.ERROR))
throw Util.pauseInIde(new RuntimeException("DASM Failure, please see log output"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
@Dasm(ChunkToCubeSet.class)
@Mixin(ClientChunkCache.class)
public abstract class MixinClientChunkCache extends MixinChunkSource implements ClientCubeCache {
@AddFieldToSets(sets = ChunkToCubeSet.class, owner = @Ref(ClientChunkCache.class),
@AddFieldToSets(containers = ChunkToCubeSet.ClientChunkCache_redirects.class,
field = @FieldSig(type = @Ref(ClientChunkCache.Storage.class), name = "storage"))
volatile ClientCubeCache.Storage cc_cubeStorage;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
@Dasm(ChunkToCubeSet.class)
@Mixin(LevelRenderer.class)
public abstract class MixinLevelRenderer implements CubicLevelRenderer {
@AddTransformToSets(ChunkToCubeSet.class) @TransformFromMethod(@MethodSig("onChunkReadyToRender(Lnet/minecraft/world/level/ChunkPos;)V"))
@AddTransformToSets(ChunkToCubeSet.LevelRenderer_redirects.class) @TransformFromMethod(@MethodSig("onChunkReadyToRender(Lnet/minecraft/world/level/ChunkPos;)V"))
public native void cc_onCubeReadyToRender(CubePos cubePos);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ private void cc_onWaitAndReset(@Nullable ViewArea viewArea, CallbackInfo ci) {
cc_isCubic = viewArea != null && ((CanBeCubic) viewArea.getLevelHeightAccessor()).cc_isCubic();
}

@AddTransformToSets(ChunkToCubeSet.class) @TransformFromMethod(@MethodSig("onChunkReadyToRender(Lnet/minecraft/world/level/ChunkPos;)V"))
@AddTransformToSets(ChunkToCubeSet.SectionOcclusionGraph_redirects.class) @TransformFromMethod(@MethodSig("onChunkReadyToRender(Lnet/minecraft/world/level/ChunkPos;)V"))
public native void cc_onCubeReadyToRender(CubePos cubePos);

@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(SectionOcclusionGraph.class), method = @MethodSig("addNeighbors(Lnet/minecraft/client/renderer/SectionOcclusionGraph$GraphEvents;Lnet/minecraft/world/level/ChunkPos;)V"))
@AddMethodToSets(containers = ChunkToCubeSet.SectionOcclusionGraph_redirects.class, method = @MethodSig("addNeighbors(Lnet/minecraft/client/renderer/SectionOcclusionGraph$GraphEvents;Lnet/minecraft/world/level/ChunkPos;)V"))
private void cc_addNeighbors(SectionOcclusionGraph.GraphEvents graphEvents, CubePos cubePos) {
var access = ((SectionOcclusionGraph$GraphEventsAccess) (Object) graphEvents);
int cubeX = cubePos.getX();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class MixinGenerationChunkHolder_Forge {
@Shadow public LevelChunk currentlyLoading;

// Corresponds to field added by Forge
@AddFieldToSets(sets = ChunkToCubeSet.class, owner = @Ref(GenerationChunkHolder.class), field = @FieldSig(name = "currentlyLoading", type = @Ref(LevelChunk.class)))
@AddFieldToSets(containers = ChunkToCubeSet.GenerationChunkHolder_Forge_Jank_redirects.class, field = @FieldSig(name = "currentlyLoading", type = @Ref(LevelChunk.class)))
public LevelCube cc_currentlyLoadingCube;

public LevelClo cc_getCurrentlyLoading() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public abstract class MixinChunkGenerationTask implements CloGenerationTask {
@Shadow @Final public ChunkStatus targetStatus;
@Shadow private volatile boolean markedForCancellation;
@Shadow @Final private StaticCache2D<GenerationChunkHolder> cache;
@AddFieldToSets(sets = ChunkToCubeSet.class, owner = @Ref(ChunkGenerationTask.class), field = @FieldSig(type = @Ref(ChunkPos.class), name = "pos"))
@AddFieldToSets(containers = ChunkToCubeSet.ChunkGenerationTask_redirects.class, field = @FieldSig(type = @Ref(ChunkPos.class), name = "pos"))
private CubePos cc_cubePos;
// scheduledChunkStatus must be one status higher than the scheduled status for cubes until the target status is reached, to ensure load order invariants are preserved
// we use the vanilla field for cube status, since that is the status of the actual cube that is being generated
@Nullable public ChunkStatus cc_scheduledChunkStatus;
@AddFieldToSets(sets = ChunkToCubeSet.class, owner = @Ref(ChunkGenerationTask.class), field = @FieldSig(type = @Ref(StaticCache2D.class), name = "cache"))
@AddFieldToSets(containers = ChunkToCubeSet.ChunkGenerationTask_redirects.class, field = @FieldSig(type = @Ref(StaticCache2D.class), name = "cache"))
private StaticCache3D<GenerationChunkHolder> cc_cubeCache;

private GeneratingCubeMap cc_getGeneratingCubeMap() {
Expand All @@ -77,7 +77,7 @@ private GeneratingCubeMap cc_getGeneratingCubeMap() {
/**
* Factory method to create a {@code ChunkGenerationTask} for a cube.
*/
@AddMethodToSets(sets = ChunkToCubeSet.class, owner = @Ref(ChunkGenerationTask.class), method = @MethodSig("create(Lnet/minecraft/server/level/GeneratingChunkMap;Lnet/minecraft/world/level/chunk/status/ChunkStatus;Lnet/minecraft/world/level/ChunkPos;)Lnet/minecraft/server/level/ChunkGenerationTask;"))
@AddMethodToSets(containers = ChunkToCubeSet.ChunkGenerationTask_redirects.class, method = @MethodSig("create(Lnet/minecraft/server/level/GeneratingChunkMap;Lnet/minecraft/world/level/chunk/status/ChunkStatus;Lnet/minecraft/world/level/ChunkPos;)Lnet/minecraft/server/level/ChunkGenerationTask;"))
@Public private static ChunkGenerationTask cc_createCubeGenerationTask(GeneratingChunkMap chunkMap, ChunkStatus targetStatus, CubePos pos) {
int cubeRadius = CubePyramid.CC_GENERATION_PYRAMID_CUBES.getStepTo(targetStatus).getAccumulatedRadiusOf(ChunkStatus.EMPTY);
int cubeDiameter = cubeRadius * 2 + 1;
Expand All @@ -94,7 +94,7 @@ private GeneratingCubeMap cc_getGeneratingCubeMap() {
return chunkGenerationTask;
}

@AddMethodToSets(sets = ChunkToCloSet.class, owner = @Ref(ChunkGenerationTask.class), method = @MethodSig("create(Lnet/minecraft/server/level/GeneratingChunkMap;Lnet/minecraft/world/level/chunk/status/ChunkStatus;Lnet/minecraft/world/level/ChunkPos;)Lnet/minecraft/server/level/ChunkGenerationTask;"))
@AddMethodToSets(containers = ChunkToCloSet.ChunkGenerationTask_redirects.class, method = @MethodSig("create(Lnet/minecraft/server/level/GeneratingChunkMap;Lnet/minecraft/world/level/chunk/status/ChunkStatus;Lnet/minecraft/world/level/ChunkPos;)Lnet/minecraft/server/level/ChunkGenerationTask;"))
@Public private static ChunkGenerationTask cc_createCubeGenerationTask(GeneratingChunkMap chunkMap, ChunkStatus targetStatus, CloPos pos) {
if (pos.isCube()) {
return cc_createCubeGenerationTask(chunkMap, targetStatus, pos.cubePos());
Expand Down
Loading