Skip to content

Commit

Permalink
- 新增 ASMModParser 优化。
Browse files Browse the repository at this point in the history
- 尝试修复 MixinTileRuneAltar 的一些问题。
- 为 NBTPrimitiveConstantsPool 功能增强了兼容性。
  • Loading branch information
KasumiNova committed Nov 15, 2024
1 parent b6df448 commit 981bf16
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {

// Project properties
group = "github.kasuminova.stellarcore"
version = "1.5.17"
version = "1.5.19"

// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
java {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ public static class Vanilla {
@Config.Comment({
"(Client/Server Performance) Cache constants -32768 - 32767 of NBTTagByte, NBTTagInt, NBTTagLong, NBTTagFloat, NBTTagDouble using constant pool.",
"Like IntegerCache in the JVM, improves memory usage and reduces object creation overhead.",
"Note: Some mods may not comply with the specification causing NBTBase to be loaded prematurely, so there may be a higher probability of problems with this feature.",
"Incompatible with old version of Quark (< r1.6-189), which modifies the bytecode of the NBTTag class too early.",
})
@Config.RequiresMcRestart
Expand Down Expand Up @@ -334,6 +335,10 @@ public static class Forge {
@Config.Name("ASMDataTableCPUUsageImprovements")
public boolean asmDataTable = false;

@Config.Comment("(Client/Server Performance) Improved performance of ASMModParser in parsing bytecode, improved startup speed (~1 ~ 5 seconds).")
@Config.Name("ASMModParserImprovements")
public boolean asmModParser = true;

@Config.Comment("(Client/Server Performance) ChunkManager optimisation, improves performance in more player environments.")
@Config.RequiresMcRestart
@Config.Name("ChunkManager")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class StellarCoreEarlyMixinLoader implements IFMLLoadingPlugin {
addMixinCFG("mixins.stellar_core_minecraft_texture_load.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelTextureLoad);
addMixinCFG("mixins.stellar_core_forge.json", () -> StellarCoreConfig.PERFORMANCE.customLoadingScreen.splashProgress);
addMixinCFG("mixins.stellar_core_forge_asmdatatable.json", () -> StellarCoreConfig.PERFORMANCE.forge.asmDataTable);
addMixinCFG("mixins.stellar_core_forge_asmmodparser.json", () -> StellarCoreConfig.PERFORMANCE.forge.asmModParser);
addMixinCFG("mixins.stellar_core_forge_bakedquad.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_bakedquad_vertexdata.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadVertexDataCanonicalization);
addMixinCFG("mixins.stellar_core_forge_capability.json", () -> StellarCoreConfig.PERFORMANCE.forge.deallocateEmptyCapabilityNBT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import vazkii.botania.api.recipe.RecipeRuneAltar;
import vazkii.botania.common.block.tile.TileRuneAltar;
import vazkii.botania.common.block.tile.TileSimpleInventory;

Expand All @@ -23,6 +24,9 @@ public abstract class MixinTileRuneAltar extends TileSimpleInventory {
@Shadow(remap = false)
public abstract boolean isEmpty();

@Shadow(remap = false)
RecipeRuneAltar currentRecipe;

@Unique
private boolean stellar_core$shouldGetEntities = true;

Expand All @@ -32,7 +36,7 @@ private void injectUpdateRecipe(final CallbackInfo ci) {
return;
}

if (isEmpty()) {
if (this.currentRecipe == null && isEmpty()) {
ci.cancel();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package github.kasuminova.stellarcore.mixin.minecraft.forge.asmmodparser;

import net.minecraftforge.fml.common.discovery.asm.ASMModParser;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;

@SuppressWarnings("MethodMayBeStatic")
@Mixin(value = ASMModParser.class, remap = false)
public class MixinASMModParser {

@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/objectweb/asm/ClassReader;accept(Lorg/objectweb/asm/ClassVisitor;I)V"))
private void redirectInit(final ClassReader instance, final ClassVisitor classVisitor, final int flags) {
instance.accept(classVisitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class MixinNBTTagCompound {
@SuppressWarnings("MethodMayBeStatic")
@Redirect(method = "read", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", remap = false))
private Object redirectRead(final Map<Object, Object> instance, final Object key, final Object value) {
return instance.put(key, ((StellarPooledNBT) value).stellar_core$getPooledNBT());
return instance.put(key, StellarPooledNBT.stellar_core$getPooledNBT((NBTBase) value));
}

/**
Expand All @@ -39,7 +39,7 @@ public void setTag(String key, NBTBase value) {
if (value == null) {
throw new IllegalArgumentException("Invalid null NBT value with key " + key);
}
this.tagMap.put(key, (NBTBase) ((StellarPooledNBT) value).stellar_core$getPooledNBT());
this.tagMap.put(key, (NBTBase) StellarPooledNBT.stellar_core$getPooledNBT(value));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package github.kasuminova.stellarcore.mixin.minecraft.nbtpool;

import github.kasuminova.stellarcore.mixin.util.StellarPooledNBT;
import net.minecraft.nbt.NBTBase;
import net.minecraft.nbt.NBTTagList;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand All @@ -18,17 +19,17 @@ public class MixinNBTTagList {
*/
@Redirect(method = "read", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", remap = false))
private boolean redirectRead(final List<Object> instance, final Object element) {
return instance.add(((StellarPooledNBT) element).stellar_core$getPooledNBT());
return instance.add(StellarPooledNBT.stellar_core$getPooledNBT((NBTBase) element));
}

@Redirect(method = "appendTag", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", remap = false))
private boolean redirectAppendTag(final List<Object> instance, final Object element) {
return instance.add(((StellarPooledNBT) element).stellar_core$getPooledNBT());
return instance.add(StellarPooledNBT.stellar_core$getPooledNBT((NBTBase) element));
}

@Redirect(method = "set", at = @At(value = "INVOKE", target = "Ljava/util/List;set(ILjava/lang/Object;)Ljava/lang/Object;", remap = false))
private Object redirectSet(final List<Object> instance, final int i, final Object element) {
return instance.set(i, ((StellarPooledNBT) element).stellar_core$getPooledNBT());
return instance.set(i, StellarPooledNBT.stellar_core$getPooledNBT((NBTBase) element));
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package github.kasuminova.stellarcore.mixin.util;

import net.minecraft.nbt.NBTBase;

public interface StellarPooledNBT {

static Object stellar_core$getPooledNBT(final NBTBase nbt) {
try {
return ((StellarPooledNBT) nbt).stellar_core$getPooledNBT();
} catch (ClassCastException e) {
return nbt;
}
}

/**
* 返回 Object 来兼容其他模组的反射。
*/
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/mixins.stellar_core_forge_asmmodparser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"package": "github.kasuminova.stellarcore.mixin.minecraft.forge.asmmodparser",
"refmap": "mixins.stellar_core.refmap.json",
"target": "@env(DEFAULT)",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinASMModParser"
]
}

0 comments on commit 981bf16

Please sign in to comment.