Tweaked disguise movement to cut out jitters.

This commit is contained in:
Jonathan Williams 2013-08-28 15:00:39 -07:00
parent cb48c2a037
commit a1d622c790
4 changed files with 88 additions and 68 deletions

View File

@ -131,9 +131,6 @@
<fileset dir="../Mineplex.Core.Common/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Minecraft.Punish/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Minecraft.Game.Core/bin">
<include name="**/*.class"/>
</fileset>
@ -207,12 +204,6 @@
<fileset dir="../Mineplex.Minecraft.Game.Core/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Minecraft.Shop/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.Minecraft.Punish/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Nautilus.Game.MineKart">
<include name="*.yml"/>

View File

@ -13,6 +13,8 @@ import net.minecraft.server.v1_6_R2.Packet24MobSpawn;
import net.minecraft.server.v1_6_R2.Packet28EntityVelocity;
import net.minecraft.server.v1_6_R2.Packet29DestroyEntity;
import net.minecraft.server.v1_6_R2.Packet31RelEntityMove;
import net.minecraft.server.v1_6_R2.Packet33RelEntityMoveLook;
import net.minecraft.server.v1_6_R2.Packet34EntityTeleport;
import net.minecraft.server.v1_6_R2.Packet40EntityMetadata;
import net.minecraft.server.v1_6_R2.Packet62NamedSoundEffect;
@ -45,6 +47,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
private NautHashMap<Integer, DisguiseBase> _spawnPacketMap = new NautHashMap<Integer, DisguiseBase>();
private NautHashMap<Integer, Packet28EntityVelocity> _movePacketMap = new NautHashMap<Integer, Packet28EntityVelocity>();
private NautHashMap<Integer, Packet28EntityVelocity> _moveTempMap = new NautHashMap<Integer, Packet28EntityVelocity>();
private HashSet<Integer> _goingUp = new HashSet<Integer>();
private NautHashMap<String, DisguiseBase> _entityDisguiseMap = new NautHashMap<String, DisguiseBase>();
private NautHashMap<String, EntityType> _addTempList = new NautHashMap<String, EntityType>();
private HashSet<String> _delTempList = new HashSet<String>();
@ -53,8 +56,6 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
private Field _soundC;
private Field _soundD;
//private int _tickCount = 0;
public DisguiseManager(JavaPlugin plugin, PacketHandler packetHandler)
{
super("Disguise Manager", plugin);
@ -162,37 +163,18 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
@EventHandler
public void TeleportDisguises(UpdateEvent event)
{
if (event.getType() != UpdateType.TICK)
if (event.getType() != UpdateType.SEC)
return;
_tickCount++;
_tickCount %= 20;
for (Player player : Bukkit.getOnlinePlayers())
{
for (Player otherPlayer : Bukkit.getOnlinePlayers())
{
if (otherPlayer.getLocation().subtract(0, .5, 0).getBlock().getTypeId() == 0)
{
if (_moveTempMap.containsKey(otherPlayer.getEntityId()))
{
((CraftPlayer)player).getHandle().playerConnection.sendPacket(_moveTempMap.get(otherPlayer.getEntityId()));
//System.out.println("Sending buffer packet for (" + otherPlayer.getEntityId() + ") at " + _tickCount + " ticks");
}
if (player == otherPlayer)
continue;
//System.out.println("Player in the air.");
//((CraftPlayer)player).getHandle().playerConnection.sendPacket(new Packet34EntityTeleport(((CraftPlayer)otherPlayer).getHandle()));
}
}
}
for (Player otherPlayer : Bukkit.getOnlinePlayers())
{
if (_moveTempMap.containsKey(otherPlayer.getEntityId()))
{
_moveTempMap.remove(otherPlayer.getEntityId());
//System.out.println("Cleared buffer packet for (" + otherPlayer.getEntityId() + ") at " + _tickCount + " ticks");
if (otherPlayer.getLocation().subtract(0, .5, 0).getBlock().getTypeId() != 0)
((CraftPlayer)player).getHandle().playerConnection.sendPacket(new Packet34EntityTeleport(((CraftPlayer)otherPlayer).getHandle()));
}
}
}
@ -204,7 +186,7 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
}
@Override
public boolean run(Packet packet, Player owner, PacketArrayList packetList)
public boolean run(Packet packet, Player owner, final PacketArrayList packetList)
{
if (packet instanceof Packet20NamedEntitySpawn)
{
@ -236,7 +218,21 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
return false;
}
}
if (packet instanceof Packet31RelEntityMove)
else if (packet instanceof Packet28EntityVelocity)
{
Packet28EntityVelocity velocityPacket = (Packet28EntityVelocity)packet;
// Only for viewers
if (velocityPacket.a == owner.getEntityId() && velocityPacket.c > 0)
{
_goingUp.add(velocityPacket.a);
}
else if (_spawnPacketMap.containsKey(velocityPacket.a))
{
return false;
}
}
else if (packet instanceof Packet31RelEntityMove)
{
final Packet31RelEntityMove movePacket = (Packet31RelEntityMove)packet;
@ -244,57 +240,88 @@ public class DisguiseManager extends MiniPlugin implements IPacketRunnable
if (movePacket.a == owner.getEntityId())
return true;
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c < 20)
{
_goingUp.remove(movePacket.a);
_movePacketMap.remove(movePacket.a);
}
if (!_spawnPacketMap.containsKey(movePacket.a))
return true;
if (movePacket.b + movePacket.c + movePacket.d == 0)
{
_movePacketMap.remove(movePacket.a);
return true;
}
final Packet28EntityVelocity velocityPacket = new Packet28EntityVelocity();
velocityPacket.a = movePacket.a;
velocityPacket.b = movePacket.b * 100;
velocityPacket.c = movePacket.c * 100;
velocityPacket.d = movePacket.d * 100;
packetList.forceAdd(velocityPacket);
boolean goingUp = false;
int lastX = velocityPacket.b;
int lastY = velocityPacket.c;
int lastZ = velocityPacket.d;
if (_movePacketMap.containsKey(movePacket.a))
{
Packet28EntityVelocity lastVelocityPacket = _movePacketMap.get(movePacket.a);
lastX = lastVelocityPacket.b;
lastY = lastVelocityPacket.c;
lastZ = lastVelocityPacket.d;
velocityPacket.b = (int) (.8 * lastVelocityPacket.b);
velocityPacket.c = (int) (.8 * lastVelocityPacket.c);
velocityPacket.d = (int) (.8 * lastVelocityPacket.d);
}
if (lastY < velocityPacket.c)
goingUp = true;
_movePacketMap.put(movePacket.a, velocityPacket);
velocityPacket.b = lastX == 0 ? 0 : velocityPacket.b * (velocityPacket.b / lastX);
velocityPacket.c = lastY == 0 ? 0 : velocityPacket.c * (velocityPacket.c / lastY);
velocityPacket.d = lastZ == 0 ? 0 : velocityPacket.d * (velocityPacket.d / lastZ);
packetList.forceAdd(velocityPacket);
if (goingUp)
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c > 20)
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
{
public void run()
{
if (!_moveTempMap.containsKey(movePacket.a))
{
_moveTempMap.put(movePacket.a, velocityPacket);
//System.out.println("Added buffer velocity packet for (" + movePacket.a + ") : (" + velocityPacket.b + ", " + velocityPacket.c + ", " + velocityPacket.d + ") at " + _tickCount + " ticks");
packetList.forceAdd(velocityPacket);
}
});
}
}
else if (packet instanceof Packet33RelEntityMoveLook)
{
final Packet33RelEntityMoveLook movePacket = (Packet33RelEntityMoveLook)packet;
// Only for viewers
if (movePacket.a == owner.getEntityId())
return true;
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c <= 20)
{
_goingUp.remove(movePacket.a);
_movePacketMap.remove(movePacket.a);
}
if (!_spawnPacketMap.containsKey(movePacket.a))
return true;
final Packet28EntityVelocity velocityPacket = new Packet28EntityVelocity();
velocityPacket.a = movePacket.a;
velocityPacket.b = movePacket.b * 100;
velocityPacket.c = movePacket.c * 100;
velocityPacket.d = movePacket.d * 100;
if (_movePacketMap.containsKey(movePacket.a))
{
Packet28EntityVelocity lastVelocityPacket = _movePacketMap.get(movePacket.a);
velocityPacket.b = (int) (.8 * lastVelocityPacket.b);
velocityPacket.c = (int) (.8 * lastVelocityPacket.c);
velocityPacket.d = (int) (.8 * lastVelocityPacket.d);
}
_movePacketMap.put(movePacket.a, velocityPacket);
packetList.forceAdd(velocityPacket);
if (_goingUp.contains(movePacket.a) && movePacket.c != 0 && movePacket.c > 20)
{
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
{
public void run()
{
packetList.forceAdd(velocityPacket);
}
});
}

View File

@ -84,6 +84,8 @@ public class PacketArrayList extends ArrayList<Packet>
{
Packet34EntityTeleport packet = (Packet34EntityTeleport)o;
//System.out.println("Packet34EntityTeleport (" + packet.b + ", " + packet.c + ", " + packet.d + ")");
if (_handler.IsForwarding(_owner) && _handler.IsForwarded(_owner, packet.a))
{
return super.add(new Packet34EntityTeleport(_handler.GetForwardId(_owner, packet.a), packet.b, packet.c, packet.d, packet.e, packet.f));
@ -95,7 +97,7 @@ public class PacketArrayList extends ArrayList<Packet>
{
Packet28EntityVelocity packet = (Packet28EntityVelocity)o;
//System.out.println("Packet28EntityVelocity (" + packet.b / 8000.0D + ", " + packet.c / 8000.0D + ", " + packet.d / 8000.0D + ")");
//System.out.println("Packet28EntityVelocity (" + packet.b / 8000.0D + ", " + packet.c / 8000.0D + ", " + packet.d / 8000.0D + ") for " + packet.a + " to " + _owner.getName());
if (_handler.IsForwarding(_owner) && _handler.IsForwarded(_owner, packet.a))
{