diff --git a/src/dark/core/client/Effects.java b/src/dark/core/client/Effects.java index f95b065b..663e8a8f 100644 --- a/src/dark/core/client/Effects.java +++ b/src/dark/core/client/Effects.java @@ -29,13 +29,14 @@ public class Effects double dy = y - cy; double dz = z - cz; double ratio = Math.sqrt(dx * dx + dy * dy + dz * dz); - - while (Math.abs(cx - x) > Math.abs(dx / ratio)) + int i = 0; + while (Math.abs(cx - x) > Math.abs(dx / ratio) && i < 100) { world.spawnParticle("townaura", cx, cy, cz, 0.0D, 0.0D, 0.0D); cx += dx * 0.1 / ratio; cy += dy * 0.1 / ratio; cz += dz * 0.1 / ratio; + i++; } } } diff --git a/src/dark/core/common/DarkMain.java b/src/dark/core/common/DarkMain.java index c0f15fac..a367320b 100644 --- a/src/dark/core/common/DarkMain.java +++ b/src/dark/core/common/DarkMain.java @@ -9,6 +9,7 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraftforge.common.Configuration; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.ForgeSubscribe; import net.minecraftforge.event.world.WorldEvent; import net.minecraftforge.oredict.OreDictionary; @@ -30,6 +31,7 @@ import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.event.FMLServerStoppingEvent; import cpw.mods.fml.common.network.NetworkMod; import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.registry.TickRegistry; import cpw.mods.fml.relauncher.Side; import dark.api.ProcessorRecipes; import dark.api.ProcessorRecipes.ProcessorType; @@ -60,6 +62,7 @@ import dark.core.common.transmit.BlockWire; import dark.core.common.transmit.ItemBlockWire; import dark.core.network.PacketHandler; import dark.core.prefab.ModPrefab; +import dark.core.prefab.helpers.PacketDataWatcher; import dark.core.prefab.items.ItemBlockHolder; import dark.core.prefab.machine.BlockMulti; import dark.core.registration.ModObjectRegistry; @@ -119,8 +122,8 @@ public class DarkMain extends ModPrefab { instance = this; super.preInit(event); - NetworkRegistry.instance().registerGuiHandler(this, proxy); + MinecraftForge.EVENT_BUS.register(PacketDataWatcher.instance); proxy.preInit(); } diff --git a/src/dark/core/network/PacketManagerTile.java b/src/dark/core/network/PacketManagerTile.java index 7eaef7a6..be797a73 100644 --- a/src/dark/core/network/PacketManagerTile.java +++ b/src/dark/core/network/PacketManagerTile.java @@ -1,5 +1,7 @@ package dark.core.network; +import java.lang.reflect.Method; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.network.INetworkManager; import net.minecraft.network.packet.Packet250CustomPayload; @@ -10,6 +12,7 @@ import universalelectricity.prefab.network.IPacketReceiver; import com.google.common.io.ByteArrayDataInput; import cpw.mods.fml.common.network.Player; +import dark.core.prefab.helpers.PacketDataWatcher; public class PacketManagerTile implements IPacketManager { @@ -44,6 +47,7 @@ public class PacketManagerTile implements IPacketManager if (tileEntity != null) { + PacketDataWatcher.instance.onPacketData(tileEntity, packet, System.currentTimeMillis()); if (tileEntity instanceof ISimplePacketReceiver) { String pId = data.readUTF(); @@ -63,5 +67,4 @@ public class PacketManagerTile implements IPacketManager } } - } diff --git a/src/dark/core/prefab/helpers/PacketDataWatcher.java b/src/dark/core/prefab/helpers/PacketDataWatcher.java new file mode 100644 index 00000000..0b4cd99a --- /dev/null +++ b/src/dark/core/prefab/helpers/PacketDataWatcher.java @@ -0,0 +1,86 @@ +package dark.core.prefab.helpers; + +import java.util.ArrayList; +import java.util.EnumSet; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.network.packet.Packet250CustomPayload; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ChatMessageComponent; +import net.minecraft.world.World; +import net.minecraftforge.event.ForgeSubscribe; +import net.minecraftforge.event.entity.player.PlayerInteractEvent; +import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action; +import universalelectricity.core.vector.Vector3; + +import com.builtbroken.common.Pair; + +import cpw.mods.fml.common.IScheduledTickHandler; +import cpw.mods.fml.common.TickType; + +public class PacketDataWatcher +{ + HashMap, List> packetSizes = new HashMap, List>(); + + public static PacketDataWatcher instance = new PacketDataWatcher(); + + public boolean enable = false; + + public void onPacketData(TileEntity entity, Packet250CustomPayload data, long t) + { + if (entity != null && enable) + { + Pair location = new Pair(entity.worldObj, new Vector3(entity)); + List l = this.packetSizes.get(location); + if (l == null) + { + l = new ArrayList(); + } + l.add(data.getPacketSize()); + this.packetSizes.put(location, l); + } + } + + @ForgeSubscribe + public void playerRightClickEvent(PlayerInteractEvent event) + { + if (event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.capabilities.isCreativeMode && event.entityPlayer.getHeldItem() != null && event.entityPlayer.getHeldItem().itemID == Item.blazeRod.itemID) + { + if (event.entityPlayer.worldObj.isRemote) + { + if (event.entityPlayer.isSneaking()) + { + this.enable = !this.enable; + event.entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("PacketWatcher is now " + (this.enable ? "Enabled. Now caching packet sizes." : "Disabled. Data cache has been cleared"))); + this.packetSizes.clear(); + } + else + { + TileEntity ent = event.entityPlayer.worldObj.getBlockTileEntity(event.x, event.y, event.z); + if (ent != null) + { + System.out.println("Entity Check"); + Pair location = new Pair(ent.worldObj, new Vector3(ent)); + int p = 0, a = 0; + if (this.packetSizes.get(location) != null) + { + for (int i : this.packetSizes.get(location)) + { + a += i; + } + p = this.packetSizes.get(location).size(); + a /= (p > 0 ? p : 1); + } + event.entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("AveragePacketSize: " + a + "bits for " + p + " packets")); + + } + } + } + } + } +}