diff --git a/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCore.java b/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCore.java index e81c0489..62925260 100644 --- a/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCore.java +++ b/src/main/java/cr0s/warpdrive/block/detection/BlockCloakingCore.java @@ -72,9 +72,9 @@ public class BlockCloakingCore extends BlockContainer { if (tileEntity != null && (par5EntityPlayer.getHeldItem() == null)) { WarpDrive.addChatMessage(par5EntityPlayer, tileEntity.getStatus() // + " isInvalid? " + te.isInvalid() + " Valid? " + te.isValid + " Cloaking? " + te.isCloaking + " Enabled? " + te.isEnabled - + ((!tileEntity.isValid) ? " Invalid assembly!" : - ((!tileEntity.isEnabled) ? " Cloak is disabled" : - ((tileEntity.isCloaking) ? " A tier " + tileEntity.tier + " cloak is currently covering " + tileEntity.volume + " blocks!" : "Cloak needs more power!")))); + + ((!tileEntity.isValid) ? "\nInvalid assembly!" : + ((!tileEntity.isEnabled) ? "\nCloak is disabled" : + ((tileEntity.isCloaking) ? "\nA tier " + tileEntity.tier + " cloak is currently covering " + tileEntity.volume + " blocks!" : "\nCloak needs more power!")))); return true; } diff --git a/src/main/java/cr0s/warpdrive/core/ClassTransformer.java b/src/main/java/cr0s/warpdrive/core/ClassTransformer.java index 52286666..f3be56c5 100644 --- a/src/main/java/cr0s/warpdrive/core/ClassTransformer.java +++ b/src/main/java/cr0s/warpdrive/core/ClassTransformer.java @@ -8,7 +8,11 @@ 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.FieldInsnNode; +import org.objectweb.asm.tree.InsnNode; +import org.objectweb.asm.tree.LabelNode; import org.objectweb.asm.tree.LdcInsnNode; +import org.objectweb.asm.tree.LineNumberNode; import org.objectweb.asm.tree.MethodInsnNode; import org.objectweb.asm.tree.MethodNode; import org.objectweb.asm.tree.VarInsnNode; @@ -17,15 +21,22 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans private HashMap nodemap = new HashMap(); private final String GRAVITY_MANAGER_CLASS = "cr0s/warpdrive/GravityManager"; + private final String CLOAK_MANAGER_CLASS = "cr0s/warpdrive/data/CloakManager"; private boolean debugLog = false; public ClassTransformer() { - nodemap.put("entityLivingBaseClass", "sv"); - nodemap.put("moveEntityWithHeadingMethod", "func_70612_e"); - nodemap.put("moveEntityWithHeadingDesc", "(FF)V"); - nodemap.put("entityItemClass", "xk"); - nodemap.put("onUpdateMethod", "func_70071_h_"); - nodemap.put("onUpdateDesc", "()V"); + nodemap.put("EntityLivingBase.class", "sv"); + nodemap.put("moveEntityWithHeading.name", "func_70612_e"); + nodemap.put("moveEntityWithHeading.desc", "(FF)V"); + + nodemap.put("EntityItem.class", "xk"); + nodemap.put("onUpdate.name", "func_70071_h_"); + nodemap.put("onUpdate.desc", "()V"); + + nodemap.put("WorldClient.class", "bjf"); + nodemap.put("func_147492_c.name", "func_147492_c"); + nodemap.put("func_147492_c.desc", "(IIILnet/minecraft/block/Block;I)Z"); + nodemap.put("setBlock.name", "func_147465_d"); } @Override @@ -37,23 +48,27 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans String className = name.replace('/', '.'); - if (debugLog) { System.out.println("Checking " + name); } - if (className.equals(nodemap.get("entityLivingBaseClass")) || className.equals("net.minecraft.entity.EntityLivingBase")) { - bytes = transformEntityLivingBase(bytes, name.contains(".")); - } else if (className.equals(nodemap.get("entityItemClass")) || className.equals("net.minecraft.entity.item.EntityItem")) { - bytes = transformEntityItem(bytes, name.contains("/")); + // if (debugLog) { System.out.println("Checking " + name); } + if (className.equals(nodemap.get("EntityLivingBase.class")) || className.equals("net.minecraft.entity.EntityLivingBase")) { + bytes = transformMinecraftEntityLivingBase(bytes); + } else if (className.equals(nodemap.get("EntityItem.class")) || className.equals("net.minecraft.entity.item.EntityItem")) { + bytes = transformMinecraftEntityItem(bytes); + } else if (className.equals(nodemap.get("WorldClient.class")) || className.equals("net.minecraft.client.multiplayer.WorldClient")) { + bytes = transformMinecraftWorldClient(bytes); + } else if (className.equals("com.creativemd.itemphysic.physics.ServerPhysic")) { + bytes = transformItemPhysicEntityItem(bytes); } return bytes; } - private byte[] transformEntityItem(byte[] bytes, final boolean isDevelopment) { - ClassNode node = new ClassNode(); - ClassReader reader = new ClassReader(bytes); - reader.accept(node, 0); - int operationCount = 2; + private byte[] transformMinecraftEntityLivingBase(byte[] bytes) { + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader(bytes); + classReader.accept(classNode, 0); + int operationCount = 1; int injectionCount = 0; - Iterator methods = node.methods.iterator(); + Iterator methods = classNode.methods.iterator(); do { if (!methods.hasNext()) { @@ -61,19 +76,78 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } MethodNode methodnode = (MethodNode) methods.next(); - if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } - if ( (methodnode.name.equals(nodemap.get("onUpdateMethod")) || methodnode.name.equals("onUpdate")) - && methodnode.desc.equals(nodemap.get("onUpdateDesc")) ) { + if ( (methodnode.name.equals(nodemap.get("moveEntityWithHeading.name")) || methodnode.name.equals("moveEntityWithHeading")) + && methodnode.desc.equals(nodemap.get("moveEntityWithHeading.desc")) ) { if (debugLog) { System.out.println("Method found!"); } int count = 0; while (count < methodnode.instructions.size()) { - AbstractInsnNode list = methodnode.instructions.get(count); + AbstractInsnNode abstractNode = methodnode.instructions.get(count); - if (list instanceof LdcInsnNode) { - LdcInsnNode nodeAt = (LdcInsnNode) list; + if (abstractNode instanceof LdcInsnNode) { + LdcInsnNode nodeAt = (LdcInsnNode) abstractNode; + + if (nodeAt.cst.equals(Double.valueOf(0.080000000000000002D))) { + VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); + MethodInsnNode overwriteNode = new MethodInsnNode( + Opcodes.INVOKESTATIC, + GRAVITY_MANAGER_CLASS, + "getGravityForEntity", + "(L" + "net/minecraft/entity/EntityLivingBase" + ";)D", + false); + methodnode.instructions.insertBefore(nodeAt, beforeNode); + methodnode.instructions.set(nodeAt, overwriteNode); + if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + injectionCount++; + } + } + + count++; + } + } + } while (true); + + if (injectionCount != operationCount) { + System.out.println("Injection failed for " + classNode.name + " (" + injectionCount + " / " + operationCount + "), aborting..."); + } else { + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); + classNode.accept(writer); + bytes = writer.toByteArray(); + System.out.println("Injection successfull!"); + } + return bytes; + } + + private byte[] transformMinecraftEntityItem(byte[] bytes) { + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader(bytes); + classReader.accept(classNode, 0); + int operationCount = 2; + int injectionCount = 0; + Iterator methods = classNode.methods.iterator(); + + do { + if (!methods.hasNext()) { + break; + } + + MethodNode methodnode = (MethodNode) methods.next(); + // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + + if ( (methodnode.name.equals(nodemap.get("onUpdate.name")) || methodnode.name.equals("onUpdate")) + && methodnode.desc.equals(nodemap.get("onUpdate.desc")) ) { + if (debugLog) { System.out.println("Method found!"); } + + int count = 0; + + while (count < methodnode.instructions.size()) { + AbstractInsnNode abstractNode = methodnode.instructions.get(count); + + if (abstractNode instanceof LdcInsnNode) { + LdcInsnNode nodeAt = (LdcInsnNode) abstractNode; if (nodeAt.cst.equals(Double.valueOf(0.039999999105930328D))) { VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); @@ -85,7 +159,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + node.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectionCount++; } @@ -99,7 +173,7 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + node.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectionCount++; } } @@ -110,23 +184,23 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } while (true); if (injectionCount != operationCount) { - System.out.println("Injection failed for " + node.name + " (" + injectionCount + " / " + operationCount + "), aborting..."); + System.out.println("Injection failed for " + classNode.name + " (" + injectionCount + " / " + operationCount + "), aborting..."); } else { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); - node.accept(writer); + classNode.accept(writer); bytes = writer.toByteArray(); System.out.println("Injection successfull!"); } return bytes; } - private byte[] transformEntityLivingBase(byte[] bytes, final boolean isDevelopment) { - ClassNode node = new ClassNode(); - ClassReader reader = new ClassReader(bytes); - reader.accept(node, 0); - int operationCount = 1; + private byte[] transformItemPhysicEntityItem(byte[] bytes) { + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader(bytes); + classReader.accept(classNode, 0); + int operationCount = 2; int injectionCount = 0; - Iterator methods = node.methods.iterator(); + Iterator methods = classNode.methods.iterator(); do { if (!methods.hasNext()) { @@ -134,30 +208,46 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } MethodNode methodnode = (MethodNode) methods.next(); + // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } - if ( (methodnode.name.equals(nodemap.get("moveEntityWithHeadingMethod")) || methodnode.name.equals("moveEntityWithHeading")) - && methodnode.desc.equals(nodemap.get("moveEntityWithHeadingDesc")) ) { + if ( (methodnode.name.equals("update")) + && methodnode.desc.equals("(Lnet/minecraft/entity/item/EntityItem;)V") ) { if (debugLog) { System.out.println("Method found!"); } int count = 0; while (count < methodnode.instructions.size()) { - AbstractInsnNode list = methodnode.instructions.get(count); + AbstractInsnNode abstractNode = methodnode.instructions.get(count); + if (debugLog) { deasm(abstractNode); } - if (list instanceof LdcInsnNode) { - LdcInsnNode nodeAt = (LdcInsnNode) list; + if (abstractNode instanceof LdcInsnNode) { + LdcInsnNode nodeAt = (LdcInsnNode) abstractNode; - if (nodeAt.cst.equals(Double.valueOf(0.080000000000000002D))) { + if (nodeAt.cst.equals(Double.valueOf(0.04D))) { VarInsnNode beforeNode = new VarInsnNode(Opcodes.ALOAD, 0); MethodInsnNode overwriteNode = new MethodInsnNode( Opcodes.INVOKESTATIC, GRAVITY_MANAGER_CLASS, - "getGravityForEntity", - "(L" + "net/minecraft/entity/EntityLivingBase" + ";)D", + "getItemGravity", + "(L" + "net/minecraft/entity/item/EntityItem" + ";)D", false); methodnode.instructions.insertBefore(nodeAt, beforeNode); methodnode.instructions.set(nodeAt, overwriteNode); - if (debugLog) { System.out.println("Injecting into " + node.name + "." + methodnode.name + " " + methodnode.desc); } + if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + injectionCount++; + } + + 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) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } injectionCount++; } } @@ -168,13 +258,105 @@ public class ClassTransformer implements net.minecraft.launchwrapper.IClassTrans } while (true); if (injectionCount != operationCount) { - System.out.println("Injection failed for " + node.name + " (" + injectionCount + " / " + operationCount + "), aborting..."); + System.out.println("Injection failed for " + classNode.name + " (" + injectionCount + " / " + operationCount + "), aborting..."); } else { ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); - node.accept(writer); + classNode.accept(writer); bytes = writer.toByteArray(); System.out.println("Injection successfull!"); } return bytes; } + + private byte[] transformMinecraftWorldClient(byte[] bytes) { + ClassNode classNode = new ClassNode(); + ClassReader classReader = new ClassReader(bytes); + classReader.accept(classNode, 0); + int operationCount = 1; + int injectionCount = 0; + Iterator methods = classNode.methods.iterator(); + + do { + if (!methods.hasNext()) { + break; + } + + MethodNode methodnode = (MethodNode) methods.next(); + // if (debugLog) { System.out.println("- Method " + methodnode.name + " " + methodnode.desc); } + + if ( (methodnode.name.equals(nodemap.get("func_147492_c.name")) || methodnode.name.equals("func_147492_c")) + && methodnode.desc.equals(nodemap.get("func_147492_c.desc")) ) { + if (debugLog) { System.out.println("Method found!"); } + + int count = 0; + + while (count < methodnode.instructions.size()) { + AbstractInsnNode abstractNode = methodnode.instructions.get(count); + + if (abstractNode instanceof MethodInsnNode) { + MethodInsnNode nodeAt = (MethodInsnNode) abstractNode; + + if (nodeAt.name.equals(nodemap.get("setBlock.name")) || nodeAt.name.equals("setBlock")) { + MethodInsnNode overwriteNode = new MethodInsnNode( + Opcodes.INVOKESTATIC, + CLOAK_MANAGER_CLASS, + "onBlockChange", + "(IIILnet/minecraft/block/Block;II)Z", + false); + methodnode.instructions.set(nodeAt, overwriteNode); + if (debugLog) { System.out.println("Injecting into " + classNode.name + "." + methodnode.name + " " + methodnode.desc); } + injectionCount++; + } + } + + count++; + } + } + } while (true); + + if (injectionCount != operationCount) { + System.out.println("Injection failed for " + classNode.name + " (" + injectionCount + " / " + operationCount + "), aborting..."); + } else { + ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); // | ClassWriter.COMPUTE_FRAMES); + classNode.accept(writer); + bytes = writer.toByteArray(); + System.out.println("Injection successfull!"); + } + return bytes; + } + + private static void deasm(AbstractInsnNode abstractNode) { + if (abstractNode instanceof VarInsnNode) { + VarInsnNode node = (VarInsnNode) abstractNode; + System.out.println(" + Var " + node.var); + + } else if (abstractNode instanceof LabelNode) { + LabelNode node = (LabelNode) abstractNode; + System.out.println(" + Label " + node.getLabel()); + + } else if (abstractNode instanceof LineNumberNode) { + LineNumberNode node = (LineNumberNode) abstractNode; + System.out.println(" + Line " + node.line); + + } else if (abstractNode instanceof InsnNode) { + InsnNode node = (InsnNode) abstractNode; + System.out.println(" + Instruction " + node); + + } else if (abstractNode instanceof LdcInsnNode) { + LdcInsnNode node = (LdcInsnNode) abstractNode; + System.out.println(" + Load " + node.cst); + + } else if (abstractNode instanceof FieldInsnNode) { + FieldInsnNode node = (FieldInsnNode) abstractNode; + System.out.println(" + Field " + node.owner + " " + node.name + " " + node.desc); + + } else if (abstractNode instanceof MethodInsnNode) { + MethodInsnNode node = (MethodInsnNode) abstractNode; + System.out.println(" + Method " + node.owner + " " + node.name + " " + node.desc); + + } else { + System.out.println(" + Instruction " + abstractNode.getOpcode() + " " + abstractNode.getType() + " " + abstractNode.toString()); + } + + } } diff --git a/src/main/java/cr0s/warpdrive/data/CloakManager.java b/src/main/java/cr0s/warpdrive/data/CloakManager.java index 937a6371..e5e8d7c2 100644 --- a/src/main/java/cr0s/warpdrive/data/CloakManager.java +++ b/src/main/java/cr0s/warpdrive/data/CloakManager.java @@ -2,10 +2,16 @@ package cr0s.warpdrive.data; import java.util.LinkedList; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.World; +import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.network.PacketHandler; /** @@ -17,7 +23,7 @@ import cr0s.warpdrive.network.PacketHandler; public class CloakManager { - private LinkedList cloaks; + private static LinkedList cloaks; public CloakManager() { this.cloaks = new LinkedList(); @@ -76,7 +82,10 @@ public class CloakManager { return (getCloakedArea(worldObj, x, y, z) != null); } - public void addCloakedAreaWorld(World worldObj, int minX, int minY, int minZ, int maxX, int maxY, int maxZ, int x, int y, int z, byte tier) { + public void addCloakedAreaWorld(World worldObj, + final int minX, final int minY, final int minZ, + final int maxX, final int maxY, final int maxZ, + final int x, final int y, final int z, final byte tier) { cloaks.add(new CloakedArea(worldObj, x, y, z, AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ), tier)); } @@ -97,7 +106,7 @@ public class CloakManager { } public CloakedArea getCloakedArea(World worldObj, int x, int y, int z) { - for (CloakedArea area : this.cloaks) { + for (CloakedArea area : cloaks) { if (area.coreX == x && area.coreY == y && area.coreZ == z && area.dimensionId == worldObj.provider.dimensionId) return area; } @@ -105,9 +114,40 @@ public class CloakManager { return null; } + @SideOnly(Side.CLIENT) + public CloakedArea getCloakedArea(int x, int y, int z) { + // client only + for (CloakedArea area : cloaks) { + if (area.coreX == x && area.coreY == y && area.coreZ == z) + return area; + } + + return null; + } + public void updatePlayer(EntityPlayer player) { for (CloakedArea area : this.cloaks) { area.updatePlayer(player); } } + + @SideOnly(Side.CLIENT) + public static boolean onBlockChange(int x, int y, int z, Block block, int metadata, int flag) { + if (block != Blocks.air) { + for (CloakedArea area : cloaks) { + if (area.isBlockWithinArea(x, y, z)) { + // WarpDrive.logger.info("CM block is inside"); + if (!area.isEntityWithinArea(Minecraft.getMinecraft().thePlayer)) { + // WarpDrive.logger.info("CM player is inside"); + if (area.tier == 1) { + return Minecraft.getMinecraft().theWorld.setBlock(x, y, z, WarpDrive.blockGas, 5, flag); + } else { + return Minecraft.getMinecraft().theWorld.setBlock(x, y, z, Blocks.air, 0, flag); + } + } + } + } + } + return Minecraft.getMinecraft().theWorld.setBlock(x, y, z, block, metadata, flag); + } } diff --git a/src/main/java/cr0s/warpdrive/data/CloakedArea.java b/src/main/java/cr0s/warpdrive/data/CloakedArea.java index 9e98b482..d69e4ec6 100644 --- a/src/main/java/cr0s/warpdrive/data/CloakedArea.java +++ b/src/main/java/cr0s/warpdrive/data/CloakedArea.java @@ -23,6 +23,33 @@ public class CloakedArea { private LinkedList playersInArea; public byte tier = 0; + public CloakedArea(World worldObj, final int x, final int y, final int z, AxisAlignedBB aabb, final byte tier) { + this.coreX = x; + this.coreY = y; + this.coreZ = z; + this.aabb = aabb; + this.tier = tier; + this.playersInArea = new LinkedList(); + + if (worldObj == null || aabb == null) { + return; + } + + this.dimensionId = worldObj.provider.dimensionId; + + try { + // Add all players currently inside the field + List list = worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, this.aabb); + for (Entity e : list) { + if (e instanceof EntityPlayer) { + addPlayer(((EntityPlayer) e).getCommandSenderName()); + } + } + } catch (Exception exception) { + exception.printStackTrace(); + } + } + public boolean isPlayerListedInArea(String username) { for (String playerInArea : playersInArea) { if (playerInArea.equals(username)) { @@ -54,31 +81,10 @@ public class CloakedArea { && aabb.minZ <= entity.posZ && (aabb.maxZ + 1) > entity.posZ); } - public CloakedArea(World worldObj, int x, int y, int z, AxisAlignedBB aabb, byte tier) { - this.coreX = x; - this.coreY = y; - this.coreZ = z; - this.aabb = aabb; - this.tier = tier; - this.playersInArea = new LinkedList(); - - if (worldObj == null || aabb == null) { - return; - } - - this.dimensionId = worldObj.provider.dimensionId; - - try { - // Add all players currently inside the field - List list = worldObj.getEntitiesWithinAABB(EntityPlayerMP.class, this.aabb); - for (Entity e : list) { - if (e instanceof EntityPlayer) { - addPlayer(((EntityPlayer) e).getCommandSenderName()); - } - } - } catch (Exception e) { - e.printStackTrace(); - } + public boolean isBlockWithinArea(final int x, final int y, final int z) { + return (aabb.minX <= x && (aabb.maxX + 1) > x + && aabb.minY <= y && (aabb.maxY + 1) > y + && aabb.minZ <= z && (aabb.maxZ + 1) > z); } // Sending only if field changes: sets up or collapsing diff --git a/src/main/java/cr0s/warpdrive/network/MessageCloak.java b/src/main/java/cr0s/warpdrive/network/MessageCloak.java index d3ad606e..27e0d7fb 100644 --- a/src/main/java/cr0s/warpdrive/network/MessageCloak.java +++ b/src/main/java/cr0s/warpdrive/network/MessageCloak.java @@ -30,14 +30,14 @@ public class MessageCloak implements IMessage, IMessageHandler (" + cloakMessage.maxX + "; " + cloakMessage.maxY + "; " + cloakMessage.maxZ + ")"); + + ") -> (" + cloakMessage.maxX + "; " + cloakMessage.maxY + "; " + cloakMessage.maxZ + ") tier " + cloakMessage.tier); } EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer; diff --git a/src/main/java/cr0s/warpdrive/network/PacketHandler.java b/src/main/java/cr0s/warpdrive/network/PacketHandler.java index 8342c9d3..84e78b36 100644 --- a/src/main/java/cr0s/warpdrive/network/PacketHandler.java +++ b/src/main/java/cr0s/warpdrive/network/PacketHandler.java @@ -25,11 +25,11 @@ import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.data.Vector3; public class PacketHandler { - public static final SimpleNetworkWrapper simpleNetworkManager = NetworkRegistry.INSTANCE.newSimpleChannel(WarpDrive.MODID); + public static final SimpleNetworkWrapper simpleNetworkManager = NetworkRegistry.INSTANCE.newSimpleChannel(WarpDrive.MODID); private static Method EntityTrackerEntry_getPacketForThisEntity; - public static void init() { - // Forge packets + public static void init() { + // Forge packets simpleNetworkManager.registerMessage(MessageBeamEffect.class, MessageBeamEffect.class, 0, Side.CLIENT); simpleNetworkManager.registerMessage(MessageFrequency.class , MessageFrequency.class , 1, Side.CLIENT); simpleNetworkManager.registerMessage(MessageCloak.class , MessageCloak.class , 2, Side.CLIENT); @@ -43,7 +43,7 @@ public class PacketHandler { } catch (Exception e) { throw new RuntimeException(e); } - } + } // Beam effect sent to client side public static void sendBeamPacket(World worldObj, Vector3 source, Vector3 target, float red, float green, float blue, int age, int energy, int radius) { @@ -62,7 +62,7 @@ public class PacketHandler { int radius_square = radius * radius; for (int index = 0; index < playerEntityList.size(); index++) { EntityPlayerMP entityplayermp = playerEntityList.get(index); - + if (entityplayermp.dimension == dimensionId) { Vector3 player = new Vector3(entityplayermp); if (source.distanceTo_square(player) < radius_square || target.distanceTo_square(player) < radius_square) { @@ -111,14 +111,14 @@ public class PacketHandler { } // Sending cloaking area definition (server -> client) - public static void sendCloakPacket(EntityPlayer player, final AxisAlignedBB aabb, final int tier, final boolean decloak) { + public static void sendCloakPacket(EntityPlayer player, final AxisAlignedBB aabb, final byte tier, final boolean decloak) { MessageCloak cloakMessage = new MessageCloak(aabb, tier, decloak); simpleNetworkManager.sendTo(cloakMessage, (EntityPlayerMP) player); if (WarpDriveConfig.LOGGING_CLOAKING) { - WarpDrive.logger.info("Sent cloak packet (aabb " + aabb + ") tier " + tier + " decloak " + decloak); + WarpDrive.logger.info("Sent cloak packet (aabb " + aabb + " tier " + tier + " decloak " + decloak + ")"); } } - + public static Packet getPacketForThisEntity(Entity entity) { EntityTrackerEntry entry = new EntityTrackerEntry(entity, 0, 0, false); try {