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

Support class/string targets in dasm annotations #19

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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ dependencies {
targetConfiguration = "testArchivesOutput"
}

libraries("com.github.OpenCubicChunks:dasm:9d5aa6b061") {
libraries("com.github.OpenCubicChunks:dasm:da8944f034") {
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 @@ -10,7 +10,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -234,10 +233,7 @@ private static void buildClassTarget(ClassNode targetClass, RedirectsParser.Clas
String name = (String) values.get(i);
Object value = values.get(i + 1);
if (name.equals("value")) {
Type val = (Type) value;
if (!Objects.equals(val, Type.getObjectType(Object.class.getName()))) { // Special case the default
srcClass = val;
}
srcClass = parseCopyFromAnnotation((AnnotationNode) value);
} else if (name.equals("stage")) {
var parts = ((String[]) value);
requestedStage = TransformFrom.ApplicationStage.valueOf(parts[1]);
Expand Down Expand Up @@ -283,12 +279,7 @@ private static void buildClassTarget(ClassNode targetClass, RedirectsParser.Clas
var parts = ((String[]) value);
requestedStage = TransformFrom.ApplicationStage.valueOf(parts[1]);
}
case "copyFrom" -> {
var val = (Type) value;
if (!Objects.equals(val, Type.getObjectType(Object.class.getName()))) { // Special case the default
srcOwner = val;
}
}
case "copyFrom" -> srcOwner = parseCopyFromAnnotation((AnnotationNode) value);
}
}
if (stage != requestedStage) {
Expand Down Expand Up @@ -324,6 +315,17 @@ private static void buildClassTarget(ClassNode targetClass, RedirectsParser.Clas
}
}

private static Type parseCopyFromAnnotation(AnnotationNode copyFromAnnotation) {
assert copyFromAnnotation.values.size() == 2 : "CopyFrom annotation has multiple targeting fields";

if ((copyFromAnnotation.values.get(0)).equals("clazz")) {
return (Type) copyFromAnnotation.values.get(1);
} else if ((copyFromAnnotation.values.get(0)).equals("string")) {
return Type.getObjectType((String) copyFromAnnotation.values.get(1));
}
return Type.getType(Object.class);
}

private static String parseMethodDescriptor(AnnotationNode ann) {
if (ann == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.github.opencubicchunks.cubicchunks.mixin;

public @interface CopyFrom {
Class<?> clazz() default Object.class;

String string() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

String value();

Class<?> copyFrom() default Object.class;
CopyFrom copyFrom() default @CopyFrom();

Signature signature() default @Signature(fromString = true);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.opencubicchunks.cubicchunks.mixin;

public @interface TransformFromClass {
Class<?> value();
CopyFrom value();

TransformFrom.ApplicationStage stage() default TransformFrom.ApplicationStage.PRE_APPLY;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alas, it was so young

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.github.opencubicchunks.cc_core.api.CubicConstants;
import io.github.opencubicchunks.cc_core.utils.Coords;
import io.github.opencubicchunks.cubicchunks.CubicChunks;
import io.github.opencubicchunks.cubicchunks.mixin.CopyFrom;
import io.github.opencubicchunks.cubicchunks.mixin.DasmRedirect;
import io.github.opencubicchunks.cubicchunks.mixin.TransformFrom;
import io.github.opencubicchunks.cubicchunks.world.level.chunklike.CloAccess;
Expand Down Expand Up @@ -127,13 +128,13 @@ private static void replaceMissingSections(Registry<Biome> p_281389_, LevelChunk
return this.getMinBuildHeight();
}

@TransformFrom(copyFrom = ChunkAccess.class, value = "getBlockEntitiesPos()Ljava/util/Set;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getBlockEntitiesPos()Ljava/util/Set;")
@Override public native Set<BlockPos> getBlockEntitiesPos();

@TransformFrom(copyFrom = ChunkAccess.class, value = "getSections()[Lnet/minecraft/world/level/chunk/LevelChunkSection;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getSections()[Lnet/minecraft/world/level/chunk/LevelChunkSection;")
@Override public native LevelChunkSection[] getSections();

@TransformFrom(copyFrom = ChunkAccess.class, value = "getSection(I)Lnet/minecraft/world/level/chunk/LevelChunkSection;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getSection(I)Lnet/minecraft/world/level/chunk/LevelChunkSection;")
@Override public native LevelChunkSection getSection(int p_187657_);

// TODO (P2) heightmap methods on cubes
Expand Down Expand Up @@ -161,42 +162,42 @@ private static void replaceMissingSections(Registry<Biome> p_281389_, LevelChunk
return cloPos;
}

@TransformFrom(copyFrom = ChunkAccess.class, value = "getStartForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;)"
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getStartForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;)"
+ "Lnet/minecraft/world/level/levelgen/structure/StructureStart;")
@Override @Nullable public native StructureStart getStartForStructure(Structure p_223005_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "setStartForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;"
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setStartForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;"
+ "Lnet/minecraft/world/level/levelgen/structure/StructureStart;)V")
@Override public native void setStartForStructure(Structure p_223010_, StructureStart p_223011_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getAllStarts()Ljava/util/Map;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getAllStarts()Ljava/util/Map;")
@Override public native Map<Structure, StructureStart> getAllStarts();

@TransformFrom(copyFrom = ChunkAccess.class, value = "setAllStarts(Ljava/util/Map;)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setAllStarts(Ljava/util/Map;)V")
@Override public native void setAllStarts(Map<Structure, StructureStart> p_62090_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getReferencesForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;)"
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getReferencesForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;)"
+ "Lit/unimi/dsi/fastutil/longs/LongSet;")
@Override public native LongSet getReferencesForStructure(Structure p_223017_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "addReferenceForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;J)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "addReferenceForStructure(Lnet/minecraft/world/level/levelgen/structure/Structure;J)V")
@Override public native void addReferenceForStructure(Structure p_223007_, long p_223008_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getAllReferences()Ljava/util/Map;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getAllReferences()Ljava/util/Map;")
@Override public native Map<Structure, LongSet> getAllReferences();

@TransformFrom(copyFrom = ChunkAccess.class, value = "setAllReferences(Ljava/util/Map;)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setAllReferences(Ljava/util/Map;)V")
@Override public native void setAllReferences(Map<Structure, LongSet> p_187663_);

@Override public boolean isYSpaceEmpty(int p_62075_, int p_62076_) {
// TODO
return false;
}

@TransformFrom(copyFrom = ChunkAccess.class, value = "setUnsaved(Z)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setUnsaved(Z)V")
@Override public native void setUnsaved(boolean p_62094_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "isUnsaved()Z")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "isUnsaved()Z")
@Override public native boolean isUnsaved();

@Override public abstract ChunkStatus getStatus();
Expand All @@ -208,28 +209,28 @@ private static void replaceMissingSections(Registry<Biome> p_281389_, LevelChunk

@Override public abstract void removeBlockEntity(BlockPos p_62101_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "markPosForPostprocessing(Lnet/minecraft/core/BlockPos;)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "markPosForPostprocessing(Lnet/minecraft/core/BlockPos;)V")
@Override public native void markPosForPostprocessing(BlockPos p_62102_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getPostProcessing()[Lit/unimi/dsi/fastutil/shorts/ShortList;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getPostProcessing()[Lit/unimi/dsi/fastutil/shorts/ShortList;")
@Override public native ShortList[] getPostProcessing();

@TransformFrom(copyFrom = ChunkAccess.class, value = "addPackedPostProcess(SI)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "addPackedPostProcess(SI)V")
@Override public native void addPackedPostProcess(short p_62092_, int p_62093_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "setBlockEntityNbt(Lnet/minecraft/nbt/CompoundTag;)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setBlockEntityNbt(Lnet/minecraft/nbt/CompoundTag;)V")
@Override public native void setBlockEntityNbt(CompoundTag p_62091_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getBlockEntityNbt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/nbt/CompoundTag;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getBlockEntityNbt(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/nbt/CompoundTag;")
@Override @Nullable public native CompoundTag getBlockEntityNbt(BlockPos p_62103_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getBlockEntityNbtForSaving(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/nbt/CompoundTag;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getBlockEntityNbtForSaving(Lnet/minecraft/core/BlockPos;)Lnet/minecraft/nbt/CompoundTag;")
@Override @Nullable public native CompoundTag getBlockEntityNbtForSaving(BlockPos p_62104_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "findBlockLightSources(Ljava/util/function/BiConsumer;)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "findBlockLightSources(Ljava/util/function/BiConsumer;)V")
@Override public native void findBlockLightSources(BiConsumer<BlockPos, BlockState> p_285269_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "findBlocks(Ljava/util/function/Predicate;Ljava/util/function/BiConsumer;)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "findBlocks(Ljava/util/function/Predicate;Ljava/util/function/BiConsumer;)V")
@Override public native void findBlocks(Predicate<BlockState> p_285343_, BiConsumer<BlockPos, BlockState> p_285030_);

@Override public void findBlocks(BiPredicate<BlockState, BlockPos> p_285343_, BiConsumer<BlockPos, BlockState> p_285030_) {
Expand Down Expand Up @@ -265,37 +266,37 @@ private static void replaceMissingSections(Registry<Biome> p_281389_, LevelChunk

@Override public abstract ChunkAccess.TicksToSave getTicksForSerialization();

@TransformFrom(copyFrom = ChunkAccess.class, value = "getUpgradeData()Lnet/minecraft/world/level/chunk/UpgradeData;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getUpgradeData()Lnet/minecraft/world/level/chunk/UpgradeData;")
@Override public native UpgradeData getUpgradeData();

@TransformFrom(copyFrom = ChunkAccess.class, value = "isOldNoiseGeneration()Z")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "isOldNoiseGeneration()Z")
@Override public native boolean isOldNoiseGeneration();

@TransformFrom(copyFrom = ChunkAccess.class, value = "getBlendingData()Lnet/minecraft/world/level/levelgen/blending/BlendingData;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getBlendingData()Lnet/minecraft/world/level/levelgen/blending/BlendingData;")
@Override @Nullable public native BlendingData getBlendingData();

@TransformFrom(copyFrom = ChunkAccess.class, value = "setBlendingData(Lnet/minecraft/world/level/levelgen/blending/BlendingData;)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setBlendingData(Lnet/minecraft/world/level/levelgen/blending/BlendingData;)V")
@Override public native void setBlendingData(BlendingData p_187646_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getInhabitedTime()J")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getInhabitedTime()J")
@Override public native long getInhabitedTime();

@TransformFrom(copyFrom = ChunkAccess.class, value = "incrementInhabitedTime(J)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "incrementInhabitedTime(J)V")
@Override public native void incrementInhabitedTime(long p_187633_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "setInhabitedTime(J)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setInhabitedTime(J)V")
@Override public native void setInhabitedTime(long p_62099_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "isLightCorrect()Z")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "isLightCorrect()Z")
@Override public native boolean isLightCorrect();

@TransformFrom(copyFrom = ChunkAccess.class, value = "setLightCorrect(Z)V")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "setLightCorrect(Z)V")
@Override public native void setLightCorrect(boolean p_62100_);

@TransformFrom(copyFrom = ChunkAccess.class, value = "getMinBuildHeight()I")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getMinBuildHeight()I")
@Override public native int getMinBuildHeight();

@TransformFrom(copyFrom = ChunkAccess.class, value = "getHeight()I")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getHeight()I")
@Override public native int getHeight();

@Override public NoiseChunk getOrCreateNoiseChunk(Function<ChunkAccess, NoiseChunk> p_223013_) {
Expand All @@ -314,7 +315,7 @@ private static void replaceMissingSections(Registry<Biome> p_281389_, LevelChunk
throw new UnsupportedOperationException(); // TODO P3
}

@TransformFrom(copyFrom = ChunkAccess.class, value = "hasAnyStructureReferences()Z")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "hasAnyStructureReferences()Z")
@Override public native boolean hasAnyStructureReferences();

@Override @Nullable public BelowZeroRetrogen getBelowZeroRetrogen() {
Expand All @@ -325,7 +326,7 @@ private static void replaceMissingSections(Registry<Biome> p_281389_, LevelChunk
return false; // Used for below-zero retrogen; not applicable to cubes
}

@TransformFrom(copyFrom = ChunkAccess.class, value = "getHeightAccessorForGeneration()Lnet/minecraft/world/level/LevelHeightAccessor;")
@TransformFrom(copyFrom = @CopyFrom(clazz = ChunkAccess.class), value = "getHeightAccessorForGeneration()Lnet/minecraft/world/level/LevelHeightAccessor;")
@Override public native LevelHeightAccessor getHeightAccessorForGeneration();

@Override public void initializeLightSources() {
Expand Down
7 changes: 3 additions & 4 deletions src/main/resources/cubicchunks.mixins.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},
"mixins": [
"common.client.multiplayer.MixinClientLevel",
"common.server.MixinMinecraftServer",
"common.server.level.MixinChunkTaskPriorityQueue",
"common.server.level.MixinChunkTaskPriorityQueueSorter",
"common.server.level.MixinChunkTicketTracker",
Expand All @@ -24,11 +25,9 @@
"common.server.level.MixinServerLevel",
"common.server.level.MixinServerPlayer",
"common.server.level.MixinTickingTracker",
"common.server.MixinMinecraftServer",
"common.TestMixin",
"common.world.level.MixinLevel",
"common.world.level.chunk.MixinChunkAccess",
"common.world.level.cube.MixinCubeAccess",
"common.world.level.MixinLevel"
"common.world.level.cube.MixinCubeAccess"
],
"client": [],
"server": []
Expand Down
Loading