Add in Item height as well, prevents floating disguises when a item is disguised

This commit is contained in:
libraryaddict 2014-06-12 18:06:07 +12:00
parent 0056898e01
commit 014c34ce0e

View File

@ -149,7 +149,7 @@ public class PacketsManager {
for (int i = 0; i < packets.size(); i++) { for (int i = 0; i < packets.size(); i++) {
spawnPackets[i + 2] = packets.get(i); spawnPackets[i + 2] = packets.get(i);
} }
Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguise), 0); Location loc = disguisedEntity.getLocation().clone().add(0, getYModifier(disguisedEntity, disguise), 0);
byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F); byte yaw = (byte) (int) (loc.getYaw() * 256.0F / 360.0F);
byte pitch = (byte) (int) (loc.getPitch() * 256.0F / 360.0F); byte pitch = (byte) (int) (loc.getPitch() * 256.0F / 360.0F);
if (DisguiseConfig.isMovementPacketsEnabled()) { if (DisguiseConfig.isMovementPacketsEnabled()) {
@ -423,27 +423,31 @@ public class PacketsManager {
/** /**
* Get the Y level to add to the disguise for realism. * Get the Y level to add to the disguise for realism.
*/ */
private static double getYModifier(Disguise disguise) { private static double getYModifier(Entity entity, Disguise disguise) {
double yMod = 0;
if (entity.getType() == EntityType.DROPPED_ITEM) {
yMod -= 0.13;
}
switch (disguise.getType()) { switch (disguise.getType()) {
case BAT: case BAT:
if (disguise.getEntity() instanceof LivingEntity) if (entity instanceof LivingEntity)
return ((LivingEntity) disguise.getEntity()).getEyeHeight(); return yMod + ((LivingEntity) entity).getEyeHeight();
case MINECART: case MINECART:
case MINECART_CHEST: case MINECART_CHEST:
case MINECART_FURNACE: case MINECART_FURNACE:
case MINECART_HOPPER: case MINECART_HOPPER:
case MINECART_MOB_SPAWNER: case MINECART_MOB_SPAWNER:
case MINECART_TNT: case MINECART_TNT:
switch (disguise.getEntity().getType()) { switch (entity.getType()) {
case MINECART: case MINECART:
case MINECART_CHEST: case MINECART_CHEST:
case MINECART_FURNACE: case MINECART_FURNACE:
case MINECART_HOPPER: case MINECART_HOPPER:
case MINECART_MOB_SPAWNER: case MINECART_MOB_SPAWNER:
case MINECART_TNT: case MINECART_TNT:
return 0; return yMod;
default: default:
return 0.4; return yMod + 0.4;
} }
case ARROW: case ARROW:
case BOAT: case BOAT:
@ -457,16 +461,18 @@ public class PacketsManager {
case SPLASH_POTION: case SPLASH_POTION:
case THROWN_EXP_BOTTLE: case THROWN_EXP_BOTTLE:
case WITHER_SKULL: case WITHER_SKULL:
return 0.7; return yMod + 0.7;
case PLAYER: case PLAYER:
if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) { if (DisguiseConfig.isBedPacketsEnabled() && ((PlayerWatcher) disguise.getWatcher()).isSleeping()) {
return 0.35; return yMod + 0.35;
} }
break; break;
case DROPPED_ITEM:
return yMod + 0.13;
default: default:
break; break;
} }
return 0; return yMod;
} }
/** /**
@ -1285,7 +1291,7 @@ public class PacketsManager {
byte pitchValue = (Byte) mods.read(5); byte pitchValue = (Byte) mods.read(5);
mods.write(5, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue)); mods.write(5, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) { if (sentPacket.getType() == PacketType.Play.Server.ENTITY_TELEPORT) {
double y = getYModifier(disguise); double y = getYModifier(entity, disguise);
if (y != 0) { if (y != 0) {
y *= 32; y *= 32;
mods.write(2, (Integer) mods.read(2) + (int) Math.floor(y)); mods.write(2, (Integer) mods.read(2) + (int) Math.floor(y));