File tree Expand file tree Collapse file tree 3 files changed +34
-6
lines changed
common/src/main/java/com/viaversion/viabackwards Expand file tree Collapse file tree 3 files changed +34
-6
lines changed Original file line number Diff line number Diff line change 2828import com .viaversion .viabackwards .protocol .v1_21_2to1_21 .Protocol1_21_2To1_21 ;
2929import com .viaversion .viabackwards .protocol .v1_21_2to1_21 .storage .PlayerStorage ;
3030import com .viaversion .viabackwards .protocol .v1_21_2to1_21 .storage .SignStorage ;
31+ import com .viaversion .viabackwards .utils .VelocityUtil ;
3132import com .viaversion .viaversion .api .data .entity .EntityTracker ;
3233import com .viaversion .viaversion .api .minecraft .Holder ;
3334import com .viaversion .viaversion .api .minecraft .Particle ;
@@ -548,9 +549,9 @@ private void handleRelativeArguments(
548549 } else if (!relativeDeltaX && !relativeDeltaY && !relativeDeltaZ ) {
549550 final PacketWrapper entityMotionPacket = wrapper .create (ClientboundPackets1_21 .SET_ENTITY_MOTION );
550551 entityMotionPacket .write (Types .VAR_INT , entityId != null ? entityId : tracker (wrapper .user ()).clientEntityId ());
551- entityMotionPacket .write (Types .SHORT , ( short ) ( movementX * 8000 ));
552- entityMotionPacket .write (Types .SHORT , ( short ) ( movementY * 8000 ));
553- entityMotionPacket .write (Types .SHORT , ( short ) ( movementZ * 8000 ));
552+ entityMotionPacket .write (Types .SHORT , VelocityUtil . toLegacyVelocity ( movementX ));
553+ entityMotionPacket .write (Types .SHORT , VelocityUtil . toLegacyVelocity ( movementY ));
554+ entityMotionPacket .write (Types .SHORT , VelocityUtil . toLegacyVelocity ( movementZ ));
554555
555556 entityMotionPacket .send (Protocol1_21_2To1_21 .class );
556557 } else if (!warned ) {
Original file line number Diff line number Diff line change 2525import com .viaversion .viabackwards .protocol .v1_21_9to1_21_7 .storage .MannequinData ;
2626import com .viaversion .viabackwards .protocol .v1_21_9to1_21_7 .storage .PlayerRotationStorage ;
2727import com .viaversion .viabackwards .protocol .v1_21_9to1_21_7 .tracker .EntityTracker1_21_9 ;
28+ import com .viaversion .viabackwards .utils .VelocityUtil ;
2829import com .viaversion .viaversion .api .connection .UserConnection ;
2930import com .viaversion .viaversion .api .data .entity .TrackedEntity ;
3031import com .viaversion .viaversion .api .minecraft .BlockPosition ;
@@ -329,9 +330,9 @@ private String randomHackyEmptyName() {
329330 }
330331
331332 private void writeMovementShorts (final PacketWrapper wrapper , final Vector3d movement ) {
332- wrapper .write (Types .SHORT , ( short ) ( movement .x () * 8000 ));
333- wrapper .write (Types .SHORT , ( short ) ( movement .y () * 8000 ));
334- wrapper .write (Types .SHORT , ( short ) ( movement .z () * 8000 ));
333+ wrapper .write (Types .SHORT , VelocityUtil . toLegacyVelocity ( movement .x ()));
334+ wrapper .write (Types .SHORT , VelocityUtil . toLegacyVelocity ( movement .y ()));
335+ wrapper .write (Types .SHORT , VelocityUtil . toLegacyVelocity ( movement .z ()));
335336 }
336337
337338 private void storePlayerRotation (final PacketWrapper wrapper ) {
Original file line number Diff line number Diff line change 1+ /*
2+ * This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
3+ * Copyright (C) 2016-2026 ViaVersion and contributors
4+ *
5+ * This program is free software: you can redistribute it and/or modify
6+ * it under the terms of the GNU General Public License as published by
7+ * the Free Software Foundation, either version 3 of the License, or
8+ * (at your option) any later version.
9+ *
10+ * This program is distributed in the hope that it will be useful,
11+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ * GNU General Public License for more details.
14+ *
15+ * You should have received a copy of the GNU General Public License
16+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17+ */
18+ package com .viaversion .viabackwards .utils ;
19+
20+ public class VelocityUtil {
21+
22+ public static short toLegacyVelocity (double value ) {
23+ return (short ) Math .max (Short .MIN_VALUE , Math .min (Short .MAX_VALUE , (long ) (value * 8000 )));
24+ }
25+
26+ }
You can’t perform that action at this time.
0 commit comments