Skip to content

Commit 981bf16

Browse files
committed
- 新增 ASMModParser 优化。
- 尝试修复 MixinTileRuneAltar 的一些问题。 - 为 NBTPrimitiveConstantsPool 功能增强了兼容性。
1 parent b6df448 commit 981bf16

File tree

9 files changed

+57
-7
lines changed

9 files changed

+57
-7
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212

1313
// Project properties
1414
group = "github.kasuminova.stellarcore"
15-
version = "1.5.17"
15+
version = "1.5.19"
1616

1717
// Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod
1818
java {

src/main/java/github/kasuminova/stellarcore/common/config/category/Performance.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ public static class Vanilla {
205205
@Config.Comment({
206206
"(Client/Server Performance) Cache constants -32768 - 32767 of NBTTagByte, NBTTagInt, NBTTagLong, NBTTagFloat, NBTTagDouble using constant pool.",
207207
"Like IntegerCache in the JVM, improves memory usage and reduces object creation overhead.",
208+
"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.",
208209
"Incompatible with old version of Quark (< r1.6-189), which modifies the bytecode of the NBTTag class too early.",
209210
})
210211
@Config.RequiresMcRestart
@@ -334,6 +335,10 @@ public static class Forge {
334335
@Config.Name("ASMDataTableCPUUsageImprovements")
335336
public boolean asmDataTable = false;
336337

338+
@Config.Comment("(Client/Server Performance) Improved performance of ASMModParser in parsing bytecode, improved startup speed (~1 ~ 5 seconds).")
339+
@Config.Name("ASMModParserImprovements")
340+
public boolean asmModParser = true;
341+
337342
@Config.Comment("(Client/Server Performance) ChunkManager optimisation, improves performance in more player environments.")
338343
@Config.RequiresMcRestart
339344
@Config.Name("ChunkManager")

src/main/java/github/kasuminova/stellarcore/mixin/StellarCoreEarlyMixinLoader.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class StellarCoreEarlyMixinLoader implements IFMLLoadingPlugin {
5656
addMixinCFG("mixins.stellar_core_minecraft_texture_load.json", () -> StellarCoreConfig.PERFORMANCE.vanilla.parallelTextureLoad);
5757
addMixinCFG("mixins.stellar_core_forge.json", () -> StellarCoreConfig.PERFORMANCE.customLoadingScreen.splashProgress);
5858
addMixinCFG("mixins.stellar_core_forge_asmdatatable.json", () -> StellarCoreConfig.PERFORMANCE.forge.asmDataTable);
59+
addMixinCFG("mixins.stellar_core_forge_asmmodparser.json", () -> StellarCoreConfig.PERFORMANCE.forge.asmModParser);
5960
addMixinCFG("mixins.stellar_core_forge_bakedquad.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadDataCanonicalization);
6061
addMixinCFG("mixins.stellar_core_forge_bakedquad_vertexdata.json", () -> StellarCoreConfig.PERFORMANCE.forge.unpackedBakedQuadVertexDataCanonicalization);
6162
addMixinCFG("mixins.stellar_core_forge_capability.json", () -> StellarCoreConfig.PERFORMANCE.forge.deallocateEmptyCapabilityNBT);

src/main/java/github/kasuminova/stellarcore/mixin/botania/MixinTileRuneAltar.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.spongepowered.asm.mixin.injection.Inject;
1212
import org.spongepowered.asm.mixin.injection.Redirect;
1313
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
14+
import vazkii.botania.api.recipe.RecipeRuneAltar;
1415
import vazkii.botania.common.block.tile.TileRuneAltar;
1516
import vazkii.botania.common.block.tile.TileSimpleInventory;
1617

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

27+
@Shadow(remap = false)
28+
RecipeRuneAltar currentRecipe;
29+
2630
@Unique
2731
private boolean stellar_core$shouldGetEntities = true;
2832

@@ -32,7 +36,7 @@ private void injectUpdateRecipe(final CallbackInfo ci) {
3236
return;
3337
}
3438

35-
if (isEmpty()) {
39+
if (this.currentRecipe == null && isEmpty()) {
3640
ci.cancel();
3741
}
3842
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package github.kasuminova.stellarcore.mixin.minecraft.forge.asmmodparser;
2+
3+
import net.minecraftforge.fml.common.discovery.asm.ASMModParser;
4+
import org.objectweb.asm.ClassReader;
5+
import org.objectweb.asm.ClassVisitor;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.injection.At;
8+
import org.spongepowered.asm.mixin.injection.Redirect;
9+
10+
@SuppressWarnings("MethodMayBeStatic")
11+
@Mixin(value = ASMModParser.class, remap = false)
12+
public class MixinASMModParser {
13+
14+
@Redirect(method = "<init>", at = @At(value = "INVOKE", target = "Lorg/objectweb/asm/ClassReader;accept(Lorg/objectweb/asm/ClassVisitor;I)V"))
15+
private void redirectInit(final ClassReader instance, final ClassVisitor classVisitor, final int flags) {
16+
instance.accept(classVisitor, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
17+
}
18+
19+
}

src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagCompound.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public class MixinNBTTagCompound {
2727
@SuppressWarnings("MethodMayBeStatic")
2828
@Redirect(method = "read", at = @At(value = "INVOKE", target = "Ljava/util/Map;put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", remap = false))
2929
private Object redirectRead(final Map<Object, Object> instance, final Object key, final Object value) {
30-
return instance.put(key, ((StellarPooledNBT) value).stellar_core$getPooledNBT());
30+
return instance.put(key, StellarPooledNBT.stellar_core$getPooledNBT((NBTBase) value));
3131
}
3232

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

4545
/**

src/main/java/github/kasuminova/stellarcore/mixin/minecraft/nbtpool/MixinNBTTagList.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package github.kasuminova.stellarcore.mixin.minecraft.nbtpool;
22

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

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

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

3435
}

src/main/java/github/kasuminova/stellarcore/mixin/util/StellarPooledNBT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package github.kasuminova.stellarcore.mixin.util;
22

3+
import net.minecraft.nbt.NBTBase;
4+
35
public interface StellarPooledNBT {
46

7+
static Object stellar_core$getPooledNBT(final NBTBase nbt) {
8+
try {
9+
return ((StellarPooledNBT) nbt).stellar_core$getPooledNBT();
10+
} catch (ClassCastException e) {
11+
return nbt;
12+
}
13+
}
14+
515
/**
616
* 返回 Object 来兼容其他模组的反射。
717
*/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"package": "github.kasuminova.stellarcore.mixin.minecraft.forge.asmmodparser",
3+
"refmap": "mixins.stellar_core.refmap.json",
4+
"target": "@env(DEFAULT)",
5+
"minVersion": "0.8",
6+
"compatibilityLevel": "JAVA_8",
7+
"mixins": [
8+
"MixinASMModParser"
9+
]
10+
}

0 commit comments

Comments
 (0)