Fix field remapping with same name in hierarchy (#539 #550)

Update AGP to 1.23
This commit is contained in:
IzzelAliz 2022-06-23 00:09:06 +08:00
parent 31bb3bbecc
commit 999b9bb30e
No known key found for this signature in database
GPG Key ID: EE50E123A11D8338
8 changed files with 27 additions and 33 deletions

View File

@ -65,7 +65,7 @@ dependencies {
annotationProcessor 'com.github.ArclightTeam:mixin-tools:1.0.0'
implementation 'jline:jline:2.12.1'
implementation 'net.md-5:SpecialSource:1.9.0'
implementation 'net.md-5:SpecialSource:1.11.0'
implementation 'org.apache.logging.log4j:log4j-jul:2.15.0'
implementation 'net.md-5:bungeecord-chat:1.16-R0.4'
implementation 'mysql:mysql-connector-java:5.1.49'

View File

@ -109,7 +109,7 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerWorld
// @formatter:on
@SuppressWarnings({"FieldCanBeLocal", "unused"})
public PrimaryLevelData $$worldDataServer;
public PrimaryLevelData M; // TODO f_8549_ check on update
private int tickPosition;
public LevelStorageSource.LevelStorageAccess convertable;
public UUID uuid;
@ -153,10 +153,10 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerWorld
}
}
if (worldInfo instanceof PrimaryLevelData) {
this.$$worldDataServer = (PrimaryLevelData) worldInfo;
this.M = (PrimaryLevelData) worldInfo;
} else if (worldInfo instanceof DerivedLevelData) {
// damn spigot again
this.$$worldDataServer = DelegateWorldInfo.wrap(((DerivedLevelData) worldInfo));
this.M = DelegateWorldInfo.wrap(((DerivedLevelData) worldInfo));
((DerivedWorldInfoBridge) worldInfo).bridge$setDimType(this.getTypeKey());
if (ArclightConfig.spec().getCompat().isSymlinkWorld()) {
WorldSymlink.create((DerivedLevelData) worldInfo, levelSave.getDimensionPath(this.dimension()).toFile());
@ -165,7 +165,7 @@ public abstract class ServerLevelMixin extends LevelMixin implements ServerWorld
this.spigotConfig = new SpigotWorldConfig(worldInfo.getLevelName());
this.uuid = WorldUUID.getUUID(levelSave.getDimensionPath(this.dimension()).toFile());
((ServerChunkProviderBridge) this.chunkSource).bridge$setViewDistance(spigotConfig.viewDistance);
((WorldInfoBridge) this.$$worldDataServer).bridge$setWorld((ServerLevel) (Object) this);
((WorldInfoBridge) this.M).bridge$setWorld((ServerLevel) (Object) this);
var data = this.getDataStorage().computeIfAbsent(LevelPersistentData::new, () -> new LevelPersistentData(null), "bukkit_pdc");
this.bridge$getWorld().readBukkitValues(data.getTag());
}

View File

@ -44,12 +44,12 @@ public abstract class LevelChunkMixin extends ChunkAccessMixin implements ChunkB
public boolean mustNotSave;
public boolean needsDecoration;
private transient boolean arclight$doPlace;
public ServerLevel $$level;
public ServerLevel q; // TODO f_62776_ check on update
@Inject(method = "<init>(Lnet/minecraft/world/level/Level;Lnet/minecraft/world/level/ChunkPos;Lnet/minecraft/world/level/chunk/UpgradeData;Lnet/minecraft/world/ticks/LevelChunkTicks;Lnet/minecraft/world/ticks/LevelChunkTicks;J[Lnet/minecraft/world/level/chunk/LevelChunkSection;Lnet/minecraft/world/level/chunk/LevelChunk$PostLoadProcessor;Lnet/minecraft/world/level/levelgen/blending/BlendingData;)V", at = @At("RETURN"))
private void arclight$init(Level worldIn, ChunkPos p_196855_, UpgradeData p_196856_, LevelChunkTicks<Block> p_196857_, LevelChunkTicks<Fluid> p_196858_, long p_196859_, @Nullable LevelChunkSection[] p_196860_, @Nullable LevelChunk.PostLoadProcessor p_196861_, @Nullable BlendingData p_196862_, CallbackInfo ci) {
if (DistValidate.isValid(worldIn)) {
this.$$level = ((ServerLevel) worldIn);
this.q = ((ServerLevel) worldIn);
this.bukkitChunk = new CraftChunk((LevelChunk) (Object) this);
}
}

View File

@ -7,7 +7,6 @@ import com.google.common.collect.Maps;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.AbstractInsnNode;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldInsnNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.InsnList;
import org.objectweb.asm.tree.MethodInsnNode;
@ -106,10 +105,10 @@ public class ArclightMixinPlugin implements IMixinConfigPlugin {
.build();
// damn spigot
private final Map<String, Map<String, String>> fieldRenames = ImmutableMap.<String, Map<String, String>>builder()
.put("net.minecraft.world.level.chunk.LevelChunk", ImmutableMap.of("$$level", "f_62776_"))
.put("net.minecraft.server.level.ServerLevel", ImmutableMap.of("$$worldDataServer", "f_8549_"))
.build();
//private final Map<String, Map<String, String>> fieldRenames = ImmutableMap.<String, Map<String, String>>builder()
// .put("net.minecraft.world.level.chunk.LevelChunk", ImmutableMap.of("$$level", "f_62776_"))
// .put("net.minecraft.server.level.ServerLevel", ImmutableMap.of("$$worldDataServer", "f_8549_"))
// .build();
private final Set<String> modifyConstructor = ImmutableSet.<String>builder()
.add("net.minecraft.world.level.Level")
@ -173,23 +172,6 @@ public class ArclightMixinPlugin implements IMixinConfigPlugin {
}
}
modifyConstructor(targetClassName, targetClass);
renameFields(targetClassName, targetClass);
}
private void renameFields(String targetClassName, ClassNode classNode) {
Map<String, String> map = this.fieldRenames.get(targetClassName);
if (map != null) {
for (FieldNode field : classNode.fields) {
field.name = map.getOrDefault(field.name, field.name);
}
for (MethodNode method : classNode.methods) {
for (AbstractInsnNode instruction : method.instructions) {
if (instruction instanceof FieldInsnNode node) {
node.name = map.getOrDefault(node.name, node.name);
}
}
}
}
}
private void modifyConstructor(String targetClassName, ClassNode classNode) {

View File

@ -18,6 +18,8 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
@ -68,8 +70,18 @@ public class ArclightRemapper {
new BufferedReader(new InputStreamReader(ArclightRemapper.class.getResourceAsStream("/bukkit_srg.srg"))),
null, null, false
);
// TODO workaround for https://github.com/md-5/SpecialSource/pull/81
// remove on update
var content = new String(ArclightRemapper.class.getResourceAsStream("/bukkit_srg.srg").readAllBytes(), StandardCharsets.UTF_8);
var i = content.indexOf("net/minecraft/server/level/ChunkMap net/minecraft/server/level/ChunkTracker");
var nextSection = content.substring(i).lines().skip(1).dropWhile(it -> it.startsWith("\t")).findFirst().orElseThrow();
var nextIndex = content.indexOf(nextSection);
this.toBukkitMapping.loadMappings(
new BufferedReader(new InputStreamReader(ArclightRemapper.class.getResourceAsStream("/bukkit_srg.srg"))),
new BufferedReader(new StringReader(content.substring(0, i) + content.substring(nextIndex))),
null, null, true
);
this.toBukkitMapping.loadMappings(
new BufferedReader(new StringReader(content.substring(i, nextIndex))),
null, null, true
);
BiMap<String, String> inverseClassMap = HashBiMap.create(toNmsMapping.classes).inverse();

View File

@ -200,7 +200,7 @@ public class ClassLoaderRemapper extends LenientJarRemapper {
private String mapField(Field field) {
String owner = Type.getInternalName(field.getDeclaringClass());
String srgName = field.getName();
String desc = Type.getInternalName(field.getType());
String desc = Type.getDescriptor(field.getType());
return toBukkitRemapper.mapFieldName(owner, srgName, desc, -1);
}

View File

@ -44,7 +44,7 @@ repositories {
def embedLibs = [/*"org.spongepowered:mixin:$mixinVersion", */ 'org.yaml:snakeyaml:1.30',
'org.xerial:sqlite-jdbc:3.36.0.3', 'mysql:mysql-connector-java:8.0.27',
/*'commons-lang:commons-lang:2.6',*/ 'com.googlecode.json-simple:json-simple:1.1.1',
'org.apache.logging.log4j:log4j-jul:2.17.0', 'net.md-5:SpecialSource:1.10.0',
'org.apache.logging.log4j:log4j-jul:2.17.0', 'net.md-5:SpecialSource:1.11.0',
'org.jline:jline-terminal-jansi:3.12.1', 'org.fusesource.jansi:jansi:1.18',
/*'org.jline:jline-terminal:3.12.1', 'org.jline:jline-reader:3.12.1',*/
'jline:jline:2.12.1', 'org.apache.maven:maven-resolver-provider:3.8.1',

View File

@ -12,7 +12,7 @@ allprojects {
}
ext {
agpVersion = '1.22'
agpVersion = '1.23'
minecraftVersion = '1.18.2'
forgeVersion = '40.1.31'
apiVersion = '1.2.6'