Smarter falling block snapping to grid, allow 0.5 Y and snap to block above if Y above 0.85
This commit is contained in:
		| @@ -51,7 +51,8 @@ public class FallingBlockWatcher extends FlagWatcher { | |||||||
|  |  | ||||||
|             relMove.getModifier().write(0, getDisguise().getEntity().getEntityId()); |             relMove.getModifier().write(0, getDisguise().getEntity().getEntityId()); | ||||||
|             shorts.write(0, conRel(loc.getX(), loc.getBlockX() + 0.5)); |             shorts.write(0, conRel(loc.getX(), loc.getBlockX() + 0.5)); | ||||||
|             shorts.write(1, conRel(loc.getY(), loc.getBlockY())); |             shorts.write(1, conRel(loc.getY(), | ||||||
|  |                     loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0))); | ||||||
|             shorts.write(2, conRel(loc.getZ(), loc.getBlockZ() + 0.5)); |             shorts.write(2, conRel(loc.getZ(), loc.getBlockZ() + 0.5)); | ||||||
|  |  | ||||||
|             try { |             try { | ||||||
|   | |||||||
| @@ -33,7 +33,7 @@ public class PacketHandlerMovement implements IPacketHandler { | |||||||
|                 PacketType.Play.Server.ENTITY_TELEPORT, PacketType.Play.Server.REL_ENTITY_MOVE}; |                 PacketType.Play.Server.ENTITY_TELEPORT, PacketType.Play.Server.REL_ENTITY_MOVE}; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private short conRel(int oldCord, int newCord) { |     private short conRel(double oldCord, double newCord) { | ||||||
|         return (short) ((oldCord - newCord) * 4096); |         return (short) ((oldCord - newCord) * 4096); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -87,21 +87,24 @@ public class PacketHandlerMovement implements IPacketHandler { | |||||||
|             if (sentPacket.getType() != PacketType.Play.Server.ENTITY_TELEPORT) { |             if (sentPacket.getType() != PacketType.Play.Server.ENTITY_TELEPORT) { | ||||||
|                 StructureModifier<Short> shorts = movePacket.getShorts(); |                 StructureModifier<Short> shorts = movePacket.getShorts(); | ||||||
|  |  | ||||||
|                 Location current = entity.getLocation(); |                 Location origLoc = entity.getLocation(); | ||||||
|                 Vector diff = new Vector(shorts.read(0) / 4096D, shorts.read(1) / 4096D, shorts.read(2) / 4096D); |                 Vector diff = new Vector(shorts.read(0) / 4096D, shorts.read(1) / 4096D, shorts.read(2) / 4096D); | ||||||
|                 Location newLoc = current.clone().subtract(diff); |                 Location newLoc = origLoc.clone().subtract(diff); | ||||||
|  |  | ||||||
|                 boolean sameBlock = |                 double origY = | ||||||
|                         current.getBlockX() == newLoc.getBlockX() && current.getBlockY() == newLoc.getBlockY() && |                         origLoc.getBlockY() + (origLoc.getY() % 1 >= 0.85 ? 1 : origLoc.getY() % 1 >= 0.35 ? .5 : 0); | ||||||
|                                 current.getBlockZ() == newLoc.getBlockZ(); |                 double newY = newLoc.getBlockY() + (newLoc.getY() % 1 >= 0.85 ? 1 : newLoc.getY() % 1 >= 0.35 ? .5 : 0); | ||||||
|  |  | ||||||
|  |                 boolean sameBlock = origLoc.getBlockX() == newLoc.getBlockX() && newY == origY && | ||||||
|  |                         origLoc.getBlockZ() == newLoc.getBlockZ(); | ||||||
|  |  | ||||||
|                 if (sameBlock) { |                 if (sameBlock) { | ||||||
|                     // Make no modifications |                     // Make no modifications but don't send anything | ||||||
|                     return; |                     return; | ||||||
|                 } else { |                 } else { | ||||||
|                     shorts.write(0, conRel(current.getBlockX(), newLoc.getBlockX())); |                     shorts.write(0, conRel(origLoc.getBlockX(), newLoc.getBlockX())); | ||||||
|                     shorts.write(1, conRel(current.getBlockY(), newLoc.getBlockY())); |                     shorts.write(1, conRel(origY, newY)); | ||||||
|                     shorts.write(2, conRel(current.getBlockZ(), newLoc.getBlockZ())); |                     shorts.write(2, conRel(origLoc.getBlockZ(), newLoc.getBlockZ())); | ||||||
|                 } |                 } | ||||||
|             } else { |             } else { | ||||||
|                 Location loc = entity.getLocation(); |                 Location loc = entity.getLocation(); | ||||||
| @@ -109,7 +112,13 @@ public class PacketHandlerMovement implements IPacketHandler { | |||||||
|                 StructureModifier<Double> doubles = movePacket.getDoubles(); |                 StructureModifier<Double> doubles = movePacket.getDoubles(); | ||||||
|                 // Center the block |                 // Center the block | ||||||
|                 doubles.write(0, loc.getBlockX() + 0.5); |                 doubles.write(0, loc.getBlockX() + 0.5); | ||||||
|                 doubles.write(1, (double) loc.getBlockY()); |  | ||||||
|  |                 double y = loc.getBlockY(); | ||||||
|  |  | ||||||
|  |                 // Force into a multiple of 0.25 | ||||||
|  |                 y += Math.floor((loc.getY() % 1) * 4) / 4D; | ||||||
|  |  | ||||||
|  |                 doubles.write(1, y); | ||||||
|                 doubles.write(2, loc.getBlockZ() + 0.5); |                 doubles.write(2, loc.getBlockZ() + 0.5); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -311,7 +311,7 @@ public class PacketHandlerSpawn implements IPacketHandler { | |||||||
|                 if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) { |                 if (((FallingBlockWatcher) disguise.getWatcher()).isGridLocked()) { | ||||||
|                     // Center the block |                     // Center the block | ||||||
|                     x = loc.getBlockX() + 0.5; |                     x = loc.getBlockX() + 0.5; | ||||||
|                     y = loc.getBlockY(); |                     y = loc.getBlockY() + (loc.getY() % 1 >= 0.85 ? 1 : loc.getY() % 1 >= 0.35 ? .5 : 0); | ||||||
|                     z = loc.getBlockZ() + 0.5; |                     z = loc.getBlockZ() + 0.5; | ||||||
|                 } |                 } | ||||||
|             } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) { |             } else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == -1) { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user