7171import com .google .common .base .Strings ;
7272import com .google .common .collect .BiMap ;
7373import com .google .common .collect .HashBiMap ;
74- import com .google .common .collect .Sets ;
7574import io .netty .util .internal .PlatformDependent ;
75+ import it .unimi .dsi .fastutil .bytes .ByteOpenHashSet ;
7676import it .unimi .dsi .fastutil .ints .Int2ObjectOpenHashMap ;
7777import it .unimi .dsi .fastutil .ints .IntArrayList ;
7878import it .unimi .dsi .fastutil .ints .IntOpenHashSet ;
79- import it .unimi .dsi .fastutil .longs .*;
79+ import it .unimi .dsi .fastutil .longs .Long2ObjectLinkedOpenHashMap ;
80+ import it .unimi .dsi .fastutil .longs .Long2ObjectMap ;
81+ import it .unimi .dsi .fastutil .longs .Long2ObjectOpenHashMap ;
82+ import it .unimi .dsi .fastutil .longs .LongIterator ;
8083import it .unimi .dsi .fastutil .objects .ObjectIterator ;
8184import lombok .Getter ;
8285import lombok .Setter ;
9093import java .lang .reflect .Field ;
9194import java .net .InetSocketAddress ;
9295import java .nio .ByteOrder ;
93- import java .util .List ;
9496import java .util .*;
95- import java .util .Queue ;
97+ import java .util .List ;
9698import java .util .Map .Entry ;
99+ import java .util .Queue ;
97100import java .util .concurrent .ThreadLocalRandom ;
98101import java .util .concurrent .TimeUnit ;
99102import java .util .concurrent .atomic .AtomicReference ;
@@ -125,6 +128,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
125128 public static final float DEFAULT_SPEED = 0.1f ;
126129 public static final float MAXIMUM_SPEED = 6f ; // TODO: Decrease when block collisions are fixed
127130 public static final float DEFAULT_FLY_SPEED = 0.05f ;
131+ public static final float DEFAULT_VERTICAL_FLY_SPEED = 1f ;
128132
129133 public static final int PERMISSION_CUSTOM = 3 ;
130134 public static final int PERMISSION_OPERATOR = 2 ;
@@ -178,7 +182,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
178182 protected Vector3 teleportPosition ;
179183 protected Vector3 newPosition ;
180184 protected Vector3 sleeping ;
181- private Vector3 lastRightClickPos ;
185+ private BlockVector3 lastRightClickPos ;
182186 private final Queue <Vector3 > clientMovements = PlatformDependent .newMpscQueue (4 );
183187
184188 protected boolean connected = true ;
@@ -215,6 +219,24 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
215219 @ Getter
216220 @ Setter
217221 private boolean canTickShield = true ;
222+ /**
223+ * Player's client-side walk speed. Remember to call getAdventureSettings().update() if changed.
224+ */
225+ @ Getter
226+ @ Setter
227+ private float walkSpeed = DEFAULT_SPEED ;
228+ /**
229+ * Player's client-side fly speed. Remember to call getAdventureSettings().update() if changed.
230+ */
231+ @ Getter
232+ @ Setter
233+ private float flySpeed = DEFAULT_FLY_SPEED ;
234+ /**
235+ * Player's client-side vertical fly speed. Remember to call getAdventureSettings().update() if changed.
236+ */
237+ @ Getter
238+ @ Setter
239+ private float verticalFlySpeed = DEFAULT_VERTICAL_FLY_SPEED ;
218240
219241 private int exp ;
220242 private int expLevel ;
@@ -296,7 +318,7 @@ public class Player extends EntityHuman implements CommandSender, InventoryHolde
296318 /**
297319 * Packets that can be received before the player has logged in
298320 */
299- private static final Set < Byte > PRE_LOGIN_PACKETS = Sets . newHashSet ( ProtocolInfo .BATCH_PACKET , ProtocolInfo .LOGIN_PACKET , ProtocolInfo .REQUEST_NETWORK_SETTINGS_PACKET , ProtocolInfo .REQUEST_CHUNK_RADIUS_PACKET , ProtocolInfo .SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET , ProtocolInfo .RESOURCE_PACK_CHUNK_REQUEST_PACKET , ProtocolInfo .RESOURCE_PACK_CLIENT_RESPONSE_PACKET , ProtocolInfo .CLIENT_CACHE_STATUS_PACKET , ProtocolInfo .PACKET_VIOLATION_WARNING_PACKET , ProtocolInfo .CLIENT_TO_SERVER_HANDSHAKE_PACKET );
321+ private static final ByteOpenHashSet PRE_LOGIN_PACKETS = new ByteOpenHashSet ( new byte []{ ProtocolInfo .BATCH_PACKET , ProtocolInfo .LOGIN_PACKET , ProtocolInfo .REQUEST_NETWORK_SETTINGS_PACKET , ProtocolInfo .REQUEST_CHUNK_RADIUS_PACKET , ProtocolInfo .SET_LOCAL_PLAYER_AS_INITIALIZED_PACKET , ProtocolInfo .RESOURCE_PACK_CHUNK_REQUEST_PACKET , ProtocolInfo .RESOURCE_PACK_CLIENT_RESPONSE_PACKET , ProtocolInfo .CLIENT_CACHE_STATUS_PACKET , ProtocolInfo .PACKET_VIOLATION_WARNING_PACKET , ProtocolInfo .CLIENT_TO_SERVER_HANDSHAKE_PACKET } );
300322 /**
301323 * Default kick message for flying
302324 */
@@ -4197,7 +4219,6 @@ public void onCompletion(Server server) {
41974219 UseItemData useItemData = (UseItemData ) transactionPacket .transactionData ;
41984220 BlockVector3 blockVector = useItemData .blockPos ;
41994221 BlockFace face = useItemData .face ;
4200- int type = useItemData .actionType ;
42014222
42024223 this .setShieldBlockingDelay (5 );
42034224
@@ -4209,14 +4230,14 @@ public void onCompletion(Server server) {
42094230 itemSent = true ; // Assume that the item is still correct even if the selected slot is not
42104231 }
42114232
4212- switch (type ) {
4233+ switch (useItemData . actionType ) {
42134234 case InventoryTransactionPacket .USE_ITEM_ACTION_CLICK_BLOCK :
42144235 // Hack: Fix client spamming right clicks
42154236 if ((lastRightClickPos != null && this .getInventory ().getItemInHandFast ().getBlockId () == BlockID .AIR && System .currentTimeMillis () - lastRightClickTime < 200.0 && blockVector .distanceSquared (lastRightClickPos ) < 0.00001 )) {
42164237 return ;
42174238 }
42184239
4219- lastRightClickPos = blockVector . asVector3 () ;
4240+ lastRightClickPos = blockVector ;
42204241 lastRightClickTime = System .currentTimeMillis ();
42214242
42224243 this .breakingBlock = null ;
@@ -4366,17 +4387,15 @@ public void onCompletion(Server server) {
43664387 return ;
43674388 }
43684389
4369- type = useItemOnEntityData .actionType ;
4370-
43714390 if (inventory .getHeldItemIndex () != useItemOnEntityData .hotbarSlot ) {
43724391 inventory .equipItem (useItemOnEntityData .hotbarSlot );
43734392 }
43744393
43754394 item = this .inventory .getItemInHand ();
43764395
4377- switch (type ) {
4396+ switch (useItemOnEntityData . actionType ) {
43784397 case InventoryTransactionPacket .USE_ITEM_ON_ENTITY_ACTION_INTERACT :
4379- if (this .distanceSquared (target ) > 1000 ) {
4398+ if (this .distanceSquared (target ) > 256 ) { // TODO: Note entity scale
43804399 this .getServer ().getLogger ().debug (username + ": target entity is too far away" );
43814400 return ;
43824401 }
@@ -4513,8 +4532,7 @@ public void onCompletion(Server server) {
45134532 ReleaseItemData releaseItemData = (ReleaseItemData ) transactionPacket .transactionData ;
45144533
45154534 try {
4516- type = releaseItemData .actionType ;
4517- switch (type ) {
4535+ switch (releaseItemData .actionType ) {
45184536 case InventoryTransactionPacket .RELEASE_ITEM_ACTION_RELEASE :
45194537 if (this .isUsingItem ()) {
45204538 int ticksUsed = this .server .getTick () - this .startAction ;
@@ -4529,7 +4547,7 @@ public void onCompletion(Server server) {
45294547 case InventoryTransactionPacket .RELEASE_ITEM_ACTION_CONSUME :
45304548 return ;
45314549 default :
4532- this .getServer ().getLogger ().debug (username + ": unknown release item action type: " + type );
4550+ this .getServer ().getLogger ().debug (username + ": unknown release item action type: " + releaseItemData . actionType );
45334551 }
45344552 } finally {
45354553 this .setUsingItem (false );
@@ -4687,12 +4705,11 @@ public void onCompletion(Server server) {
46874705 }
46884706
46894707 LecternUpdatePacket lecternUpdatePacket = (LecternUpdatePacket ) packet ;
4690- Vector3 lecternPos = lecternUpdatePacket .blockPosition .asVector3 ();
4691- if (lecternPos .distanceSquared (this ) > 4096 ) {
4708+ if (lecternUpdatePacket .blockPosition .distanceSquared (this ) > 4096 ) {
46924709 return ;
46934710 }
46944711 if (!lecternUpdatePacket .dropBook ) {
4695- BlockEntity blockEntityLectern = this .level .getBlockEntityIfLoaded (this .chunk , lecternPos );
4712+ BlockEntity blockEntityLectern = this .level .getBlockEntityIfLoaded (this .chunk , lecternUpdatePacket . blockPosition . asVector3 () );
46964713 if (blockEntityLectern instanceof BlockEntityLectern ) {
46974714 BlockEntityLectern lectern = (BlockEntityLectern ) blockEntityLectern ;
46984715 if (lectern .getRawPage () != lecternUpdatePacket .page ) {
@@ -4917,8 +4934,9 @@ private void onBlockBreakComplete(BlockVector3 blockPos, BlockFace face) { // Fr
49174934 }
49184935 this .needSendHeldItem = true ;
49194936 if (blockPos .distanceSquared (this ) < 10000 ) {
4920- this .level .sendBlocks (this , new Block []{this .level .getBlock (blockPos .asVector3 (), false )}, UpdateBlockPacket .FLAG_ALL_PRIORITY );
4921- BlockEntity blockEntity = this .level .getBlockEntityIfLoaded (this .chunk , blockPos .asVector3 ());
4937+ Vector3 pos = blockPos .asVector3 ();
4938+ this .level .sendBlocks (this , new Block []{this .level .getBlock (pos , false )}, UpdateBlockPacket .FLAG_ALL_PRIORITY );
4939+ BlockEntity blockEntity = this .level .getBlockEntityIfLoaded (this .chunk , pos );
49224940 if (blockEntity instanceof BlockEntitySpawnable ) {
49234941 ((BlockEntitySpawnable ) blockEntity ).spawnTo (this );
49244942 }
0 commit comments