3
0

Patch ChunkProviderServer.loadedChunkHashMap in runtime, fix #1

This commit is contained in:
Prototik 2015-05-14 12:38:03 +07:00
parent d4a181d431
commit 8c4713c6d7
5 changed files with 104 additions and 19 deletions

View File

@ -41,17 +41,14 @@ minecraft {
srgExtra "PK: org/bukkit/craftbukkit org/bukkit/craftbukkit/v1_7_R4" srgExtra "PK: org/bukkit/craftbukkit org/bukkit/craftbukkit/v1_7_R4"
} }
group = 'net.minecraftforge' group = 'pw.prok.kcauldron'
ext.mcVersion = "1.7.10" archivesBaseName = 'kcauldron'
ext.cauldronVersion = "2"
ext.forgeVersion = "1403"
ext.bukkitVersion = "1"
ext.revision = "54"
version = "${mcVersion}-${cauldronVersion}.${forgeVersion}.${bukkitVersion}.${revision}"
jenkins { ext.mcVersion = "1.7.10"
job = 'Cauldron' ext.cauldronVersion = "3"
} ext.forgeVersion = "1403"
ext.revision = "57"
version = "${mcVersion}-${cauldronVersion}.${forgeVersion}.${revision}"
launch4j { launch4j {
jreMinVersion = '1.6.0' jreMinVersion = '1.6.0'
@ -63,8 +60,8 @@ tasks.packageUniversal {
tasks.packageUniversal.manifest { tasks.packageUniversal.manifest {
attributes([ attributes([
'Implementation-Vendor': 'Cauldron', 'Implementation-Vendor': 'Prototik',
'Implementation-Title': 'Cauldron', 'Implementation-Title': 'KCauldron',
'Implementation-Version': 'KCauldron-'+project.version, 'Implementation-Version': 'KCauldron-'+project.version,
'Forge-Version': '10.13.3.1403', 'Forge-Version': '10.13.3.1403',
'Specification-Vendor': 'Bukkit Team', 'Specification-Vendor': 'Bukkit Team',

View File

@ -1,6 +1,41 @@
--- ../src-base/minecraft/cpw/mods/fml/relauncher/CoreModManager.java --- ../src-base/minecraft/cpw/mods/fml/relauncher/CoreModManager.java
+++ ../src-work/minecraft/cpw/mods/fml/relauncher/CoreModManager.java +++ ../src-work/minecraft/cpw/mods/fml/relauncher/CoreModManager.java
@@ -153,6 +153,9 @@ @@ -27,10 +27,14 @@
import java.util.Map;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
+
+import kcauldron.KCauldonClassTransformer;
import net.minecraft.launchwrapper.ITweaker;
import net.minecraft.launchwrapper.Launch;
import net.minecraft.launchwrapper.LaunchClassLoader;
+
import org.apache.logging.log4j.Level;
+
import com.google.common.base.Strings;
import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList;
@@ -38,6 +42,7 @@
import com.google.common.collect.Maps;
import com.google.common.collect.ObjectArrays;
import com.google.common.primitives.Ints;
+
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.asm.transformers.ModAccessTransformer;
import cpw.mods.fml.common.launcher.FMLInjectionAndSortingTweaker;
@@ -94,6 +99,11 @@
@Override
public void injectIntoClassLoader(LaunchClassLoader classLoader)
{
+ // Cauldron start
+ // Register own ClassTransformer for some needs
+ classLoader.registerTransformer("kcauldron.KCauldonClassTransformer");
+ KCauldonClassTransformer.DEV = deobfuscatedEnvironment;
+ // Cauldron end
FMLRelaunchLog.fine("Injecting coremod %s {%s} class transformers", name, coreModInstance.getClass().getName());
if (coreModInstance.getASMTransformerClass() != null) for (String transformer : coreModInstance.getASMTransformerClass())
{
@@ -153,6 +163,9 @@
} }
@ -10,7 +45,7 @@
public static void handleLaunch(File mcDir, LaunchClassLoader classLoader, FMLTweaker tweaker) public static void handleLaunch(File mcDir, LaunchClassLoader classLoader, FMLTweaker tweaker)
{ {
CoreModManager.mcDir = mcDir; CoreModManager.mcDir = mcDir;
@@ -212,6 +215,19 @@ @@ -212,6 +225,19 @@
loadCoreMod(classLoader, coreModClassName, null); loadCoreMod(classLoader, coreModClassName, null);
} }
discoverCoreMods(mcDir, classLoader); discoverCoreMods(mcDir, classLoader);
@ -30,7 +65,7 @@
} }
@@ -424,8 +440,11 @@ @@ -424,8 +450,11 @@
MCVersion requiredMCVersion = coreModClazz.getAnnotation(IFMLLoadingPlugin.MCVersion.class); MCVersion requiredMCVersion = coreModClazz.getAnnotation(IFMLLoadingPlugin.MCVersion.class);
if (!Arrays.asList(rootPlugins).contains(coreModClass) && (requiredMCVersion == null || Strings.isNullOrEmpty(requiredMCVersion.value()))) if (!Arrays.asList(rootPlugins).contains(coreModClass) && (requiredMCVersion == null || Strings.isNullOrEmpty(requiredMCVersion.value())))
{ {

View File

@ -38,7 +38,7 @@
+ public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility + public List loadedChunks = new ArrayList(); // Cauldron - vanilla compatibility
public WorldServer worldObj; public WorldServer worldObj;
private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet(); private Set<Long> loadingChunks = com.google.common.collect.Sets.newHashSet();
+ public LongHashMap field_73244_f = new LongHashMap(); // Cauldron - vanilla/mystcraft compatibility + public LongHashMap loadedChunkHashMap_vanilla = new LongHashMap(); // Cauldron - vanilla/mystcraft compatibility
private static final String __OBFID = "CL_00001436"; private static final String __OBFID = "CL_00001436";
public ChunkProviderServer(WorldServer p_i1520_1_, IChunkLoader p_i1520_2_, IChunkProvider p_i1520_3_) public ChunkProviderServer(WorldServer p_i1520_1_, IChunkLoader p_i1520_2_, IChunkProvider p_i1520_3_)
@ -170,7 +170,7 @@
- chunk.onChunkLoad(); - chunk.onChunkLoad();
+ this.loadedChunkHashMap.put(LongHash.toLong(p_73158_1_, p_73158_2_), chunk); // CraftBukkit + this.loadedChunkHashMap.put(LongHash.toLong(p_73158_1_, p_73158_2_), chunk); // CraftBukkit
+ this.loadedChunks.add(chunk); // Cauldron - vanilla compatibility + this.loadedChunks.add(chunk); // Cauldron - vanilla compatibility
+ this.field_73244_f.add(ChunkCoordIntPair.chunkXZ2Int(p_73158_1_, p_73158_2_), chunk); // Cauldron - vanilla/mystcraft compatibility + this.loadedChunkHashMap_vanilla.add(ChunkCoordIntPair.chunkXZ2Int(p_73158_1_, p_73158_2_), chunk); // Cauldron - vanilla/mystcraft compatibility
+ loadingChunks.remove(LongHash.toLong(p_73158_1_, p_73158_2_)); // Cauldron - LongHash + loadingChunks.remove(LongHash.toLong(p_73158_1_, p_73158_2_)); // Cauldron - LongHash
+ +
+ if (chunk != null) + if (chunk != null)
@ -408,7 +408,7 @@
+ // this.unloadQueue.remove(olong); + // this.unloadQueue.remove(olong);
+ this.loadedChunkHashMap.remove(chunkcoordinates); // CraftBukkit + this.loadedChunkHashMap.remove(chunkcoordinates); // CraftBukkit
+ this.loadedChunks.remove(chunk); // Cauldron - vanilla compatibility + this.loadedChunks.remove(chunk); // Cauldron - vanilla compatibility
+ this.field_73244_f.remove(ChunkCoordIntPair.chunkXZ2Int(LongHash.msw(chunkcoordinates), LongHash.lsw(chunkcoordinates))); // Cauldron - vanilla/mystcraft compatibility + this.loadedChunkHashMap_vanilla.remove(ChunkCoordIntPair.chunkXZ2Int(LongHash.msw(chunkcoordinates), LongHash.lsw(chunkcoordinates))); // Cauldron - vanilla/mystcraft compatibility
+ ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk); + ForgeChunkManager.putDormantChunk(chunkcoordinates, chunk);
+ if(this.loadedChunkHashMap.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){ + if(this.loadedChunkHashMap.size() == 0 && ForgeChunkManager.getPersistentChunksFor(this.worldObj).size() == 0 && !DimensionManager.shouldLoadSpawn(this.worldObj.provider.dimensionId)){
+ DimensionManager.unloadWorld(this.worldObj.provider.dimensionId); + DimensionManager.unloadWorld(this.worldObj.provider.dimensionId);

View File

@ -17,7 +17,7 @@
- queuedChunk.provider.loadedChunkHashMap.add(ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk); - queuedChunk.provider.loadedChunkHashMap.add(ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk);
+ queuedChunk.provider.loadedChunkHashMap.put(LongHash.toLong(queuedChunk.x, queuedChunk.z), chunk); + queuedChunk.provider.loadedChunkHashMap.put(LongHash.toLong(queuedChunk.x, queuedChunk.z), chunk);
queuedChunk.provider.loadedChunks.add(chunk); queuedChunk.provider.loadedChunks.add(chunk);
+ queuedChunk.provider.field_73244_f.add(ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk); // Cauldron - vanilla/mystcraft compatibility + queuedChunk.provider.loadedChunkHashMap_vanilla.add(ChunkCoordIntPair.chunkXZ2Int(queuedChunk.x, queuedChunk.z), chunk); // Cauldron - vanilla/mystcraft compatibility
chunk.onChunkLoad(); chunk.onChunkLoad();
if (queuedChunk.provider.currentChunkProvider != null) { if (queuedChunk.provider.currentChunkProvider != null) {

View File

@ -0,0 +1,53 @@
package kcauldron;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import net.minecraft.launchwrapper.IClassTransformer;
import static org.objectweb.asm.Opcodes.*;
public class KCauldonClassTransformer implements IClassTransformer {
public static boolean DEV;
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
if ("net.minecraft.world.gen.ChunkProviderServer".equals(transformedName) || "net.minecraftforge.common.chunkio.ChunkIOProvider".equals(transformedName)) {
return patchChunkCall(basicClass);
}
return basicClass;
}
private byte[] patchChunkCall(byte[] bytes) {
ClassReader reader = new ClassReader(bytes);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
reader.accept(new ClassVisitor(ASM5, writer) {
@Override
public FieldVisitor visitField(int access, String name,
String desc, String signature, Object value) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = DEV ? "loadedChunkHashMap" : "field_73244_f";
}
return super.visitField(access, name, desc, signature, value);
}
@Override
public MethodVisitor visitMethod(int access, String name,
String desc, String signature, String[] exceptions) {
return new MethodVisitor(api, super.visitMethod(access, name, desc, signature, exceptions)) {
@Override
public void visitFieldInsn(int opcode, String owner,
String name, String desc) {
if ("loadedChunkHashMap_vanilla".equals(name)) {
name = DEV ? "loadedChunkHashMap" : "field_73244_f";
}
super.visitFieldInsn(opcode, owner, name, desc);
}
};
}
}, 0);
return writer.toByteArray();
}
}