-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e90ecf2
commit 16ed4e0
Showing
29 changed files
with
1,154 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
.../java/com/mitchej123/hodgepodge/asm/transformers/mc/NBTTagCompoundHashMapTransformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.mitchej123.hodgepodge.asm.transformers.mc; | ||
|
||
import net.minecraft.launchwrapper.IClassTransformer; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.objectweb.asm.ClassReader; | ||
import org.objectweb.asm.ClassWriter; | ||
import org.objectweb.asm.Opcodes; | ||
import org.objectweb.asm.tree.AbstractInsnNode; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.objectweb.asm.tree.MethodInsnNode; | ||
import org.objectweb.asm.tree.MethodNode; | ||
import org.objectweb.asm.tree.TypeInsnNode; | ||
|
||
@SuppressWarnings("unused") | ||
public class NBTTagCompoundHashMapTransformer implements IClassTransformer { | ||
|
||
private static final Logger LOGGER = LogManager.getLogger("NBTTagCompoundHashMapTransformerTransformer"); | ||
public static final String INIT = "<init>"; | ||
public static final String EMPTY_DESC = "()V"; | ||
public static final String HASHMAP = "java/util/HashMap"; | ||
public static final String FASTUTIL_HASHMAP = "it/unimi/dsi/fastutil/objects/Object2ObjectOpenHashMap"; | ||
public static final String NBT_TAG_COMPOUND = "net.minecraft.nbt.NBTTagCompound"; | ||
|
||
@Override | ||
public byte[] transform(String name, String transformedName, byte[] basicClass) { | ||
if (basicClass == null) return null; | ||
if (!transformedName.equals(NBT_TAG_COMPOUND)) { | ||
return basicClass; | ||
} | ||
|
||
final ClassReader cr = new ClassReader(basicClass); | ||
final ClassNode cn = new ClassNode(); | ||
cr.accept(cn, 0); | ||
final boolean changed = transformClassNode(transformedName, cn); | ||
if (changed) { | ||
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS); | ||
cn.accept(cw); | ||
return cw.toByteArray(); | ||
} | ||
return basicClass; | ||
} | ||
|
||
/** @return Was the class changed? */ | ||
public boolean transformClassNode(String transformedName, ClassNode cn) { | ||
if (cn == null) { | ||
return false; | ||
} | ||
|
||
boolean changed = false; | ||
for (MethodNode mn : cn.methods) { | ||
if (mn.name.equals(INIT) && mn.desc.equals(EMPTY_DESC)) { | ||
for (AbstractInsnNode node : mn.instructions.toArray()) { | ||
if (node.getOpcode() == Opcodes.NEW && node instanceof TypeInsnNode tNode) { | ||
if (tNode.desc.equals(HASHMAP)) { | ||
LOGGER.info("Found HashMap instantiation in NBTTagCompound.<init>"); | ||
mn.instructions.insertBefore(tNode, new TypeInsnNode(Opcodes.NEW, FASTUTIL_HASHMAP)); | ||
mn.instructions.remove(tNode); | ||
changed = true; | ||
} | ||
} else if (node.getOpcode() == Opcodes.INVOKESPECIAL && node instanceof MethodInsnNode mNode) { | ||
if (mNode.name.equals(INIT) && mNode.desc.equals(EMPTY_DESC) && mNode.owner.equals(HASHMAP)) { | ||
LOGGER.info("Found HashMap constructor call in NBTTagCompound.<init>"); | ||
mn.instructions.insertBefore( | ||
mNode, | ||
new MethodInsnNode( | ||
Opcodes.INVOKESPECIAL, | ||
FASTUTIL_HASHMAP, | ||
INIT, | ||
EMPTY_DESC, | ||
false)); | ||
mn.instructions.remove(mNode); | ||
changed = true; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return changed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/mitchej123/hodgepodge/core/CoreCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mitchej123.hodgepodge.core; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import com.mitchej123.hodgepodge.config.TweaksConfig; | ||
|
||
public class CoreCompat { | ||
|
||
private static final Logger LOOGGER = LogManager.getLogger("HodgepodgeCoreCompat"); | ||
|
||
public static void disableCoretweaksConflictingMixins() { | ||
if (TweaksConfig.threadedWorldDataSaving) { | ||
LOOGGER.info("Disabled CoreTweaks conflicting mixin: enhanceMapStorageErrors"); | ||
makamys.coretweaks.Config.enhanceMapStorageErrors.disable(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
.../java/com/mitchej123/hodgepodge/mixins/early/forge/MixinForgeChunkManager_threadedIO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.mitchej123.hodgepodge.mixins.early.forge; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import net.minecraft.nbt.NBTTagCompound; | ||
import net.minecraftforge.common.ForgeChunkManager; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import com.mitchej123.hodgepodge.core.HodgepodgeCore; | ||
|
||
@Mixin(ForgeChunkManager.class) | ||
public class MixinForgeChunkManager_threadedIO { | ||
|
||
@Redirect( | ||
method = "saveWorld", | ||
at = @At( | ||
value = "INVOKE", | ||
target = "Lnet/minecraft/nbt/CompressedStreamTools;write(Lnet/minecraft/nbt/NBTTagCompound;Ljava/io/File;)V")) | ||
private static void redirectWrite(NBTTagCompound forcedChunkNBTData, File chunkLoaderFile) throws IOException { | ||
HodgepodgeCore.saveWorldDataUncompressed(chunkLoaderFile, forcedChunkNBTData); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...om/mitchej123/hodgepodge/mixins/early/minecraft/MixinAnvilChunkLoader_FixAllocations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mitchej123.hodgepodge.mixins.early.minecraft; | ||
|
||
import java.util.Set; | ||
|
||
import net.minecraft.world.ChunkCoordIntPair; | ||
import net.minecraft.world.chunk.storage.AnvilChunkLoader; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
import com.mitchej123.hodgepodge.hax.LongChunkCoordIntPairSet; | ||
import com.mitchej123.hodgepodge.mixins.interfaces.MutableChunkCoordIntPair; | ||
|
||
@Mixin(AnvilChunkLoader.class) | ||
public class MixinAnvilChunkLoader_FixAllocations { | ||
|
||
@Shadow | ||
private Set<ChunkCoordIntPair> pendingAnvilChunksCoordinates = new LongChunkCoordIntPairSet(); | ||
|
||
private final MutableChunkCoordIntPair reusableCCIP = (MutableChunkCoordIntPair) new ChunkCoordIntPair(0, 0); | ||
|
||
@Redirect(method = "chunkExists", at = @At(value = "NEW", target = "Lnet/minecraft/world/ChunkCoordIntPair;")) | ||
private ChunkCoordIntPair chunkExistsReusable(int i, int j) { | ||
return (ChunkCoordIntPair) reusableCCIP.setChunkPos(i, j); | ||
} | ||
} |
Oops, something went wrong.