Updated WarpDriveCore to 1.12.2

This commit is contained in:
Unknown 2018-06-30 22:43:07 +02:00 committed by unknown
parent 3d033c6f98
commit 59efb4cb79
5 changed files with 80 additions and 54 deletions

View file

@ -35,27 +35,27 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
public static ConcurrentSkipListMap<String, Integer> countClass = new ConcurrentSkipListMap<>(); public static ConcurrentSkipListMap<String, Integer> countClass = new ConcurrentSkipListMap<>();
public static ConcurrentHashMap<String, Long> sizeClass = new ConcurrentHashMap<>(8192); public static ConcurrentHashMap<String, Long> sizeClass = new ConcurrentHashMap<>(8192);
private static final String GRAVITY_MANAGER_CLASS = "cr0s/warpdrive/GravityManager"; private static final String GRAVITY_MANAGER_CLASS = "cr0s/warpdrive/data/GravityManager";
private static final String CLOAK_MANAGER_CLASS = "cr0s/warpdrive/data/CloakManager"; private static final String CLOAK_MANAGER_CLASS = "cr0s/warpdrive/data/CloakManager";
private boolean debugLog = false; private boolean debugLog = false;
public ClassTransformer() { public ClassTransformer() {
nodeMap.put("EntityLivingBase.class", "sv"); nodeMap.put("EntityLivingBase.class", "vn");
nodeMap.put("moveEntityWithHeading.name", "func_70612_e"); nodeMap.put("travel.name", "func_191986_a");
nodeMap.put("moveEntityWithHeading.desc", "(FF)V"); nodeMap.put("travel.desc", "(FFF)V");
nodeMap.put("EntityItem.class", "xk"); nodeMap.put("EntityItem.class", "acj");
nodeMap.put("onUpdate.name", "func_70071_h_"); nodeMap.put("onUpdate.name", "func_70071_h_");
nodeMap.put("onUpdate.desc", "()V"); nodeMap.put("onUpdate.desc", "()V");
nodeMap.put("WorldClient.class", "bjf"); nodeMap.put("WorldClient.class", "brz");
nodeMap.put("func_147492_c.name", "func_147492_c"); nodeMap.put("invalidateRegionAndSetBlock.name", "func_180503_b");
nodeMap.put("func_147492_c.desc", "(IIILnet/minecraft/block/Block;I)Z"); nodeMap.put("invalidateRegionAndSetBlock.desc", "(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)Z");
nodeMap.put("setBlock.name", "func_147465_d"); nodeMap.put("setBlockState.name", "func_180501_a");
nodeMap.put("Chunk.class", "apx"); nodeMap.put("Chunk.class", "axu");
nodeMap.put("fillChunk.name", "func_76607_a"); nodeMap.put("read.name", "func_186033_a");
nodeMap.put("fillChunk.desc", "([BIIZ)V"); nodeMap.put("read.desc", "(Lnet/minecraft/network/PacketBuffer;IZ)V");
nodeMap.put("generateHeightMap.name", "func_76590_a"); nodeMap.put("generateHeightMap.name", "func_76590_a");
nodeMap.put("generateHeightMap.desc", "()V"); nodeMap.put("generateHeightMap.desc", "()V");
} }
@ -155,7 +155,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
final ClassReader classReader = new ClassReader(bytes); final ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0); classReader.accept(classNode, 0);
final int operationCount = 1; final int operationCount = 2;
int injectedCount = 0; int injectedCount = 0;
final Iterator methods = classNode.methods.iterator(); final Iterator methods = classNode.methods.iterator();
do { do {
@ -166,9 +166,9 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
final MethodNode methodNode = (MethodNode) methods.next(); final MethodNode methodNode = (MethodNode) methods.next();
// if (debugLog) { FMLLoadingPlugin.logger.info(String.format("- Method %s %s", methodNode.name, methodNode.desc)); } // if (debugLog) { FMLLoadingPlugin.logger.info(String.format("- Method %s %s", methodNode.name, methodNode.desc)); }
if ( (methodNode.name.equals(nodeMap.get("moveEntityWithHeading.name")) || methodNode.name.equals("moveEntityWithHeading")) if ( (methodNode.name.equals(nodeMap.get("travel.name")) || methodNode.name.equals("travel"))
&& methodNode.desc.equals(nodeMap.get("moveEntityWithHeading.desc")) ) { && methodNode.desc.equals(nodeMap.get("travel.desc")) ) {
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Found method to inject into: %s %s", methodNode.name, methodNode.desc)); }
int instructionIndex = 0; int instructionIndex = 0;
@ -178,7 +178,20 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
if (abstractNode instanceof LdcInsnNode) { if (abstractNode instanceof LdcInsnNode) {
final LdcInsnNode nodeAt = (LdcInsnNode) abstractNode; final LdcInsnNode nodeAt = (LdcInsnNode) abstractNode;
if (nodeAt.cst.equals(0.080000000000000002D)) { if (nodeAt.cst.equals(-0.080000000000000002D)) {
final VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0);
final MethodInsnNode overwriteNode = new MethodInsnNode(
Opcodes.INVOKESTATIC,
GRAVITY_MANAGER_CLASS,
"getNegGravityForEntity",
"(Lnet/minecraft/entity/Entity;)D",
false);
methodNode.instructions.insertBefore(nodeAt, beforeNode);
methodNode.instructions.set(nodeAt, overwriteNode);
if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Injecting into %s.%s %s", classNode.name, methodNode.name, methodNode.desc)); }
injectedCount++;
} else if (nodeAt.cst.equals(0.080000000000000002D)) {
final VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); final VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0);
final MethodInsnNode overwriteNode = new MethodInsnNode( final MethodInsnNode overwriteNode = new MethodInsnNode(
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
@ -227,7 +240,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
if ( (methodNode.name.equals(nodeMap.get("onUpdate.name")) || methodNode.name.equals("onUpdate")) if ( (methodNode.name.equals(nodeMap.get("onUpdate.name")) || methodNode.name.equals("onUpdate"))
&& methodNode.desc.equals(nodeMap.get("onUpdate.desc")) ) { && methodNode.desc.equals(nodeMap.get("onUpdate.desc")) ) {
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Found method to inject into: %s %s", methodNode.name, methodNode.desc)); }
int instructionIndex = 0; int instructionIndex = 0;
@ -300,7 +313,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
if ( (methodNode.name.equals("update")) if ( (methodNode.name.equals("update"))
&& methodNode.desc.equals("(Lnet/minecraft/entity/item/EntityItem;)V") ) { && methodNode.desc.equals("(Lnet/minecraft/entity/item/EntityItem;)V") ) {
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Found method to inject into: %s %s", methodNode.name, methodNode.desc)); }
int instructionIndex = 0; int instructionIndex = 0;
@ -374,7 +387,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
// Entities gravity // Entities gravity
if ( (methodNode.name.equals("getGravityForEntity")) if ( (methodNode.name.equals("getGravityForEntity"))
&& methodNode.desc.equals("(Lnet/minecraft/entity/Entity;)D") ) { && methodNode.desc.equals("(Lnet/minecraft/entity/Entity;)D") ) {
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Found method to inject into: %s %s", methodNode.name, methodNode.desc)); }
int instructionIndex = 0; int instructionIndex = 0;
@ -406,7 +419,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
// Items gravity // Items gravity
if ( (methodNode.name.equals("getItemGravity")) if ( (methodNode.name.equals("getItemGravity"))
&& methodNode.desc.equals("(Lnet/minecraft/entity/item/EntityItem;)D") ) { && methodNode.desc.equals("(Lnet/minecraft/entity/item/EntityItem;)D") ) {
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Found method to inject into: %s %s", methodNode.name, methodNode.desc)); }
int instructionIndex = 0; int instructionIndex = 0;
@ -478,9 +491,9 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
final MethodNode methodNode = (MethodNode) methods.next(); final MethodNode methodNode = (MethodNode) methods.next();
// if (debugLog) { FMLLoadingPlugin.logger.info(String.format("- Method %s %s", methodNode.name, methodNode.desc)); } // if (debugLog) { FMLLoadingPlugin.logger.info(String.format("- Method %s %s", methodNode.name, methodNode.desc)); }
if ( (methodNode.name.equals(nodeMap.get("func_147492_c.name")) || methodNode.name.equals("func_147492_c")) if ( (methodNode.name.equals(nodeMap.get("invalidateRegionAndSetBlock.name")) || methodNode.name.equals("invalidateRegionAndSetBlock"))
&& methodNode.desc.equals(nodeMap.get("func_147492_c.desc")) ) { && methodNode.desc.equals(nodeMap.get("invalidateRegionAndSetBlock.desc")) ) {
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Found method to inject into: %s %s", methodNode.name, methodNode.desc)); }
int instructionIndex = 0; int instructionIndex = 0;
@ -490,12 +503,12 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
if (abstractNode instanceof MethodInsnNode) { if (abstractNode instanceof MethodInsnNode) {
final MethodInsnNode nodeAt = (MethodInsnNode) abstractNode; final MethodInsnNode nodeAt = (MethodInsnNode) abstractNode;
if (nodeAt.name.equals(nodeMap.get("setBlock.name")) || nodeAt.name.equals("setBlock")) { if (nodeAt.name.equals(nodeMap.get("setBlockState.name")) || nodeAt.name.equals("setBlockState")) {
final MethodInsnNode overwriteNode = new MethodInsnNode( final MethodInsnNode overwriteNode = new MethodInsnNode(
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
CLOAK_MANAGER_CLASS, CLOAK_MANAGER_CLASS,
"onBlockChange", "WorldClient_invalidateRegionAndSetBlock_setBlockState",
"(IIILnet/minecraft/block/Block;II)Z", "(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;I)Z",
false); false);
methodNode.instructions.set(nodeAt, overwriteNode); methodNode.instructions.set(nodeAt, overwriteNode);
if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Injecting into %s.%s %s", classNode.name, methodNode.name, methodNode.desc)); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Injecting into %s.%s %s", classNode.name, methodNode.name, methodNode.desc)); }
@ -535,9 +548,9 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
final MethodNode methodNode = (MethodNode) methods.next(); final MethodNode methodNode = (MethodNode) methods.next();
if (debugLog) { FMLLoadingPlugin.logger.info(String.format("- Method %s %s", methodNode.name, methodNode.desc)); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("- Method %s %s", methodNode.name, methodNode.desc)); }
if ( (methodNode.name.equals(nodeMap.get("fillChunk.name")) || methodNode.name.equals("fillChunk")) if ( (methodNode.name.equals(nodeMap.get("read.name")) || methodNode.name.equals("read"))
&& methodNode.desc.equals(nodeMap.get("fillChunk.desc")) ) { && methodNode.desc.equals(nodeMap.get("read.desc")) ) {
if (debugLog) { FMLLoadingPlugin.logger.info("Method found!"); } if (debugLog) { FMLLoadingPlugin.logger.info(String.format("Found method to inject into: %s %s", methodNode.name, methodNode.desc)); }
int instructionIndex = 0; int instructionIndex = 0;
@ -553,7 +566,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans
final MethodInsnNode insertMethodNode = new MethodInsnNode( final MethodInsnNode insertMethodNode = new MethodInsnNode(
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
CLOAK_MANAGER_CLASS, CLOAK_MANAGER_CLASS,
"onFillChunk", "Chunk_read",
"(Lnet/minecraft/world/chunk/Chunk;)V", "(Lnet/minecraft/world/chunk/Chunk;)V",
false); false);
methodNode.instructions.insertBefore(nodeAt, insertMethodNode); methodNode.instructions.insertBefore(nodeAt, insertMethodNode);

View file

@ -11,7 +11,7 @@ import net.minecraftforge.fml.relauncher.IFMLCallHook;
import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin;
@IFMLLoadingPlugin.Name(value = "WarpDriveCore") // The readable mod name @IFMLLoadingPlugin.Name(value = "WarpDriveCore") // The readable mod name
@IFMLLoadingPlugin.MCVersion(value = "1.10.2") @IFMLLoadingPlugin.MCVersion(value = "1.12.2")
@IFMLLoadingPlugin.TransformerExclusions(value = "cr0s.warpdrive.core.") @IFMLLoadingPlugin.TransformerExclusions(value = "cr0s.warpdrive.core.")
@IFMLLoadingPlugin.SortingIndex(value = 1001) // > 1000 to work with srg names @IFMLLoadingPlugin.SortingIndex(value = 1001) // > 1000 to work with srg names
public class FMLLoadingPlugin implements IFMLLoadingPlugin, IFMLCallHook { public class FMLLoadingPlugin implements IFMLLoadingPlugin, IFMLCallHook {

View file

@ -6,7 +6,7 @@ import cr0s.warpdrive.network.PacketHandler;
import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.CopyOnWriteArraySet;
import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
@ -136,26 +136,30 @@ public class CloakManager {
@SuppressWarnings("unused") // Core mod @SuppressWarnings("unused") // Core mod
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public static boolean onBlockChange(final int x, final int y, final int z, final Block block, final int metadata, final int flag) { public static boolean WorldClient_invalidateRegionAndSetBlock_setBlockState(final BlockPos blockPos, final IBlockState blockState, final int flags) {
if (block != Blocks.AIR) { if (blockState.getBlock() != Blocks.AIR) {
for (final CloakedArea area : cloaks) { for (final CloakedArea area : cloaks) {
if (area.isBlockWithinArea(x, y, z)) { if (area.isBlockWithinArea(blockPos)) {
// WarpDrive.logger.info("CM block is inside"); if (WarpDrive.isDev && WarpDriveConfig.LOGGING_CLOAKING) {
WarpDrive.logger.info("CloakManager block is inside");
}
if (!area.isEntityWithinArea(Minecraft.getMinecraft().player)) { if (!area.isEntityWithinArea(Minecraft.getMinecraft().player)) {
// WarpDrive.logger.info("CM player is outside"); if (WarpDrive.isDev && WarpDriveConfig.LOGGING_CLOAKING) {
return Minecraft.getMinecraft().world.setBlockState(new BlockPos(x, y, z), area.blockStateFog, flag); WarpDrive.logger.info("CloakManager player is outside");
}
return Minecraft.getMinecraft().world.setBlockState(blockPos, area.blockStateFog, flags);
} }
} }
} }
} }
return Minecraft.getMinecraft().world.setBlockState(new BlockPos(x, y, z), block.getStateFromMeta(metadata), flag); return Minecraft.getMinecraft().world.setBlockState(blockPos, blockState, flags);
} }
@SuppressWarnings("unused") // Core mod @SuppressWarnings("unused") // Core mod
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public static void onFillChunk(final Chunk chunk) { public static void Chunk_read(final Chunk chunk) {
if (cloaks == null) { if (cloaks == null) {
WarpDrive.logger.info(String.format("CM onFillChunk (%d %d) no cloaks", WarpDrive.logger.info(String.format("CloakManager Chunk_read (%d %d) no cloaks",
chunk.x, chunk.z)); chunk.x, chunk.z));
return; return;
} }
@ -164,16 +168,22 @@ public class CloakManager {
final int chunkX_max = chunk.x * 16 + 15; final int chunkX_max = chunk.x * 16 + 15;
final int chunkZ_min = chunk.z * 16; final int chunkZ_min = chunk.z * 16;
final int chunkZ_max = chunk.z * 16 + 15; final int chunkZ_max = chunk.z * 16 + 15;
WarpDrive.logger.info(String.format("CM onFillChunk (%d %d) %d cloak(s) from (%d %d) to (%d %d)", if (WarpDrive.isDev && WarpDriveConfig.LOGGING_CLOAKING) {
chunk.x, chunk.z, cloaks.size(), WarpDrive.logger.info(String.format("CloakManager Chunk_read (%d %d) %d cloak(s) from (%d %d) to (%d %d)",
chunkX_min, chunkZ_min, chunkX_max, chunkZ_max)); chunk.x, chunk.z, cloaks.size(),
chunkX_min, chunkZ_min, chunkX_max, chunkZ_max));
}
for (final CloakedArea area : cloaks) { for (final CloakedArea area : cloaks) {
if ( area.minX <= chunkX_max && area.maxX >= chunkX_min if ( area.minX <= chunkX_max && area.maxX >= chunkX_min
&& area.minZ <= chunkZ_max && area.maxZ >= chunkZ_min ) { && area.minZ <= chunkZ_max && area.maxZ >= chunkZ_min ) {
// WarpDrive.logger.info("CM chunk is inside"); if (WarpDrive.isDev && WarpDriveConfig.LOGGING_CLOAKING) {
WarpDrive.logger.info("CloakManager chunk is inside");
}
if (!area.isEntityWithinArea(Minecraft.getMinecraft().player)) { if (!area.isEntityWithinArea(Minecraft.getMinecraft().player)) {
// WarpDrive.logger.info("CM player is outside"); if (WarpDrive.isDev && WarpDriveConfig.LOGGING_CLOAKING) {
WarpDrive.logger.info("CloakManager player is outside");
}
final int areaX_min = Math.max(chunkX_min, area.minX) & 15; final int areaX_min = Math.max(chunkX_min, area.minX) & 15;
final int areaX_max = Math.min(chunkX_max, area.maxX) & 15; final int areaX_max = Math.min(chunkX_max, area.maxX) & 15;

View file

@ -93,10 +93,10 @@ public class CloakedArea {
&& minZ <= entity.posZ && (maxZ + 1) > entity.posZ); && minZ <= entity.posZ && (maxZ + 1) > entity.posZ);
} }
public boolean isBlockWithinArea(final int x, final int y, final int z) { public boolean isBlockWithinArea(final BlockPos blockPos) {
return (minX <= x && (maxX + 1) > x return (minX <= blockPos.getX() && (maxX + 1) > blockPos.getX()
&& minY <= y && (maxY + 1) > y && minY <= blockPos.getY() && (maxY + 1) > blockPos.getY()
&& minZ <= z && (maxZ + 1) > z); && minZ <= blockPos.getZ() && (maxZ + 1) > blockPos.getZ());
} }
// Sending only if field changes: sets up or collapsing // Sending only if field changes: sets up or collapsing

View file

@ -1,8 +1,6 @@
package cr0s.warpdrive; package cr0s.warpdrive.data;
import cr0s.warpdrive.config.Dictionary; import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.data.CelestialObject;
import cr0s.warpdrive.data.StarMapRegistry;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
@ -75,6 +73,11 @@ public class GravityManager {
return gravity * OVERWORLD_ENTITY_GRAVITY; return gravity * OVERWORLD_ENTITY_GRAVITY;
} }
@SuppressWarnings("unused") // Core mod
public static double getNegGravityForEntity(final Entity entity) {
return -getGravityForEntity(entity);
}
@SuppressWarnings("unused") // Core mod @SuppressWarnings("unused") // Core mod
public static double getItemGravity(final EntityItem entity) { public static double getItemGravity(final EntityItem entity) {
final double gravity = StarMapRegistry.getGravity(entity); final double gravity = StarMapRegistry.getGravity(entity);