Added Galacticraft gravity support
This commit is contained in:
parent
7af76758c8
commit
bf1463806e
2 changed files with 112 additions and 3 deletions
|
@ -2,7 +2,6 @@ package cr0s.warpdrive;
|
|||
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.MathHelper;
|
||||
|
@ -20,7 +19,7 @@ public class GravityManager {
|
|||
private static double SPACE_VOID_GRAVITY_JETPACKSNEAK = 0.02D; // Lem 0.01D
|
||||
private static double SPACE_VOID_GRAVITY_RAWSNEAK = 0.005D; // Lem 0.01D 0.001 = no mvt
|
||||
|
||||
public static double getGravityForEntity(EntityLivingBase entity) {
|
||||
public static double getGravityForEntity(Entity entity) {
|
||||
// Is entity in space or hyper-space?
|
||||
boolean inSpace = entity.worldObj.provider.dimensionId == WarpDriveConfig.G_SPACE_DIMENSION_ID;
|
||||
boolean inHyperspace = entity.worldObj.provider.dimensionId == WarpDriveConfig.G_HYPERSPACE_DIMENSION_ID;
|
||||
|
|
|
@ -62,6 +62,9 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
|
|||
} else if (transformedName.equals("com.creativemd.itemphysic.physics.ServerPhysic")) {
|
||||
bytes = transformItemPhysicEntityItem(bytes);
|
||||
|
||||
} else if (transformedName.equals("micdoodle8.mods.galacticraft.core.util.WorldUtil")) {
|
||||
bytes = transformGalacticraftWorldUtil(bytes);
|
||||
|
||||
} else if (transformedName.equals("net.minecraft.client.multiplayer.WorldClient")) {
|
||||
bytes = transformMinecraftWorldClient(bytes);
|
||||
|
||||
|
@ -106,7 +109,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
|
|||
Opcodes.INVOKESTATIC,
|
||||
GRAVITY_MANAGER_CLASS,
|
||||
"getGravityForEntity",
|
||||
"(L" + "net/minecraft/entity/EntityLivingBase" + ";)D",
|
||||
"(Lnet/minecraft/entity/Entity;)D",
|
||||
false);
|
||||
methodnode.instructions.insertBefore(nodeAt, beforeNode);
|
||||
methodnode.instructions.set(nodeAt, overwriteNode);
|
||||
|
@ -277,6 +280,113 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
|
|||
return bytes;
|
||||
}
|
||||
|
||||
private byte[] transformGalacticraftWorldUtil(byte[] bytes) {
|
||||
ClassNode classNode = new ClassNode();
|
||||
ClassReader classReader = new ClassReader(bytes);
|
||||
classReader.accept(classNode, 0);
|
||||
int operationCount = 3 + 2 + 0;
|
||||
int injectedCount = 0;
|
||||
Iterator methods = classNode.methods.iterator();
|
||||
|
||||
do {
|
||||
if (!methods.hasNext()) {
|
||||
break;
|
||||
}
|
||||
|
||||
MethodNode methodnode = (MethodNode) methods.next();
|
||||
// if (debugLog) { FMLLoadingPlugin.logger.info("- Method " + methodnode.name + " " + methodnode.desc); }
|
||||
|
||||
// Entities gravity
|
||||
if ( (methodnode.name.equals("getGravityForEntity"))
|
||||
&& methodnode.desc.equals("(Lnet/minecraft/entity/Entity;)D") ) {
|
||||
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); }
|
||||
|
||||
int instructionIndex = 0;
|
||||
|
||||
while (instructionIndex < methodnode.instructions.size()) {
|
||||
AbstractInsnNode abstractNode = methodnode.instructions.get(instructionIndex);
|
||||
|
||||
if (abstractNode instanceof LdcInsnNode) {
|
||||
LdcInsnNode nodeAt = (LdcInsnNode) abstractNode;
|
||||
|
||||
if (nodeAt.cst.equals(Double.valueOf(0.08D))) {
|
||||
VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0);
|
||||
MethodInsnNode overwriteNode = new MethodInsnNode(
|
||||
Opcodes.INVOKESTATIC,
|
||||
GRAVITY_MANAGER_CLASS,
|
||||
"getGravityForEntity",
|
||||
"(Lnet/minecraft/entity/Entity;)D",
|
||||
false);
|
||||
methodnode.instructions.insertBefore(nodeAt, beforeNode);
|
||||
methodnode.instructions.set(nodeAt, overwriteNode);
|
||||
if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); }
|
||||
injectedCount++;
|
||||
}
|
||||
}
|
||||
|
||||
instructionIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
// Items gravity
|
||||
if ( (methodnode.name.equals("getItemGravity"))
|
||||
&& methodnode.desc.equals("(Lnet/minecraft/entity/item/EntityItem;)D") ) {
|
||||
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); }
|
||||
|
||||
int instructionIndex = 0;
|
||||
|
||||
while (instructionIndex < methodnode.instructions.size()) {
|
||||
AbstractInsnNode abstractNode = methodnode.instructions.get(instructionIndex);
|
||||
|
||||
if (abstractNode instanceof LdcInsnNode) {
|
||||
LdcInsnNode nodeAt = (LdcInsnNode) abstractNode;
|
||||
|
||||
if (nodeAt.cst.equals(Double.valueOf(0.03999999910593033D))) {
|
||||
VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0);
|
||||
MethodInsnNode overwriteNode = new MethodInsnNode(
|
||||
Opcodes.INVOKESTATIC,
|
||||
GRAVITY_MANAGER_CLASS,
|
||||
"getItemGravity",
|
||||
"(L" + "net/minecraft/entity/item/EntityItem" + ";)D",
|
||||
false);
|
||||
methodnode.instructions.insertBefore(nodeAt, beforeNode);
|
||||
methodnode.instructions.set(nodeAt, overwriteNode);
|
||||
if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); }
|
||||
injectedCount++;
|
||||
}
|
||||
/*
|
||||
if (nodeAt.cst.equals(Double.valueOf(0.98D))) {
|
||||
VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0);
|
||||
MethodInsnNode overwriteNode = new MethodInsnNode(
|
||||
Opcodes.INVOKESTATIC,
|
||||
GRAVITY_MANAGER_CLASS,
|
||||
"getItemGravity2",
|
||||
"(L" + "net/minecraft/entity/item/EntityItem" + ";)D",
|
||||
false);
|
||||
methodnode.instructions.insertBefore(nodeAt, beforeNode);
|
||||
methodnode.instructions.set(nodeAt, overwriteNode);
|
||||
if (debugLog) { FMLLoadingPlugin.logger.info("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); }
|
||||
injectedCount++;
|
||||
}
|
||||
/**/
|
||||
}
|
||||
|
||||
instructionIndex++;
|
||||
}
|
||||
}
|
||||
} while (true);
|
||||
|
||||
if (injectedCount != operationCount) {
|
||||
FMLLoadingPlugin.logger.info("Injection failed for " + classNode.name + " (" + injectedCount + " / " + operationCount + "), aborting...");
|
||||
} else {
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES);
|
||||
classNode.accept(writer);
|
||||
bytes = writer.toByteArray();
|
||||
FMLLoadingPlugin.logger.info("Successful injection in " + classNode.name);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private byte[] transformMinecraftWorldClient(byte[] bytes) {
|
||||
ClassNode classNode = new ClassNode();
|
||||
ClassReader classReader = new ClassReader(bytes);
|
||||
|
|
Loading…
Reference in a new issue