From bd4b8d427a4abe120a244c9201406e542c81a755 Mon Sep 17 00:00:00 2001 From: Sen Date: Sat, 24 May 2025 20:38:49 +0200 Subject: [PATCH] network code cleanup --- client/src/client/network/ClientPlayer.java | 118 +-- common/src/common/block/BlockChest.java | 6 +- common/src/common/entity/DataWatcher.java | 6 +- .../src/common/entity/EntityTrackerEntry.java | 48 +- common/src/common/entity/npc/EntityNPC.java | 13 +- .../src/common/entity/types/EntityLiving.java | 6 +- common/src/common/item/Item.java | 8 - .../common/network/CompressionDecoder.java | 47 ++ .../common/network/CompressionEncoder.java | 42 ++ ...ionDecoder.java => EncryptionDecoder.java} | 8 +- ...ionEncoder.java => EncryptionEncoder.java} | 8 +- .../common/network/IClientLoginHandler.java | 13 +- common/src/common/network/IClientPlayer.java | 178 ++--- .../src/common/network/IHandshakeHandler.java | 6 +- common/src/common/network/ILoginHandler.java | 8 +- common/src/common/network/IPlayer.java | 97 +-- .../src/common/network/IThreadListener.java | 3 +- common/src/common/network/NetConnection.java | 170 ++--- common/src/common/network/NetHandler.java | 9 +- .../network/NettyCompressionDecoder.java | 62 -- .../network/NettyCompressionEncoder.java | 53 -- common/src/common/network/Packet.java | 3 +- common/src/common/network/PacketBuffer.java | 685 +++++++----------- common/src/common/network/PacketDecoder.java | 59 +- common/src/common/network/PacketEncoder.java | 55 +- .../src/common/network/PacketPrepender.java | 30 +- common/src/common/network/PacketRegistry.java | 296 ++++---- common/src/common/network/PacketSplitter.java | 72 +- common/src/common/packet/APacketVarInt.java | 4 +- common/src/common/packet/CPacketAction.java | 4 +- common/src/common/packet/CPacketBook.java | 52 -- common/src/common/packet/CPacketCheat.java | 4 +- common/src/common/packet/CPacketClick.java | 4 +- common/src/common/packet/CPacketComplete.java | 6 +- common/src/common/packet/CPacketForm.java | 14 +- common/src/common/packet/CPacketMessage.java | 2 +- common/src/common/packet/CPacketPlace.java | 4 +- common/src/common/packet/CPacketPlayer.java | 104 --- .../src/common/packet/CPacketPlayerLook.java | 35 + .../common/packet/CPacketPlayerPosLook.java | 46 ++ .../common/packet/CPacketPlayerPosition.java | 38 + common/src/common/packet/CPacketSign.java | 2 +- common/src/common/packet/CPacketSkin.java | 2 +- .../src/common/packet/HPacketHandshake.java | 4 +- common/src/common/packet/LPacketLogin.java | 2 +- .../packet/LPacketPasswordResponse.java | 6 +- .../src/common/packet/RPacketDisconnect.java | 2 +- common/src/common/packet/S14PacketEntity.java | 208 ------ .../src/common/packet/SPacketAnimation.java | 4 +- .../src/common/packet/SPacketBlockAction.java | 4 +- .../common/packet/SPacketBlockBreakAnim.java | 4 +- .../src/common/packet/SPacketBlockChange.java | 4 +- common/src/common/packet/SPacketCamera.java | 4 +- ...State.java => SPacketChangeGameState.java} | 14 +- .../common/packet/SPacketCharacterList.java | 24 +- .../src/common/packet/SPacketChunkData.java | 8 +- ...oseWindow.java => SPacketCloseWindow.java} | 6 +- .../src/common/packet/SPacketCollectItem.java | 8 +- ...on.java => SPacketConfirmTransaction.java} | 6 +- .../common/packet/SPacketDestroyEntities.java | 8 +- .../common/packet/SPacketDimensionName.java | 4 +- .../src/common/packet/SPacketDisconnect.java | 2 +- .../src/common/packet/SPacketDisplayForm.java | 24 +- ...28PacketEffect.java => SPacketEffect.java} | 6 +- common/src/common/packet/SPacketEntity.java | 99 +++ ...tyAttach.java => SPacketEntityAttach.java} | 6 +- ...tyEffect.java => SPacketEntityEffect.java} | 22 +- .../common/packet/SPacketEntityEquipment.java | 8 +- ...adLook.java => SPacketEntityHeadLook.java} | 10 +- .../src/common/packet/SPacketEntityLook.java | 38 + .../common/packet/SPacketEntityLookMove.java | 47 ++ ...tadata.java => SPacketEntityMetadata.java} | 10 +- ...ties.java => SPacketEntityProperties.java} | 26 +- .../common/packet/SPacketEntityRelMove.java | 39 + ...tyStatus.java => SPacketEntityStatus.java} | 6 +- ...leport.java => SPacketEntityTeleport.java} | 12 +- .../common/packet/SPacketEntityVelocity.java | 4 +- ...etExplosion.java => SPacketExplosion.java} | 6 +- common/src/common/packet/SPacketJoinGame.java | 4 +- common/src/common/packet/SPacketLoading.java | 4 +- .../common/packet/SPacketMapChunkBulk.java | 12 +- common/src/common/packet/SPacketMessage.java | 2 +- .../packet/SPacketMultiBlockChange.java | 8 +- ...OpenWindow.java => SPacketOpenWindow.java} | 16 +- ...etParticles.java => SPacketParticles.java} | 10 +- ...ities.java => SPacketPlayerAbilities.java} | 6 +- ...stItem.java => SPacketPlayerListItem.java} | 16 +- ...ct.java => SPacketRemoveEntityEffect.java} | 10 +- common/src/common/packet/SPacketRespawn.java | 4 +- .../common/packet/SPacketSetExperience.java | 8 +- ...PacketSetSlot.java => SPacketSetSlot.java} | 10 +- ...orOpen.java => SPacketSignEditorOpen.java} | 6 +- common/src/common/packet/SPacketSkin.java | 4 +- ...undEffect.java => SPacketSoundEffect.java} | 6 +- ...ity.java => SPacketSpawnGlobalEntity.java} | 14 +- common/src/common/packet/SPacketSpawnMob.java | 4 +- .../src/common/packet/SPacketSpawnObject.java | 4 +- .../src/common/packet/SPacketSpawnPlayer.java | 4 +- ...bComplete.java => SPacketTabComplete.java} | 12 +- .../src/common/packet/SPacketTimeUpdate.java | 2 +- common/src/common/packet/SPacketTrades.java | 12 +- ...tyNBT.java => SPacketUpdateEntityNBT.java} | 14 +- ...UpdateSign.java => SPacketUpdateSign.java} | 8 +- ...tity.java => SPacketUpdateTileEntity.java} | 10 +- ...ndowItems.java => SPacketWindowItems.java} | 10 +- ...operty.java => SPacketWindowProperty.java} | 6 +- common/src/common/packet/SPacketWorld.java | 4 +- .../common/tileentity/TileEntityBanner.java | 4 +- .../common/tileentity/TileEntityBeacon.java | 4 +- .../common/tileentity/TileEntityMachine.java | 4 +- .../tileentity/TileEntityMobSpawner.java | 4 +- .../src/common/tileentity/TileEntitySign.java | 4 +- .../common/tileentity/TileEntitySkull.java | 4 +- server/src/server/Server.java | 34 +- server/src/server/network/Player.java | 118 ++- server/src/server/world/WorldServer.java | 42 +- 116 files changed, 1541 insertions(+), 2022 deletions(-) create mode 100755 common/src/common/network/CompressionDecoder.java create mode 100755 common/src/common/network/CompressionEncoder.java rename common/src/common/network/{NettyEncryptionDecoder.java => EncryptionDecoder.java} (50%) rename common/src/common/network/{NettyEncryptionEncoder.java => EncryptionEncoder.java} (50%) delete mode 100755 common/src/common/network/NettyCompressionDecoder.java delete mode 100755 common/src/common/network/NettyCompressionEncoder.java delete mode 100755 common/src/common/packet/CPacketBook.java create mode 100644 common/src/common/packet/CPacketPlayerLook.java create mode 100644 common/src/common/packet/CPacketPlayerPosLook.java create mode 100644 common/src/common/packet/CPacketPlayerPosition.java delete mode 100755 common/src/common/packet/S14PacketEntity.java rename common/src/common/packet/{S2BPacketChangeGameState.java => SPacketChangeGameState.java} (76%) rename common/src/common/packet/{S2EPacketCloseWindow.java => SPacketCloseWindow.java} (84%) rename common/src/common/packet/{S32PacketConfirmTransaction.java => SPacketConfirmTransaction.java} (86%) rename common/src/common/packet/{S28PacketEffect.java => SPacketEffect.java} (84%) create mode 100755 common/src/common/packet/SPacketEntity.java rename common/src/common/packet/{S1BPacketEntityAttach.java => SPacketEntityAttach.java} (88%) rename common/src/common/packet/{S1DPacketEntityEffect.java => SPacketEntityEffect.java} (77%) rename common/src/common/packet/{S19PacketEntityHeadLook.java => SPacketEntityHeadLook.java} (79%) create mode 100644 common/src/common/packet/SPacketEntityLook.java create mode 100644 common/src/common/packet/SPacketEntityLookMove.java rename common/src/common/packet/{S1CPacketEntityMetadata.java => SPacketEntityMetadata.java} (82%) rename common/src/common/packet/{S20PacketEntityProperties.java => SPacketEntityProperties.java} (72%) create mode 100644 common/src/common/packet/SPacketEntityRelMove.java rename common/src/common/packet/{S1APacketEntityStatus.java => SPacketEntityStatus.java} (87%) rename common/src/common/packet/{S18PacketEntityTeleport.java => SPacketEntityTeleport.java} (86%) rename common/src/common/packet/{S27PacketExplosion.java => SPacketExplosion.java} (93%) rename common/src/common/packet/{S2DPacketOpenWindow.java => SPacketOpenWindow.java} (79%) rename common/src/common/packet/{S2APacketParticles.java => SPacketParticles.java} (90%) rename common/src/common/packet/{S39PacketPlayerAbilities.java => SPacketPlayerAbilities.java} (84%) rename common/src/common/packet/{S38PacketPlayerListItem.java => SPacketPlayerListItem.java} (70%) rename common/src/common/packet/{S1EPacketRemoveEntityEffect.java => SPacketRemoveEntityEffect.java} (79%) rename common/src/common/packet/{S2FPacketSetSlot.java => SPacketSetSlot.java} (82%) rename common/src/common/packet/{S36PacketSignEditorOpen.java => SPacketSignEditorOpen.java} (85%) rename common/src/common/packet/{S29PacketSoundEffect.java => SPacketSoundEffect.java} (90%) rename common/src/common/packet/{S2CPacketSpawnGlobalEntity.java => SPacketSpawnGlobalEntity.java} (82%) rename common/src/common/packet/{S3APacketTabComplete.java => SPacketTabComplete.java} (74%) rename common/src/common/packet/{S43PacketUpdateEntityNBT.java => SPacketUpdateEntityNBT.java} (72%) rename common/src/common/packet/{S33PacketUpdateSign.java => SPacketUpdateSign.java} (88%) rename common/src/common/packet/{S35PacketUpdateTileEntity.java => SPacketUpdateTileEntity.java} (84%) rename common/src/common/packet/{S30PacketWindowItems.java => SPacketWindowItems.java} (84%) rename common/src/common/packet/{S31PacketWindowProperty.java => SPacketWindowProperty.java} (87%) diff --git a/client/src/client/network/ClientPlayer.java b/client/src/client/network/ClientPlayer.java index c972aea..167b8ae 100755 --- a/client/src/client/network/ClientPlayer.java +++ b/client/src/client/network/ClientPlayer.java @@ -63,37 +63,37 @@ import common.network.IClientPlayer; import common.network.NetConnection; import common.network.NetHandler; import common.network.Packet; +import common.packet.CPacketPlayerPosLook; import common.packet.CPacketAction; import common.packet.CPacketKeepAlive; -import common.packet.CPacketPlayer; -import common.packet.S14PacketEntity; -import common.packet.S18PacketEntityTeleport; -import common.packet.S19PacketEntityHeadLook; -import common.packet.S1APacketEntityStatus; -import common.packet.S1BPacketEntityAttach; -import common.packet.S1CPacketEntityMetadata; -import common.packet.S1DPacketEntityEffect; -import common.packet.S1EPacketRemoveEntityEffect; -import common.packet.S20PacketEntityProperties; -import common.packet.S27PacketExplosion; -import common.packet.S28PacketEffect; -import common.packet.S29PacketSoundEffect; -import common.packet.S2APacketParticles; -import common.packet.S2BPacketChangeGameState; -import common.packet.S2CPacketSpawnGlobalEntity; -import common.packet.S2DPacketOpenWindow; -import common.packet.S2EPacketCloseWindow; -import common.packet.S2FPacketSetSlot; -import common.packet.S30PacketWindowItems; -import common.packet.S31PacketWindowProperty; -import common.packet.S32PacketConfirmTransaction; -import common.packet.S33PacketUpdateSign; -import common.packet.S35PacketUpdateTileEntity; -import common.packet.S36PacketSignEditorOpen; -import common.packet.S38PacketPlayerListItem; -import common.packet.S39PacketPlayerAbilities; -import common.packet.S3APacketTabComplete; -import common.packet.S43PacketUpdateEntityNBT; +import common.packet.SPacketEntity; +import common.packet.SPacketEntityTeleport; +import common.packet.SPacketEntityHeadLook; +import common.packet.SPacketEntityStatus; +import common.packet.SPacketEntityAttach; +import common.packet.SPacketEntityMetadata; +import common.packet.SPacketEntityEffect; +import common.packet.SPacketRemoveEntityEffect; +import common.packet.SPacketEntityProperties; +import common.packet.SPacketExplosion; +import common.packet.SPacketEffect; +import common.packet.SPacketSoundEffect; +import common.packet.SPacketParticles; +import common.packet.SPacketChangeGameState; +import common.packet.SPacketSpawnGlobalEntity; +import common.packet.SPacketOpenWindow; +import common.packet.SPacketCloseWindow; +import common.packet.SPacketSetSlot; +import common.packet.SPacketWindowItems; +import common.packet.SPacketWindowProperty; +import common.packet.SPacketConfirmTransaction; +import common.packet.SPacketUpdateSign; +import common.packet.SPacketUpdateTileEntity; +import common.packet.SPacketSignEditorOpen; +import common.packet.SPacketPlayerListItem; +import common.packet.SPacketPlayerAbilities; +import common.packet.SPacketTabComplete; +import common.packet.SPacketUpdateEntityNBT; import common.packet.SPacketAnimation; import common.packet.SPacketBiome; import common.packet.SPacketBlockAction; @@ -452,7 +452,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Handles globally visible entities. Used in vanilla for lightning bolts */ - public void handleSpawnGlobalEntity(S2CPacketSpawnGlobalEntity packetIn) + public void handleSpawnGlobalEntity(SPacketSpawnGlobalEntity packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); double d0 = (double)packetIn.getEncodedX() / 32.0D; @@ -505,7 +505,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * Invoked when the server registers new proximate objects in your watchlist or when objects in your watchlist have * changed -> Registers any changes locally */ - public void handleEntityMetadata(S1CPacketEntityMetadata packetIn) + public void handleEntityMetadata(SPacketEntityMetadata packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); @@ -562,7 +562,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Updates an entity's position and rotation as specified by the packet */ - public void handleEntityTeleport(S18PacketEntityTeleport packetIn) + public void handleEntityTeleport(SPacketEntityTeleport packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); @@ -609,7 +609,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * subclassing of the packet allows for the specification of a subset of this data (e.g. only rel. position, abs. * rotation or both). */ - public void handleEntityMovement(S14PacketEntity packetIn) + public void handleEntityMovement(SPacketEntity packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = packetIn.getEntity(this.clientWorldController); @@ -633,7 +633,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * Updates the direction in which the specified entity is looking, normally this head rotation is independent of the * rotation of the entity itself */ - public void handleEntityHeadLook(S19PacketEntityHeadLook packetIn) + public void handleEntityHeadLook(SPacketEntityHeadLook packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = packetIn.getEntity(this.clientWorldController); @@ -714,7 +714,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer } entityplayer.setPositionAndRotation(d0, d1, d2, f, f1); - this.netManager.sendPacket(new CPacketPlayer.C06PacketPlayerPosLook(entityplayer.posX, entityplayer.getEntityBoundingBox().minY, entityplayer.posZ, entityplayer.rotYaw, entityplayer.rotPitch, false)); + this.netManager.sendPacket(new CPacketPlayerPosLook(entityplayer.posX, entityplayer.getEntityBoundingBox().minY, entityplayer.posZ, entityplayer.rotYaw, entityplayer.rotPitch, false)); if (!this.doneLoadingTerrain) { @@ -1008,7 +1008,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer // this.gameController.thePlayer.setSpawnPoint(packetIn.getSpawnPos(), true); // } - public void handleEntityAttach(S1BPacketEntityAttach packetIn) + public void handleEntityAttach(SPacketEntityAttach packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); @@ -1065,7 +1065,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * (spawn particles), Zombie (villager transformation), Animal (breeding mode particles), Horse (breeding/smoke * particles), Sheep (...), Tameable (...), Villager (particles for breeding mode, angry and happy), Wolf (...) */ - public void handleEntityStatus(S1APacketEntityStatus packetIn) + public void handleEntityStatus(SPacketEntityStatus packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = packetIn.getEntity(this.clientWorldController); @@ -1127,7 +1127,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Initiates a new explosion (sound, particles, drop spawn) for the affected blocks indicated by the packet. */ - public void handleExplosion(S27PacketExplosion packetIn) + public void handleExplosion(SPacketExplosion packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Explosion explosion = new Explosion(this.gameController.world, (Entity)null, packetIn.getX(), packetIn.getY(), packetIn.getZ(), packetIn.getStrength(), packetIn.getAffectedBlockPositions()); @@ -1141,7 +1141,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * Displays a GUI by ID. In order starting from id 0: Chest, Workbench, Furnace, Dispenser, Enchanting table, * Brewing stand, Villager merchant, Beacon, Anvil, Hopper, Dropper, Horse */ - public void handleOpenWindow(S2DPacketOpenWindow packetIn) + public void handleOpenWindow(SPacketOpenWindow packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); EntityNPC entityplayersp = this.gameController.player; @@ -1190,7 +1190,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Handles pickin up an ItemStack or dropping one in your inventory or an open container */ - public void handleSetSlot(S2FPacketSetSlot packetIn) + public void handleSetSlot(SPacketSetSlot packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); EntityNPC entityplayer = this.gameController.player; @@ -1231,7 +1231,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * Verifies that the server and client are synchronized with respect to the inventory/container opened by the player * and confirms if it is the case. */ - public void handleConfirmTransaction(S32PacketConfirmTransaction packetIn) + public void handleConfirmTransaction(SPacketConfirmTransaction packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Container container = null; @@ -1255,7 +1255,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Handles the placement of a specified ItemStack in a specified container/inventory slot */ - public void handleWindowItems(S30PacketWindowItems packetIn) + public void handleWindowItems(SPacketWindowItems packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); EntityNPC entityplayer = this.gameController.player; @@ -1273,7 +1273,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Creates a sign in the specified location if it didn't exist and opens the GUI to edit its text */ - public void handleSignEditorOpen(S36PacketSignEditorOpen packetIn) + public void handleSignEditorOpen(SPacketSignEditorOpen packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); TileEntity tileentity = this.clientWorldController.getTileEntity(packetIn.getSignPosition()); @@ -1296,7 +1296,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Updates a specified sign with the specified text lines */ - public void handleUpdateSign(S33PacketUpdateSign packetIn) + public void handleUpdateSign(SPacketUpdateSign packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); // boolean flag = false; @@ -1331,7 +1331,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * Updates the NBTTagCompound metadata of instances of the following entitytypes: Mob spawners, command blocks, * beacons, skulls, flowerpot */ - public void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn) + public void handleUpdateTileEntity(SPacketUpdateTileEntity packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); @@ -1350,7 +1350,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Sets the progressbar of the opened window to the specified value */ - public void handleWindowProperty(S31PacketWindowProperty packetIn) + public void handleWindowProperty(SPacketWindowProperty packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); EntityNPC entityplayer = this.gameController.player; @@ -1375,7 +1375,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Resets the ItemStack held in hand and closes the window that is opened */ - public void handleCloseWindow(S2EPacketCloseWindow packetIn) + public void handleCloseWindow(SPacketCloseWindow packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); // this.gameController.thePlayer.closeScreenAndDropStack(); @@ -1423,7 +1423,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer } } - public void handleChangeGameState(S2BPacketChangeGameState packetIn) + public void handleChangeGameState(SPacketChangeGameState packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); switch(packetIn.getAction()) { @@ -1448,7 +1448,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer } } - public void handleEffect(S28PacketEffect packetIn) + public void handleEffect(SPacketEffect packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); @@ -1513,7 +1513,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer // } // } - public void handleEntityEffect(S1DPacketEntityEffect packetIn) + public void handleEntityEffect(SPacketEntityEffect packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); @@ -1590,7 +1590,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer //// } // } - public void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn) + public void handleRemoveEntityEffect(SPacketRemoveEntityEffect packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); @@ -1602,7 +1602,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer } - public void handlePlayerListItem(S38PacketPlayerListItem packetIn) + public void handlePlayerListItem(SPacketPlayerListItem packetIn) { NetHandler.checkThread(packetIn, this, this.gameController); @@ -1649,7 +1649,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer this.addToSendQueue(new CPacketKeepAlive(packetIn.getValue())); } - public void handlePlayerAbilities(S39PacketPlayerAbilities packetIn) + public void handlePlayerAbilities(SPacketPlayerAbilities packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); EntityNPC entityplayer = this.gameController.player; @@ -1662,7 +1662,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer /** * Displays the available command-completion options the server knows of */ - public void handleTabComplete(S3APacketTabComplete packetIn) + public void handleTabComplete(SPacketTabComplete packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); String[] astring = packetIn.func_149630_c(); @@ -1674,7 +1674,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer } } - public void handleSoundEffect(S29PacketSoundEffect packetIn) + public void handleSoundEffect(SPacketSoundEffect packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); if(packetIn.getSound() == null) { @@ -1711,7 +1711,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer //// } // } - public void handleEntityNBT(S43PacketUpdateEntityNBT packetIn) + public void handleEntityNBT(SPacketUpdateEntityNBT packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = packetIn.getEntity(this.clientWorldController); @@ -1835,7 +1835,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * Spawns a specified number of particles at the specified location with a randomized displacement according to * specified bounds */ - public void handleParticles(S2APacketParticles packetIn) + public void handleParticles(SPacketParticles packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); @@ -1885,7 +1885,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer * sprinting, animals fleeing, baby speed), weapon/tool attackDamage, hostiles followRange randomization, zombie * maxHealth and knockback resistance as well as reinforcement spawning chance. */ - public void handleEntityProperties(S20PacketEntityProperties packetIn) + public void handleEntityProperties(SPacketEntityProperties packetIn) { NetHandler.checkThread(packetIn, this, this.gameController, this.clientWorldController); Entity entity = this.clientWorldController.getEntityByID(packetIn.getEntityId()); @@ -1900,7 +1900,7 @@ public class ClientPlayer extends NetHandler implements IClientPlayer { AttributeMap baseattributemap = ((EntityLiving)entity).getAttributeMap(); - for (S20PacketEntityProperties.Snapshot s20packetentityproperties$snapshot : packetIn.func_149441_d()) + for (SPacketEntityProperties.Snapshot s20packetentityproperties$snapshot : packetIn.func_149441_d()) { AttributeInstance iattributeinstance = baseattributemap.getAttributeInstanceByName(s20packetentityproperties$snapshot.func_151409_a()); diff --git a/common/src/common/block/BlockChest.java b/common/src/common/block/BlockChest.java index 7366655..9b2ed6b 100755 --- a/common/src/common/block/BlockChest.java +++ b/common/src/common/block/BlockChest.java @@ -15,7 +15,7 @@ import common.inventory.InventoryLargeChest; import common.item.CheatTab; import common.item.ItemStack; import common.material.Material; -import common.packet.S29PacketSoundEffect; +import common.packet.SPacketSoundEffect; import common.properties.IProperty; import common.properties.PropertyDirection; import common.tileentity.ILockableContainer; @@ -448,7 +448,7 @@ public class BlockChest extends BlockContainer ilockablecontainer.setLockCode(LockCode.EMPTY_CODE); // playerIn.triggerAchievement(StatRegistry.chestUnlockedStat); playerIn.connection.addHotbar(TextColor.BLUE + "%s wurde entriegelt", ilockablecontainer.getCommandName()); - playerIn.connection.sendPacket(new S29PacketSoundEffect(SoundEvent.DOOR, playerIn.posX, playerIn.posY, playerIn.posZ, 1.0F)); + playerIn.connection.sendPacket(new SPacketSoundEffect(SoundEvent.DOOR, playerIn.posX, playerIn.posY, playerIn.posZ, 1.0F)); return true; } } @@ -456,7 +456,7 @@ public class BlockChest extends BlockContainer ilockablecontainer.setLockCode(new LockCode(stack.getDisplayName())); // playerIn.triggerAchievement(StatRegistry.chestLockedStat); playerIn.connection.addHotbar(TextColor.ORANGE + "%s wurde verriegelt", ilockablecontainer.getCommandName()); - playerIn.connection.sendPacket(new S29PacketSoundEffect(SoundEvent.DOOR, playerIn.posX, playerIn.posY, playerIn.posZ, 1.0F)); + playerIn.connection.sendPacket(new SPacketSoundEffect(SoundEvent.DOOR, playerIn.posX, playerIn.posY, playerIn.posZ, 1.0F)); return true; } } diff --git a/common/src/common/entity/DataWatcher.java b/common/src/common/entity/DataWatcher.java index e4b9a7e..222676a 100755 --- a/common/src/common/entity/DataWatcher.java +++ b/common/src/common/entity/DataWatcher.java @@ -202,7 +202,7 @@ public class DataWatcher { case 5: ItemStack itemstack = (ItemStack)object.getObject(); - buffer.writeItemStackToBuffer(itemstack); + buffer.writeItemStack(itemstack); break; case 6: @@ -250,11 +250,11 @@ public class DataWatcher { break; case 4: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readStringFromBuffer(32767)); + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readString(32767)); break; case 5: - datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readItemStackFromBuffer()); + datawatcher$watchableobject = new DataWatcher.WatchableObject(j, k, buffer.readItemStack()); break; case 6: diff --git a/common/src/common/entity/EntityTrackerEntry.java b/common/src/common/entity/EntityTrackerEntry.java index 9b3a96f..fdcfcb0 100755 --- a/common/src/common/entity/EntityTrackerEntry.java +++ b/common/src/common/entity/EntityTrackerEntry.java @@ -14,14 +14,16 @@ import common.item.ItemStack; import common.log.Log; import common.nbt.NBTTagCompound; import common.network.Packet; -import common.packet.S14PacketEntity; -import common.packet.S18PacketEntityTeleport; -import common.packet.S19PacketEntityHeadLook; -import common.packet.S1BPacketEntityAttach; -import common.packet.S1CPacketEntityMetadata; -import common.packet.S1DPacketEntityEffect; -import common.packet.S20PacketEntityProperties; -import common.packet.S43PacketUpdateEntityNBT; +import common.packet.SPacketEntityRelMove; +import common.packet.SPacketEntityLook; +import common.packet.SPacketEntityLookMove; +import common.packet.SPacketEntityTeleport; +import common.packet.SPacketEntityHeadLook; +import common.packet.SPacketEntityAttach; +import common.packet.SPacketEntityMetadata; +import common.packet.SPacketEntityEffect; +import common.packet.SPacketEntityProperties; +import common.packet.SPacketUpdateEntityNBT; import common.packet.SPacketEntityEquipment; import common.packet.SPacketEntityVelocity; import common.packet.SPacketSpawnMob; @@ -96,7 +98,7 @@ public class EntityTrackerEntry { if(this.lastRiding != this.trackedEntity.vehicle || this.trackedEntity.vehicle != null && this.updateCounter % 60 == 0) { this.lastRiding = this.trackedEntity.vehicle; - this.sendPacketToTrackedPlayers(new S1BPacketEntityAttach(0, this.trackedEntity, this.trackedEntity.vehicle)); + this.sendPacketToTrackedPlayers(new SPacketEntityAttach(0, this.trackedEntity, this.trackedEntity.vehicle)); } // if(this.trackedEntity instanceof EntityFrame && this.updateCounter % 10 == 0) { @@ -141,23 +143,23 @@ public class EntityTrackerEntry { && !this.ridingEntity && this.onGround == this.trackedEntity.onGround) { if((!flag || !flag1) && !(this.trackedEntity instanceof EntityArrow)) { if(flag) { - packet1 = new S14PacketEntity.S15PacketEntityRelMove(this.trackedEntity.getId(), (byte)j2, (byte)k2, (byte)i, + packet1 = new SPacketEntityRelMove(this.trackedEntity.getId(), (byte)j2, (byte)k2, (byte)i, this.trackedEntity.onGround); } else if(flag1) { - packet1 = new S14PacketEntity.S16PacketEntityLook(this.trackedEntity.getId(), (byte)l1, (byte)i2, + packet1 = new SPacketEntityLook(this.trackedEntity.getId(), (byte)l1, (byte)i2, this.trackedEntity.onGround); } } else { - packet1 = new S14PacketEntity.S17PacketEntityLookMove(this.trackedEntity.getId(), (byte)j2, (byte)k2, (byte)i, + packet1 = new SPacketEntityLookMove(this.trackedEntity.getId(), (byte)j2, (byte)k2, (byte)i, (byte)l1, (byte)i2, this.trackedEntity.onGround); } } else { this.onGround = this.trackedEntity.onGround; this.ticksSinceLastForcedTeleport = 0; - packet1 = new S18PacketEntityTeleport(this.trackedEntity.getId(), k, j1, k1, (byte)l1, (byte)i2, + packet1 = new SPacketEntityTeleport(this.trackedEntity.getId(), k, j1, k1, (byte)l1, (byte)i2, this.trackedEntity.onGround); } } @@ -204,7 +206,7 @@ public class EntityTrackerEntry { boolean flag2 = Math.abs(j - this.encodedRotationYaw) >= 4 || Math.abs(i1 - this.encodedRotationPitch) >= 4; if(flag2) { - this.sendPacketToTrackedPlayers(new S14PacketEntity.S16PacketEntityLook(this.trackedEntity.getId(), (byte)j, (byte)i1, + this.sendPacketToTrackedPlayers(new SPacketEntityLook(this.trackedEntity.getId(), (byte)j, (byte)i1, this.trackedEntity.onGround)); this.encodedRotationYaw = j; this.encodedRotationPitch = i1; @@ -220,7 +222,7 @@ public class EntityTrackerEntry { int l = ExtMath.floorf(this.trackedEntity.getRotationYawHead() * 256.0F / 360.0F); if(Math.abs(l - this.lastHeadMotion) >= 4) { - this.sendPacketToTrackedPlayers(new S19PacketEntityHeadLook(this.trackedEntity, (byte)l)); + this.sendPacketToTrackedPlayers(new SPacketEntityHeadLook(this.trackedEntity, (byte)l)); this.lastHeadMotion = l; } @@ -239,7 +241,7 @@ public class EntityTrackerEntry { DataWatcher datawatcher = this.trackedEntity.getDataWatcher(); if(datawatcher.hasObjectChanged()) { - this.sendPacketToTrackedAndSelf(new S1CPacketEntityMetadata(this.trackedEntity.getId(), datawatcher, false)); + this.sendPacketToTrackedAndSelf(new SPacketEntityMetadata(this.trackedEntity.getId(), datawatcher, false)); } if(this.trackedEntity instanceof EntityLiving) { @@ -247,7 +249,7 @@ public class EntityTrackerEntry { Set set = serversideattributemap.getDirty(); if(!set.isEmpty()) { - this.sendPacketToTrackedAndSelf(new S20PacketEntityProperties(this.trackedEntity.getId(), set)); + this.sendPacketToTrackedAndSelf(new SPacketEntityProperties(this.trackedEntity.getId(), set)); } set.clear(); @@ -291,13 +293,13 @@ public class EntityTrackerEntry { if(!this.trackedEntity.getDataWatcher().isBlank()) { playerMP.connection - .sendPacket(new S1CPacketEntityMetadata(this.trackedEntity.getId(), this.trackedEntity.getDataWatcher(), true)); + .sendPacket(new SPacketEntityMetadata(this.trackedEntity.getId(), this.trackedEntity.getDataWatcher(), true)); } NBTTagCompound nbttagcompound = this.trackedEntity.getNBTTagCompound(); if(nbttagcompound != null) { - playerMP.connection.sendPacket(new S43PacketUpdateEntityNBT(this.trackedEntity.getId(), nbttagcompound)); + playerMP.connection.sendPacket(new SPacketUpdateEntityNBT(this.trackedEntity.getId(), nbttagcompound)); } if(this.trackedEntity instanceof EntityLiving) { @@ -305,7 +307,7 @@ public class EntityTrackerEntry { Collection collection = serversideattributemap.getWatchedAttributes(); if(!collection.isEmpty()) { - playerMP.connection.sendPacket(new S20PacketEntityProperties(this.trackedEntity.getId(), collection)); + playerMP.connection.sendPacket(new SPacketEntityProperties(this.trackedEntity.getId(), collection)); } } @@ -322,12 +324,12 @@ public class EntityTrackerEntry { } if(this.trackedEntity.vehicle != null) { - playerMP.connection.sendPacket(new S1BPacketEntityAttach(0, this.trackedEntity, this.trackedEntity.vehicle)); + playerMP.connection.sendPacket(new SPacketEntityAttach(0, this.trackedEntity, this.trackedEntity.vehicle)); } if(this.trackedEntity instanceof EntityLiving && ((EntityLiving)this.trackedEntity).getLeashedTo() != null) { playerMP.connection.sendPacket( - new S1BPacketEntityAttach(1, this.trackedEntity, ((EntityLiving)this.trackedEntity).getLeashedTo())); + new SPacketEntityAttach(1, this.trackedEntity, ((EntityLiving)this.trackedEntity).getLeashedTo())); } if(this.trackedEntity instanceof EntityLiving) { @@ -353,7 +355,7 @@ public class EntityTrackerEntry { EntityLiving entitylivingbase = (EntityLiving)this.trackedEntity; for(PotionEffect potioneffect : entitylivingbase.getEffects()) { - playerMP.connection.sendPacket(new S1DPacketEntityEffect(this.trackedEntity.getId(), potioneffect)); + playerMP.connection.sendPacket(new SPacketEntityEffect(this.trackedEntity.getId(), potioneffect)); } } } diff --git a/common/src/common/entity/npc/EntityNPC.java b/common/src/common/entity/npc/EntityNPC.java index a7c9cca..bc3c447 100755 --- a/common/src/common/entity/npc/EntityNPC.java +++ b/common/src/common/entity/npc/EntityNPC.java @@ -71,6 +71,9 @@ import common.nbt.NBTTagCompound; import common.nbt.NBTTagList; import common.network.IClientPlayer; import common.network.IPlayer; +import common.packet.CPacketPlayerPosition; +import common.packet.CPacketPlayerLook; +import common.packet.CPacketPlayerPosLook; import common.packet.CPacketAction; import common.packet.CPacketBreak; import common.packet.CPacketInput; @@ -1799,7 +1802,7 @@ public abstract class EntityNPC extends EntityLiving if (this.isRiding()) { - this.client.addToSendQueue(new CPacketPlayer.C05PacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); + this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); this.client.addToSendQueue(new CPacketInput(this.moveStrafe, this.moveForward, this.client.isJumping(), this.client.isSneaking())); } else @@ -2667,15 +2670,15 @@ public abstract class EntityNPC extends EntityLiving { if (flag2 && flag3) { - this.client.addToSendQueue(new CPacketPlayer.C06PacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotYaw, this.rotPitch, this.onGround)); + this.client.addToSendQueue(new CPacketPlayerPosLook(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.rotYaw, this.rotPitch, this.onGround)); } else if (flag2) { - this.client.addToSendQueue(new CPacketPlayer.C04PacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround)); + this.client.addToSendQueue(new CPacketPlayerPosition(this.posX, this.getEntityBoundingBox().minY, this.posZ, this.onGround)); } else if (flag3) { - this.client.addToSendQueue(new CPacketPlayer.C05PacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); + this.client.addToSendQueue(new CPacketPlayerLook(this.rotYaw, this.rotPitch, this.onGround)); } else { @@ -2684,7 +2687,7 @@ public abstract class EntityNPC extends EntityLiving } else { - this.client.addToSendQueue(new CPacketPlayer.C06PacketPlayerPosLook(this.motionX, -99999999.0D, this.motionZ, this.rotYaw, this.rotPitch, this.onGround)); + this.client.addToSendQueue(new CPacketPlayerPosLook(this.motionX, -99999999.0D, this.motionZ, this.rotYaw, this.rotPitch, this.onGround)); flag2 = false; } diff --git a/common/src/common/entity/types/EntityLiving.java b/common/src/common/entity/types/EntityLiving.java index e247346..4ec9250 100755 --- a/common/src/common/entity/types/EntityLiving.java +++ b/common/src/common/entity/types/EntityLiving.java @@ -51,7 +51,7 @@ import common.model.ParticleType; import common.nbt.NBTTagCompound; import common.nbt.NBTTagList; import common.network.IPlayer; -import common.packet.S1BPacketEntityAttach; +import common.packet.SPacketEntityAttach; import common.packet.SPacketAnimation; import common.packet.SPacketCollectItem; import common.pathfinding.PathNavigate; @@ -3094,7 +3094,7 @@ public abstract class EntityLiving extends Entity } if(!this.worldObj.client && pkt && this.worldObj instanceof AWorldServer) { - ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new S1BPacketEntityAttach(1, this, (Entity)null)); + ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityAttach(1, this, (Entity)null)); } } } @@ -3116,7 +3116,7 @@ public abstract class EntityLiving extends Entity this.leashedTo = entity; if(!this.worldObj.client && pkt && this.worldObj instanceof AWorldServer) { - ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new S1BPacketEntityAttach(1, this, this.leashedTo)); + ((AWorldServer)this.worldObj).sendToAllTrackingEntity(this, new SPacketEntityAttach(1, this, this.leashedTo)); } } diff --git a/common/src/common/item/Item.java b/common/src/common/item/Item.java index f968ee9..b144b84 100755 --- a/common/src/common/item/Item.java +++ b/common/src/common/item/Item.java @@ -231,14 +231,6 @@ public class Item return this.display; } - /** - * If this function returns true (or the item is damageable), the ItemStack's NBT tag will be sent to the client. - */ - public boolean getShareTag() - { - return true; - } - public Item getContainerItem() { return this.containerItem; diff --git a/common/src/common/network/CompressionDecoder.java b/common/src/common/network/CompressionDecoder.java new file mode 100755 index 0000000..e681218 --- /dev/null +++ b/common/src/common/network/CompressionDecoder.java @@ -0,0 +1,47 @@ +package common.network; + +import java.util.List; +import java.util.zip.DataFormatException; +import java.util.zip.Inflater; + +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; +import io.netty.handler.codec.DecoderException; + +public class CompressionDecoder extends ByteToMessageDecoder { + private final Inflater inflater; + private int treshold; + + public CompressionDecoder(int treshold) { + this.treshold = treshold; + this.inflater = new Inflater(); + } + + protected void decode(ChannelHandlerContext context, ByteBuf buffer, List output) throws DataFormatException, Exception { + if(buffer.readableBytes() == 0) + return; + PacketBuffer pbuf = new PacketBuffer(buffer); + int len = pbuf.readVarInt(); + if(len == 0) { + output.add(pbuf.readBytes(pbuf.readableBytes())); + return; + } + if(len < this.treshold) + throw new DecoderException("Badly compressed packet - size of " + len + " is below server threshold of " + this.treshold); + if(len > 2097152) + throw new DecoderException("Badly compressed packet - size of " + len + " is larger than protocol maximum of " + 2097152); + byte[] comp = new byte[pbuf.readableBytes()]; + pbuf.readBytes(comp); + this.inflater.setInput(comp); + byte[] data = new byte[len]; + this.inflater.inflate(data); + output.add(Unpooled.wrappedBuffer(data)); + this.inflater.reset(); + } + + public void setTreshold(int treshold) { + this.treshold = treshold; + } +} diff --git a/common/src/common/network/CompressionEncoder.java b/common/src/common/network/CompressionEncoder.java new file mode 100755 index 0000000..8d975f2 --- /dev/null +++ b/common/src/common/network/CompressionEncoder.java @@ -0,0 +1,42 @@ +package common.network; + +import java.util.zip.Deflater; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +public class CompressionEncoder extends MessageToByteEncoder { + private final byte[] buffer = new byte[8192]; + private final Deflater deflater; + private int treshold; + + public CompressionEncoder(int treshold) { + this.treshold = treshold; + this.deflater = new Deflater(); + } + + protected void encode(ChannelHandlerContext context, ByteBuf buffer, ByteBuf output) throws Exception { + int len = buffer.readableBytes(); + PacketBuffer pbuf = new PacketBuffer(output); + if(len < this.treshold) { + pbuf.writeVarInt(0); + pbuf.writeBuffer(buffer); + return; + } + byte[] data = new byte[len]; + buffer.readBytes(data); + pbuf.writeVarInt(data.length); + this.deflater.setInput(data, 0, len); + this.deflater.finish(); + while(!this.deflater.finished()) { + int size = this.deflater.deflate(this.buffer); + pbuf.writeBytes(this.buffer, 0, size); + } + this.deflater.reset(); + } + + public void setTreshold(int treshold) { + this.treshold = treshold; + } +} diff --git a/common/src/common/network/NettyEncryptionDecoder.java b/common/src/common/network/EncryptionDecoder.java similarity index 50% rename from common/src/common/network/NettyEncryptionDecoder.java rename to common/src/common/network/EncryptionDecoder.java index dac5156..244773b 100644 --- a/common/src/common/network/NettyEncryptionDecoder.java +++ b/common/src/common/network/EncryptionDecoder.java @@ -7,14 +7,14 @@ import java.util.List; import javax.crypto.Cipher; import javax.crypto.ShortBufferException; -public class NettyEncryptionDecoder extends MessageToMessageDecoder { +public class EncryptionDecoder extends MessageToMessageDecoder { private final EncryptionCodec codec; - public NettyEncryptionDecoder(Cipher cipher) { + public EncryptionDecoder(Cipher cipher) { this.codec = new EncryptionCodec(cipher); } - protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws ShortBufferException, Exception { - p_decode_3_.add(this.codec.decipher(p_decode_1_, p_decode_2_)); + protected void decode(ChannelHandlerContext context, ByteBuf buffer, List output) throws ShortBufferException, Exception { + output.add(this.codec.decipher(context, buffer)); } } diff --git a/common/src/common/network/NettyEncryptionEncoder.java b/common/src/common/network/EncryptionEncoder.java similarity index 50% rename from common/src/common/network/NettyEncryptionEncoder.java rename to common/src/common/network/EncryptionEncoder.java index 0ec56f2..abfa860 100644 --- a/common/src/common/network/NettyEncryptionEncoder.java +++ b/common/src/common/network/EncryptionEncoder.java @@ -6,14 +6,14 @@ import io.netty.handler.codec.MessageToByteEncoder; import javax.crypto.Cipher; import javax.crypto.ShortBufferException; -public class NettyEncryptionEncoder extends MessageToByteEncoder { +public class EncryptionEncoder extends MessageToByteEncoder { private final EncryptionCodec codec; - public NettyEncryptionEncoder(Cipher cipher) { + public EncryptionEncoder(Cipher cipher) { this.codec = new EncryptionCodec(cipher); } - protected void encode(ChannelHandlerContext p_encode_1_, ByteBuf p_encode_2_, ByteBuf p_encode_3_) throws ShortBufferException, Exception { - this.codec.cipher(p_encode_2_, p_encode_3_); + protected void encode(ChannelHandlerContext context, ByteBuf buffer, ByteBuf output) throws ShortBufferException, Exception { + this.codec.cipher(buffer, output); } } diff --git a/common/src/common/network/IClientLoginHandler.java b/common/src/common/network/IClientLoginHandler.java index b2606e1..8f6de83 100644 --- a/common/src/common/network/IClientLoginHandler.java +++ b/common/src/common/network/IClientLoginHandler.java @@ -6,13 +6,8 @@ import common.packet.RPacketLoginSuccess; import common.packet.RPacketRequestEncrypt; public interface IClientLoginHandler { - - void handleDisconnect(RPacketDisconnect packetIn); - - void handleLoginSuccess(RPacketLoginSuccess packetIn); - - void handleEnableCompression(RPacketEnableCompression packetIn); - + void handleDisconnect(RPacketDisconnect packet); + void handleLoginSuccess(RPacketLoginSuccess packet); + void handleEnableCompression(RPacketEnableCompression packet); void handleEncrypt(RPacketRequestEncrypt packet); - -} \ No newline at end of file +} diff --git a/common/src/common/network/IClientPlayer.java b/common/src/common/network/IClientPlayer.java index 292929b..7884c94 100644 --- a/common/src/common/network/IClientPlayer.java +++ b/common/src/common/network/IClientPlayer.java @@ -5,34 +5,34 @@ import common.entity.animal.EntityHorse; import common.inventory.IInventory; import common.inventory.InventoryPlayer; import common.model.ParticleType; -import common.packet.S14PacketEntity; -import common.packet.S18PacketEntityTeleport; -import common.packet.S19PacketEntityHeadLook; -import common.packet.S1APacketEntityStatus; -import common.packet.S1BPacketEntityAttach; -import common.packet.S1CPacketEntityMetadata; -import common.packet.S1DPacketEntityEffect; -import common.packet.S1EPacketRemoveEntityEffect; -import common.packet.S20PacketEntityProperties; -import common.packet.S27PacketExplosion; -import common.packet.S28PacketEffect; -import common.packet.S29PacketSoundEffect; -import common.packet.S2APacketParticles; -import common.packet.S2BPacketChangeGameState; -import common.packet.S2CPacketSpawnGlobalEntity; -import common.packet.S2DPacketOpenWindow; -import common.packet.S2EPacketCloseWindow; -import common.packet.S2FPacketSetSlot; -import common.packet.S30PacketWindowItems; -import common.packet.S31PacketWindowProperty; -import common.packet.S32PacketConfirmTransaction; -import common.packet.S33PacketUpdateSign; -import common.packet.S35PacketUpdateTileEntity; -import common.packet.S36PacketSignEditorOpen; -import common.packet.S38PacketPlayerListItem; -import common.packet.S39PacketPlayerAbilities; -import common.packet.S3APacketTabComplete; -import common.packet.S43PacketUpdateEntityNBT; +import common.packet.SPacketEntity; +import common.packet.SPacketEntityTeleport; +import common.packet.SPacketEntityHeadLook; +import common.packet.SPacketEntityStatus; +import common.packet.SPacketEntityAttach; +import common.packet.SPacketEntityMetadata; +import common.packet.SPacketEntityEffect; +import common.packet.SPacketRemoveEntityEffect; +import common.packet.SPacketEntityProperties; +import common.packet.SPacketExplosion; +import common.packet.SPacketEffect; +import common.packet.SPacketSoundEffect; +import common.packet.SPacketParticles; +import common.packet.SPacketChangeGameState; +import common.packet.SPacketSpawnGlobalEntity; +import common.packet.SPacketOpenWindow; +import common.packet.SPacketCloseWindow; +import common.packet.SPacketSetSlot; +import common.packet.SPacketWindowItems; +import common.packet.SPacketWindowProperty; +import common.packet.SPacketConfirmTransaction; +import common.packet.SPacketUpdateSign; +import common.packet.SPacketUpdateTileEntity; +import common.packet.SPacketSignEditorOpen; +import common.packet.SPacketPlayerListItem; +import common.packet.SPacketPlayerAbilities; +import common.packet.SPacketTabComplete; +import common.packet.SPacketUpdateEntityNBT; import common.packet.SPacketAnimation; import common.packet.SPacketBiome; import common.packet.SPacketBlockAction; @@ -76,7 +76,7 @@ public interface IClientPlayer { void playSound(Sound sound); boolean isRenderViewEntity(Entity entity); void updatePlayerMoveState(); - void emitParticleAtEntity(Entity entityIn, ParticleType particleTypes); + void emitParticleAtEntity(Entity entity, ParticleType particleTypes); boolean isJumping(); boolean isSprinting(); boolean isSneaking(); @@ -86,73 +86,73 @@ public interface IClientPlayer { void setMoveStrafe(float value); void addToSendQueue(Packet packet); - void handleJoinGame(SPacketJoinGame packetIn); - void handleSpawnObject(SPacketSpawnObject packetIn); - void handleSpawnGlobalEntity(S2CPacketSpawnGlobalEntity packetIn); - void handleEntityVelocity(SPacketEntityVelocity packetIn); - void handleEntityMetadata(S1CPacketEntityMetadata packetIn); - void handleSpawnPlayer(SPacketSpawnPlayer packetIn); - void handleEntityTeleport(S18PacketEntityTeleport packetIn); - void handleHeldItemChange(SPacketHeldItemChange packetIn); - void handleEntityMovement(S14PacketEntity packetIn); - void handleEntityHeadLook(S19PacketEntityHeadLook packetIn); - void handleDestroyEntities(SPacketDestroyEntities packetIn); - void handlePlayerPosLook(SPacketPlayerPosLook packetIn); - void handleMultiBlockChange(SPacketMultiBlockChange packetIn); - void handleChunkData(SPacketChunkData packetIn); - void handleBiomes(SPacketBiome packetIn); - void handleBlockChange(SPacketBlockChange packetIn); - void handleDisconnect(SPacketDisconnect packetIn); - void handleCollectItem(SPacketCollectItem packetIn); - void handleMessage(SPacketMessage packetIn); + void handleJoinGame(SPacketJoinGame packet); + void handleSpawnObject(SPacketSpawnObject packet); + void handleSpawnGlobalEntity(SPacketSpawnGlobalEntity packet); + void handleEntityVelocity(SPacketEntityVelocity packet); + void handleEntityMetadata(SPacketEntityMetadata packet); + void handleSpawnPlayer(SPacketSpawnPlayer packet); + void handleEntityTeleport(SPacketEntityTeleport packet); + void handleHeldItemChange(SPacketHeldItemChange packet); + void handleEntityMovement(SPacketEntity packet); + void handleEntityHeadLook(SPacketEntityHeadLook packet); + void handleDestroyEntities(SPacketDestroyEntities packet); + void handlePlayerPosLook(SPacketPlayerPosLook packet); + void handleMultiBlockChange(SPacketMultiBlockChange packet); + void handleChunkData(SPacketChunkData packet); + void handleBiomes(SPacketBiome packet); + void handleBlockChange(SPacketBlockChange packet); + void handleDisconnect(SPacketDisconnect packet); + void handleCollectItem(SPacketCollectItem packet); + void handleMessage(SPacketMessage packet); void handleLoading(SPacketLoading packet); - void handleAnimation(SPacketAnimation packetIn); - void handleSpawnMob(SPacketSpawnMob packetIn); - void handleTimeUpdate(SPacketTimeUpdate packetIn); + void handleAnimation(SPacketAnimation packet); + void handleSpawnMob(SPacketSpawnMob packet); + void handleTimeUpdate(SPacketTimeUpdate packet); void handleServerTick(SPacketServerTick packet); - void handleEntityAttach(S1BPacketEntityAttach packetIn); - void handleEntityStatus(S1APacketEntityStatus packetIn); - void handleUpdateHealth(SPacketUpdateHealth packetIn); - void handleSetExperience(SPacketSetExperience packetIn); - void handleRespawn(SPacketRespawn packetIn); - void handleExplosion(S27PacketExplosion packetIn); - void handleOpenWindow(S2DPacketOpenWindow packetIn); - void handleSetSlot(S2FPacketSetSlot packetIn); - void handleConfirmTransaction(S32PacketConfirmTransaction packetIn); - void handleWindowItems(S30PacketWindowItems packetIn); - void handleSignEditorOpen(S36PacketSignEditorOpen packetIn); - void handleUpdateSign(S33PacketUpdateSign packetIn); - void handleUpdateTileEntity(S35PacketUpdateTileEntity packetIn); - void handleWindowProperty(S31PacketWindowProperty packetIn); - void handleEntityEquipment(SPacketEntityEquipment packetIn); - void handleCloseWindow(S2EPacketCloseWindow packetIn); - void handleBlockAction(SPacketBlockAction packetIn); - void handleBlockBreakAnim(SPacketBlockBreakAnim packetIn); - void handleMapChunkBulk(SPacketMapChunkBulk packetIn); - void handleChangeGameState(S2BPacketChangeGameState packetIn); - void handleEffect(S28PacketEffect packetIn); - void handleEntityEffect(S1DPacketEntityEffect packetIn); - void handleCamera(SPacketCamera packetIn); - void handleRemoveEntityEffect(S1EPacketRemoveEntityEffect packetIn); - void handlePlayerListItem(S38PacketPlayerListItem packetIn); + void handleEntityAttach(SPacketEntityAttach packet); + void handleEntityStatus(SPacketEntityStatus packet); + void handleUpdateHealth(SPacketUpdateHealth packet); + void handleSetExperience(SPacketSetExperience packet); + void handleRespawn(SPacketRespawn packet); + void handleExplosion(SPacketExplosion packet); + void handleOpenWindow(SPacketOpenWindow packet); + void handleSetSlot(SPacketSetSlot packet); + void handleConfirmTransaction(SPacketConfirmTransaction packet); + void handleWindowItems(SPacketWindowItems packet); + void handleSignEditorOpen(SPacketSignEditorOpen packet); + void handleUpdateSign(SPacketUpdateSign packet); + void handleUpdateTileEntity(SPacketUpdateTileEntity packet); + void handleWindowProperty(SPacketWindowProperty packet); + void handleEntityEquipment(SPacketEntityEquipment packet); + void handleCloseWindow(SPacketCloseWindow packet); + void handleBlockAction(SPacketBlockAction packet); + void handleBlockBreakAnim(SPacketBlockBreakAnim packet); + void handleMapChunkBulk(SPacketMapChunkBulk packet); + void handleChangeGameState(SPacketChangeGameState packet); + void handleEffect(SPacketEffect packet); + void handleEntityEffect(SPacketEntityEffect packet); + void handleCamera(SPacketCamera packet); + void handleRemoveEntityEffect(SPacketRemoveEntityEffect packet); + void handlePlayerListItem(SPacketPlayerListItem packet); void handleCharacterList(SPacketCharacterList packet); - void handleKeepAlive(SPacketKeepAlive packetIn); - void handlePlayerAbilities(S39PacketPlayerAbilities packetIn); - void handleTabComplete(S3APacketTabComplete packetIn); - void handleSoundEffect(S29PacketSoundEffect packetIn); - void handleEntityNBT(S43PacketUpdateEntityNBT packetIn); - void handleParticles(S2APacketParticles packetIn); - void handleEntityProperties(S20PacketEntityProperties packetIn); - void handleSkin(SPacketSkin packetIn); - void handleTrades(SPacketTrades packetIn); - void handleWorld(SPacketWorld packetIn); - void handleDimName(SPacketDimensionName packetIn); + void handleKeepAlive(SPacketKeepAlive packet); + void handlePlayerAbilities(SPacketPlayerAbilities packet); + void handleTabComplete(SPacketTabComplete packet); + void handleSoundEffect(SPacketSoundEffect packet); + void handleEntityNBT(SPacketUpdateEntityNBT packet); + void handleParticles(SPacketParticles packet); + void handleEntityProperties(SPacketEntityProperties packet); + void handleSkin(SPacketSkin packet); + void handleTrades(SPacketTrades packet); + void handleWorld(SPacketWorld packet); + void handleDimName(SPacketDimensionName packet); void handleForm(SPacketDisplayForm packet); void displayGUIChest(IInventory chestInventory, InventoryPlayer inventory); - void displayGui(IInteractionObject guiOwner, InventoryPlayer inventory, World worldObj); + void displayGui(IInteractionObject guiOwner, InventoryPlayer inventory, World world); void displayGuiHorse(EntityHorse horse, InventoryPlayer inventory, IInventory horseInventory); - void displayGuiMerchant(String title, InventoryPlayer inventory, World worldObj); + void displayGuiMerchant(String title, InventoryPlayer inventory, World world); void displayGuiSign(BlockPos pos, String[] text); void closeGui(); } \ No newline at end of file diff --git a/common/src/common/network/IHandshakeHandler.java b/common/src/common/network/IHandshakeHandler.java index b6815e8..1a534ba 100644 --- a/common/src/common/network/IHandshakeHandler.java +++ b/common/src/common/network/IHandshakeHandler.java @@ -3,7 +3,5 @@ package common.network; import common.packet.HPacketHandshake; public interface IHandshakeHandler { - - void processHandshake(HPacketHandshake packetIn); - -} \ No newline at end of file + void processHandshake(HPacketHandshake packet); +} diff --git a/common/src/common/network/ILoginHandler.java b/common/src/common/network/ILoginHandler.java index 479e986..b33bca6 100644 --- a/common/src/common/network/ILoginHandler.java +++ b/common/src/common/network/ILoginHandler.java @@ -5,11 +5,7 @@ import common.packet.LPacketPasswordResponse; import common.packet.LPacketStartEncrypt; public interface ILoginHandler { - - void processPasswordResponse(LPacketPasswordResponse packetIn); - + void processPasswordResponse(LPacketPasswordResponse packet); void processEncryption(LPacketStartEncrypt packet); - void processLogin(LPacketLogin packet); - -} \ No newline at end of file +} diff --git a/common/src/common/network/IPlayer.java b/common/src/common/network/IPlayer.java index 42d3fb6..bbe9652 100644 --- a/common/src/common/network/IPlayer.java +++ b/common/src/common/network/IPlayer.java @@ -11,7 +11,6 @@ import common.inventory.Container; import common.inventory.IInventory; import common.item.ItemStack; import common.packet.CPacketAction; -import common.packet.CPacketBook; import common.packet.CPacketBreak; import common.packet.CPacketCheat; import common.packet.CPacketClick; @@ -63,115 +62,61 @@ public interface IPlayer { } void onEntityDeath(); - boolean isInEditor(); - EntityNPC getPresentEntity(); - String getUser(); - int getLatency(); - boolean isAdmin(); - void addToPlayerScore(EntityLiving entity); - - void displayTradeGui(EntityNPC npc); - + void displayTradeGui(EntityNPC entity); void setPlayerHealthUpdated(); - - void removeEntity(Entity p_152339_1_); - + void removeEntity(Entity entity); void sendPlayerAbilities(); - void addFeed(String msg); - void addHotbar(String msg); - void addHotbar(String format, Object... args); - void sendThrowMessage(ItemStack stack); - void resetLastExperience(); - - void travelToDimension(int dimensionId, BlockPos pos, float yaw, float pitch, PortalType portal); - + void travelToDimension(int dimension, BlockPos pos, float yaw, float pitch, PortalType portal); void teleport(double x, double y, double z, float yaw, float pitch, int dimension); - void onItemPickup(Entity entity, int amount); - - void mountEntity(Entity entityIn); - + void mountEntity(Entity entity); void openEditSign(TileEntitySign signTile); - void displayGui(IInteractionObject guiOwner); - void displayGUIChest(IInventory chestInventory); - void displayGUIHorse(EntityHorse horse, IInventory horseInventory); - void closeScreen(); - void onItemUseFinish(); - void onNewEffect(PotionEffect id); - void onChangedEffect(PotionEffect id, boolean added); - void onFinishedEffect(PotionEffect effect); - void setPositionAndUpdate(double x, double y, double z); - - void onCriticalHit(Entity entityHit); - - void onEnchantmentCritical(Entity entityHit); - + void onCriticalHit(Entity entity); + void onEnchantmentCritical(Entity entity); void updateEffectMeta(); - void playSound(SoundEvent name, float volume); - void sendContainerToPlayer(Container container); - void updateEntity(); - void setSelection(boolean primary, BlockPos pos); - void setSelectMode(); - void sendPacket(Packet packet); - void setPlayerLocation(double x, double y, double z, float yaw, float pitch); - - void processKeepAlive(CPacketKeepAlive packetIn); - - void processMessage(CPacketMessage packetIn); - - void processComplete(CPacketComplete packetIn); - - void processPlayer(CPacketPlayer packetIn); - - void processBreak(CPacketBreak packetIn); - - void processPlace(CPacketPlace packetIn); - - void processAction(CPacketAction packetIn); - - void processInput(CPacketInput packetIn); - - void processClick(CPacketClick packetIn); - - void processCheat(CPacketCheat packetIn); - - void processSign(CPacketSign packetIn); - - void processSkin(CPacketSkin packetIn); - - void processBook(CPacketBook packetIn); - - void processForm(CPacketForm packet); - List getLoadedChunkList(); double getManagedX(); double getManagedZ(); void setManagedPos(double x, double z); -} \ No newline at end of file + + void processKeepAlive(CPacketKeepAlive packet); + void processMessage(CPacketMessage packet); + void processComplete(CPacketComplete packet); + void processPlayer(CPacketPlayer packet); + void processBreak(CPacketBreak packet); + void processPlace(CPacketPlace packet); + void processAction(CPacketAction packet); + void processInput(CPacketInput packet); + void processClick(CPacketClick packet); + void processCheat(CPacketCheat packet); + void processSign(CPacketSign packet); + void processSkin(CPacketSkin packet); + void processForm(CPacketForm packet); +} diff --git a/common/src/common/network/IThreadListener.java b/common/src/common/network/IThreadListener.java index e6f14d4..646777a 100755 --- a/common/src/common/network/IThreadListener.java +++ b/common/src/common/network/IThreadListener.java @@ -2,8 +2,7 @@ package common.network; import common.future.ListenableFuture; -public interface IThreadListener -{ +public interface IThreadListener { ListenableFuture schedule(Runnable run); boolean isMainThread(); default void log(String prefixed, String line) { diff --git a/common/src/common/network/NetConnection.java b/common/src/common/network/NetConnection.java index a359d83..216b3cb 100755 --- a/common/src/common/network/NetConnection.java +++ b/common/src/common/network/NetConnection.java @@ -27,34 +27,32 @@ public class NetConnection extends SimpleChannelInboundHandler { private static final Pattern IP_REPLACER = Pattern.compile("([0-9]*)\\.([0-9]*)\\.[0-9]*\\.[0-9]*"); public static final AttributeKey ATTR_STATE = AttributeKey.valueOf("protocol"); - private final Queue outboundPacketsQueue = new ConcurrentLinkedQueue(); - private final ReentrantReadWriteLock readWriteLock = new ReentrantReadWriteLock(); + + private final Queue queue = new ConcurrentLinkedQueue(); + private final ReentrantReadWriteLock lock = new ReentrantReadWriteLock(); private Channel channel; - private SocketAddress socketAddress; - private NetHandler packetListener; - private String terminationReason; + private SocketAddress address; + private NetHandler handler; + private String exitReason; private boolean disconnected; - public void channelActive(ChannelHandlerContext p_channelActive_1_) throws Exception + public void channelActive(ChannelHandlerContext context) throws Exception { - super.channelActive(p_channelActive_1_); - this.channel = p_channelActive_1_.channel(); - this.socketAddress = this.channel.remoteAddress(); + super.channelActive(context); + this.channel = context.channel(); + this.address = this.channel.remoteAddress(); try { this.setConnectionState(PacketRegistry.HANDSHAKE); } - catch (Throwable throwable) + catch (Throwable t) { - Log.JNI.error(throwable, "Fehler beim Aufbauen der Verbindung für Handshake"); + Log.JNI.error(t, "Fehler beim Aufbauen der Verbindung für Handshake"); } } - /** - * Sets the new connection state and registers which packets this channel may send and receive - */ public void setConnectionState(PacketRegistry newState) { this.channel.attr(ATTR_STATE).set(newState); @@ -62,36 +60,36 @@ public class NetConnection extends SimpleChannelInboundHandler // Log.debug("Automatisches Lesen eingeschaltet"); } - public void channelInactive(ChannelHandlerContext p_channelInactive_1_) throws Exception + public void channelInactive(ChannelHandlerContext context) throws Exception { this.closeChannel("Ende der Datenübertragung"); } - public void exceptionCaught(ChannelHandlerContext p_exceptionCaught_1_, Throwable p_exceptionCaught_2_) throws Exception + public void exceptionCaught(ChannelHandlerContext context, Throwable throwable) throws Exception { String comp; - if (p_exceptionCaught_2_ instanceof TimeoutException) + if (throwable instanceof TimeoutException) { comp = "Zeitüberschreitung"; } else { - comp = "Interner Fehler: " + p_exceptionCaught_2_; - if(!(p_exceptionCaught_2_ instanceof ClosedChannelException)) - Log.SYSTEM.error(p_exceptionCaught_2_, "Fehler in der Verbindung mit %s", this.getCutAddress()); + comp = "Interner Fehler: " + throwable; + if(!(throwable instanceof ClosedChannelException)) + Log.SYSTEM.error(throwable, "Fehler in der Verbindung mit %s", this.getCutAddress()); } this.closeChannel(comp); } - protected void channelRead0(ChannelHandlerContext p_channelRead0_1_, Packet p_channelRead0_2_) throws Exception + protected void channelRead0(ChannelHandlerContext context, Packet packet) throws Exception { if (this.channel.isOpen()) { try { - p_channelRead0_2_.processPacket(this.packetListener); + packet.processPacket(this.handler); } catch (ThreadQuickExitException e) { @@ -100,17 +98,13 @@ public class NetConnection extends SimpleChannelInboundHandler } } - /** - * Sets the NetHandler for this NetworkManager, no checks are made if this handler is suitable for the particular - * connection state (protocol) - */ public void setNetHandler(NetHandler handler) { if (handler == null) { throw new NullPointerException("Handler ist Null"); } // Log.debug("Setze Handler von " + this + " auf " + handler); - this.packetListener = handler; + this.handler = handler; } public void sendPacket(Packet packetIn) @@ -122,15 +116,15 @@ public class NetConnection extends SimpleChannelInboundHandler } else { - this.readWriteLock.writeLock().lock(); + this.lock.writeLock().lock(); try { - this.outboundPacketsQueue.add(new NetConnection.InboundHandlerTuplePacketListener(packetIn, null)); + this.queue.add(new NetConnection.InboundHandlerTuplePacketListener(packetIn, null)); } finally { - this.readWriteLock.writeLock().unlock(); + this.lock.writeLock().unlock(); } } } @@ -144,29 +138,25 @@ public class NetConnection extends SimpleChannelInboundHandler } else { - this.readWriteLock.writeLock().lock(); + this.lock.writeLock().lock(); try { - this.outboundPacketsQueue.add(new NetConnection.InboundHandlerTuplePacketListener(packetIn, listener)); + this.queue.add(new NetConnection.InboundHandlerTuplePacketListener(packetIn, listener)); } finally { - this.readWriteLock.writeLock().unlock(); + this.lock.writeLock().unlock(); } } } - /** - * Will commit the packet to the channel. If the current thread 'owns' the channel it will write and flush the - * packet, otherwise it will add a task for the channel eventloop thread to do that. - */ private void dispatchPacket(final Packet inPacket, final GenericFutureListener > [] futureListeners) { - final PacketRegistry enumconnectionstate = PacketRegistry.getType(inPacket); - final PacketRegistry enumconnectionstate1 = (PacketRegistry)this.channel.attr(ATTR_STATE).get(); + final PacketRegistry state = PacketRegistry.getType(inPacket); + final PacketRegistry current = this.channel.attr(ATTR_STATE).get(); - if (enumconnectionstate1 != enumconnectionstate) + if (current != state) { // Log.debug("Automatisches Lesen ausgeschaltet"); this.channel.config().setAutoRead(false); @@ -174,9 +164,9 @@ public class NetConnection extends SimpleChannelInboundHandler if (this.channel.eventLoop().inEventLoop()) { - if (enumconnectionstate != enumconnectionstate1) + if (state != current) { - this.setConnectionState(enumconnectionstate); + this.setConnectionState(state); } ChannelFuture channelfuture = this.channel.writeAndFlush(inPacket); @@ -194,9 +184,9 @@ public class NetConnection extends SimpleChannelInboundHandler { public void run() { - if (enumconnectionstate != enumconnectionstate1) + if (state != current) { - NetConnection.this.setConnectionState(enumconnectionstate); + NetConnection.this.setConnectionState(state); } ChannelFuture channelfuture1 = NetConnection.this.channel.writeAndFlush(inPacket); @@ -212,68 +202,46 @@ public class NetConnection extends SimpleChannelInboundHandler } } - /** - * Will iterate through the outboundPacketQueue and dispatch all Packets - */ private void flushOutboundQueue() { if (this.channel != null && this.channel.isOpen()) { - this.readWriteLock.readLock().lock(); + this.lock.readLock().lock(); try { - while (!this.outboundPacketsQueue.isEmpty()) + while (!this.queue.isEmpty()) { - NetConnection.InboundHandlerTuplePacketListener networkmanager$inboundhandlertuplepacketlistener = (NetConnection.InboundHandlerTuplePacketListener)this.outboundPacketsQueue.poll(); - if(networkmanager$inboundhandlertuplepacketlistener != null) { // NPE Fix - this.dispatchPacket(networkmanager$inboundhandlertuplepacketlistener.packet, networkmanager$inboundhandlertuplepacketlistener.futureListeners); - } + NetConnection.InboundHandlerTuplePacketListener entry = this.queue.poll(); + if(entry != null) // NPE Fix + this.dispatchPacket(entry.packet, entry.listeners); } } finally { - this.readWriteLock.readLock().unlock(); + this.lock.readLock().unlock(); } } } - /** - * Checks timeouts and processes all packets received - */ public void processReceivedPackets() { this.flushOutboundQueue(); - this.packetListener.update(); -// if (this.packetListener instanceof ITickable) -// { -// ((ITickable)this.packetListener).update(); -// } + this.handler.update(); if(this.channel != null) this.channel.flush(); } - -// /** -// * Returns the socket address of the remote side. Server-only. -// */ -// public SocketAddress getRemoteAddress() -// { -// return this.socketAddress; -// } public String getCutAddress() { - return this.socketAddress == null ? "?.?.*.*" : IP_REPLACER.matcher(this.socketAddress.toString()).replaceAll("$1.$2.*.*"); + return this.address == null ? "?.?.*.*" : IP_REPLACER.matcher(this.address.toString()).replaceAll("$1.$2.*.*"); } - /** - * Closes the channel, the parameter can be used for an exit message (not certain how it gets sent) - */ public void closeChannel(String message) { if (this.channel.isOpen()) { this.channel.close().awaitUninterruptibly(); - this.terminationReason = message; + this.exitReason = message; } } @@ -287,17 +255,6 @@ public class NetConnection extends SimpleChannelInboundHandler return this.channel == null; } - /** - * Gets the current handler for processing packets - */ - public NetHandler getNetHandler() - { - return this.packetListener; - } - - /** - * Switches the channel to manual reading modus - */ public void disableAutoRead() { this.channel.config().setAutoRead(false); @@ -307,32 +264,32 @@ public class NetConnection extends SimpleChannelInboundHandler { if (treshold >= 0) { - if (this.channel.pipeline().get("decompress") instanceof NettyCompressionDecoder) + if (this.channel.pipeline().get("decompress") instanceof CompressionDecoder) { - ((NettyCompressionDecoder)this.channel.pipeline().get("decompress")).setCompressionTreshold(treshold); + ((CompressionDecoder)this.channel.pipeline().get("decompress")).setTreshold(treshold); } else { - this.channel.pipeline().addBefore("decoder", "decompress", new NettyCompressionDecoder(treshold)); + this.channel.pipeline().addBefore("decoder", "decompress", new CompressionDecoder(treshold)); } - if (this.channel.pipeline().get("compress") instanceof NettyCompressionEncoder) + if (this.channel.pipeline().get("compress") instanceof CompressionEncoder) { - ((NettyCompressionEncoder)this.channel.pipeline().get("compress")).setCompressionTreshold(treshold); + ((CompressionEncoder)this.channel.pipeline().get("compress")).setTreshold(treshold); } else { - this.channel.pipeline().addBefore("encoder", "compress", new NettyCompressionEncoder(treshold)); + this.channel.pipeline().addBefore("encoder", "compress", new CompressionEncoder(treshold)); } } else { - if (this.channel.pipeline().get("decompress") instanceof NettyCompressionDecoder) + if (this.channel.pipeline().get("decompress") instanceof CompressionDecoder) { this.channel.pipeline().remove("decompress"); } - if (this.channel.pipeline().get("compress") instanceof NettyCompressionEncoder) + if (this.channel.pipeline().get("compress") instanceof CompressionEncoder) { this.channel.pipeline().remove("compress"); } @@ -346,15 +303,8 @@ public class NetConnection extends SimpleChannelInboundHandler if (!this.disconnected) { this.disconnected = true; - - if (this.terminationReason != null) - { - this.getNetHandler().onDisconnect(this.terminationReason); - } - else if (this.getNetHandler() != null) - { - this.getNetHandler().onDisconnect("Verbindung getrennt"); - } + if(this.handler != null) + this.handler.onDisconnect(this.exitReason != null ? this.exitReason : "Verbindung getrennt"); } else { @@ -364,19 +314,19 @@ public class NetConnection extends SimpleChannelInboundHandler } public void startEncryption(SecretKey key) { - this.channel.pipeline().addBefore("splitter", "decrypt", new NettyEncryptionDecoder(EncryptUtil.createCipher(Cipher.DECRYPT_MODE, key))); - this.channel.pipeline().addBefore("prepender", "encrypt", new NettyEncryptionEncoder(EncryptUtil.createCipher(Cipher.ENCRYPT_MODE, key))); + this.channel.pipeline().addBefore("splitter", "decrypt", new EncryptionDecoder(EncryptUtil.createCipher(Cipher.DECRYPT_MODE, key))); + this.channel.pipeline().addBefore("prepender", "encrypt", new EncryptionEncoder(EncryptUtil.createCipher(Cipher.ENCRYPT_MODE, key))); } - static class InboundHandlerTuplePacketListener + private static class InboundHandlerTuplePacketListener { private final Packet packet; - private final GenericFutureListener > [] futureListeners; + private final GenericFutureListener > [] listeners; - public InboundHandlerTuplePacketListener(Packet inPacket, GenericFutureListener > inFutureListener) + public InboundHandlerTuplePacketListener(Packet packet, GenericFutureListener > listener) { - this.packet = inPacket; - this.futureListeners = inFutureListener == null ? null : new GenericFutureListener[] {inFutureListener}; + this.packet = packet; + this.listeners = listener == null ? null : new GenericFutureListener[] {listener}; } } } diff --git a/common/src/common/network/NetHandler.java b/common/src/common/network/NetHandler.java index 1454ec5..2c1f59a 100755 --- a/common/src/common/network/NetHandler.java +++ b/common/src/common/network/NetHandler.java @@ -19,8 +19,7 @@ public abstract class NetHandler { public void update() { } - public static void checkThread(final Packet packet, final T handler, IThreadListener listener) - throws ThreadQuickExitException { + public static void checkThread(final Packet packet, final T handler, IThreadListener listener) throws ThreadQuickExitException { if(!listener.isMainThread()) { listener.schedule(new Runnable() { public void run() { @@ -31,11 +30,9 @@ public abstract class NetHandler { } } - public static void checkThread(final Packet packet, final T handler, IThreadListener listener, Object check) - throws ThreadQuickExitException { - if(check == null && listener.isMainThread()) { + public static void checkThread(final Packet packet, final T handler, IThreadListener listener, Object check) throws ThreadQuickExitException { + if(check == null && listener.isMainThread()) throw EXIT; - } checkThread(packet, handler, listener); } } diff --git a/common/src/common/network/NettyCompressionDecoder.java b/common/src/common/network/NettyCompressionDecoder.java deleted file mode 100755 index d77de45..0000000 --- a/common/src/common/network/NettyCompressionDecoder.java +++ /dev/null @@ -1,62 +0,0 @@ -package common.network; - -import java.util.List; -import java.util.zip.DataFormatException; -import java.util.zip.Inflater; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.Unpooled; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.ByteToMessageDecoder; -import io.netty.handler.codec.DecoderException; - -public class NettyCompressionDecoder extends ByteToMessageDecoder -{ - private final Inflater inflater; - private int treshold; - - public NettyCompressionDecoder(int treshold) - { - this.treshold = treshold; - this.inflater = new Inflater(); - } - - protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws DataFormatException, Exception - { - if (p_decode_2_.readableBytes() != 0) - { - PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_); - int i = packetbuffer.readVarIntFromBuffer(); - - if (i == 0) - { - p_decode_3_.add(packetbuffer.readBytes(packetbuffer.readableBytes())); - } - else - { - if (i < this.treshold) - { - throw new DecoderException("Badly compressed packet - size of " + i + " is below server threshold of " + this.treshold); - } - - if (i > 2097152) - { - throw new DecoderException("Badly compressed packet - size of " + i + " is larger than protocol maximum of " + 2097152); - } - - byte[] abyte = new byte[packetbuffer.readableBytes()]; - packetbuffer.readBytes(abyte); - this.inflater.setInput(abyte); - byte[] abyte1 = new byte[i]; - this.inflater.inflate(abyte1); - p_decode_3_.add(Unpooled.wrappedBuffer(abyte1)); - this.inflater.reset(); - } - } - } - - public void setCompressionTreshold(int treshold) - { - this.treshold = treshold; - } -} diff --git a/common/src/common/network/NettyCompressionEncoder.java b/common/src/common/network/NettyCompressionEncoder.java deleted file mode 100755 index 9719f99..0000000 --- a/common/src/common/network/NettyCompressionEncoder.java +++ /dev/null @@ -1,53 +0,0 @@ -package common.network; - -import java.util.zip.Deflater; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; - -public class NettyCompressionEncoder extends MessageToByteEncoder -{ - private final byte[] buffer = new byte[8192]; - private final Deflater deflater; - private int treshold; - - public NettyCompressionEncoder(int treshold) - { - this.treshold = treshold; - this.deflater = new Deflater(); - } - - protected void encode(ChannelHandlerContext p_encode_1_, ByteBuf p_encode_2_, ByteBuf p_encode_3_) throws Exception - { - int i = p_encode_2_.readableBytes(); - PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_); - - if (i < this.treshold) - { - packetbuffer.writeVarIntToBuffer(0); - packetbuffer.writeBytes(p_encode_2_); - } - else - { - byte[] abyte = new byte[i]; - p_encode_2_.readBytes(abyte); - packetbuffer.writeVarIntToBuffer(abyte.length); - this.deflater.setInput(abyte, 0, i); - this.deflater.finish(); - - while (!this.deflater.finished()) - { - int j = this.deflater.deflate(this.buffer); - packetbuffer.writeBytes((byte[])this.buffer, 0, j); - } - - this.deflater.reset(); - } - } - - public void setCompressionTreshold(int treshold) - { - this.treshold = treshold; - } -} diff --git a/common/src/common/network/Packet.java b/common/src/common/network/Packet.java index 4ba381f..bc9c9d9 100755 --- a/common/src/common/network/Packet.java +++ b/common/src/common/network/Packet.java @@ -2,8 +2,7 @@ package common.network; import java.io.IOException; -public interface Packet -{ +public interface Packet { void readPacketData(PacketBuffer buf) throws IOException; void writePacketData(PacketBuffer buf) throws IOException; void processPacket(T handler); diff --git a/common/src/common/network/PacketBuffer.java b/common/src/common/network/PacketBuffer.java index 390c141..cbc0a3b 100755 --- a/common/src/common/network/PacketBuffer.java +++ b/common/src/common/network/PacketBuffer.java @@ -15,449 +15,250 @@ import io.netty.buffer.ByteBufOutputStream; import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.EncoderException; -public class PacketBuffer -{ +public class PacketBuffer { private static final Charset UTF_8 = Charset.forName("UTF-8"); + + private final ByteBuf buf; + + public PacketBuffer(ByteBuf wrapped) { + this.buf = wrapped; + } + + public static int getVarIntSize(int input) { + for(int i = 1; i < 5; ++i) { + if((input & -1 << i * 7) == 0) + return i; + } + return 5; + } + + public void writeByteArray(byte[] data) { + this.writeVarInt(data.length); + this.writeBytes(data); + } + + public byte[] readByteArray() { + byte[] data = new byte[this.readVarInt()]; + this.readBytes(data); + return data; + } + + public void writeBlockPos(BlockPos pos) { + this.writeInt(pos.getX()); + this.writeInt(pos.getY()); + this.writeInt(pos.getZ()); + } + + public BlockPos readBlockPos() { + return new BlockPos(this.readInt(), this.readInt(), this.readInt()); + } + + public void writeEnumValue(Enum value) { + this.writeVarInt(value.ordinal()); + } + + public > T readEnumValue(Class clazz) { + return (T)((Enum[])clazz.getEnumConstants())[this.readVarInt()]; + } + + public void writeEnumOrNull(Enum value) { + this.writeVarInt(value == null ? -1 : value.ordinal()); + } + + public > T readEnumOrNull(Class clazz) { + int n = this.readVarInt(); + return n < 0 ? null : (T)((Enum[])clazz.getEnumConstants())[n]; + } + + public void writeVarInt(int value) { + while((value & -128) != 0) { + this.writeByte(value & 127 | 128); + value >>>= 7; + } + this.writeByte(value); + } + + public int readVarInt() { + int v = 0; + int c = 0; + while(true) { + byte b = this.readByte(); + v |= (b & 127) << c++ * 7; + if(c > 5) + throw new RuntimeException("VarInt too big"); + if((b & 128) != 128) + break; + } + return v; + } - private final ByteBuf buf; + public void writeTag(NBTTagCompound tag) { + if(tag == null) { + this.writeByte(0); + return; + } + try { + NBTLoader.write(tag, new ByteBufOutputStream(this.buf)); + } + catch(IOException e) { + throw new EncoderException(e); + } + } + + public NBTTagCompound readTag() throws IOException { + int i = this.buf.readerIndex(); + byte b = this.readByte(); + if(b == 0) + return null; + this.buf.readerIndex(i); + return NBTLoader.read(new ByteBufInputStream(this.buf), new NBTSizeTracker(2097152L)); + } + + public void writeItemStack(ItemStack stack) { + if(stack == null) { + this.writeShort(-1); + return; + } + this.writeShort(ItemRegistry.getIdFromItem(stack.getItem())); + this.writeVarInt(stack.stackSize); + this.writeShort(stack.getMetadata()); + this.writeTag(stack.getTagCompound()); + } + + public ItemStack readItemStack() throws IOException { + int id = this.readShort(); + if(id < 0) + return null; + int amt = this.readVarInt(); + int meta = this.readShort(); + ItemStack stack = new ItemStack(ItemRegistry.getItemById(id), amt, meta); + stack.setTagCompound(this.readTag()); + return stack; + } + + public void writeString(String str) { + byte[] data = str.getBytes(UTF_8); + if(data.length > 32767) + throw new EncoderException("String too big (was " + str.length() + " bytes encoded, max " + 32767 + ")"); + this.writeVarInt(data.length); + this.writeBytes(data); + } + + public String readString(int limit) { + int len = this.readVarInt(); + if(len > limit * 4) + throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + len + " > " + limit * 4 + ")"); + else if(len < 0) + throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!"); + byte[] data = new byte[len]; + this.readBytes(data); + String str = new String(data, UTF_8); + if(str.length() > limit) + throw new DecoderException("The received string length is longer than maximum allowed (" + len + " > " + limit + ")"); + return str; + } + + public void writeBoolean(boolean value) { + this.buf.writeBoolean(value); + } + + public boolean readBoolean() { + return this.buf.readBoolean(); + } + + public void writeByte(int value) { + this.buf.writeByte(value); + } + + public byte readByte() { + return this.buf.readByte(); + } + + public short readUnsignedByte() { + return this.buf.readUnsignedByte(); + } + + public void writeShort(int value) { + this.buf.writeShort(value); + } + + public short readShort() { + return this.buf.readShort(); + } + + public int readUnsignedShort() { + return this.buf.readUnsignedShort(); + } + + public void writeInt(int value) { + this.buf.writeInt(value); + } + + public int readInt() { + return this.buf.readInt(); + } + + public long readUnsignedInt() { + return this.buf.readUnsignedInt(); + } + + public void writeLong(long value) { + this.buf.writeLong(value); + } + + public long readLong() { + return this.buf.readLong(); + } + + public void writeFloat(float value) { + this.buf.writeFloat(value); + } + + public float readFloat() { + return this.buf.readFloat(); + } + + public void writeDouble(double value) { + this.buf.writeDouble(value); + } + + public double readDouble() { + return this.buf.readDouble(); + } + + public ByteBuf readBytes(int size) { + return this.buf.readBytes(size); + } + + public void writeBytes(byte[] data) { + this.buf.writeBytes(data); + } + + public void readBytes(byte[] buffer) { + this.buf.readBytes(buffer); + } + + public void writeBytes(byte[] data, int offset, int length) { + this.buf.writeBytes(data, offset, length); + } + + public void writeBuffer(ByteBuf buf) { + this.buf.writeBytes(buf); + } + + public void writeBuffer(ByteBuf buf, int offset, int length) { + this.buf.writeBytes(buf, offset, length); + } + + public int readableBytes() { + return this.buf.readableBytes(); + } + + public void ensureWritable(int size) { + this.buf.ensureWritable(size); + } - public PacketBuffer(ByteBuf wrapped) - { - this.buf = wrapped; - } - - /** - * Calculates the number of bytes required to fit the supplied int (0-5) if it were to be read/written using - * readVarIntFromBuffer or writeVarIntToBuffer - */ - public static int getVarIntSize(int input) - { - for (int i = 1; i < 5; ++i) - { - if ((input & -1 << i * 7) == 0) - { - return i; - } - } - - return 5; - } - - public void writeByteArray(byte[] array) - { - this.writeVarIntToBuffer(array.length); - this.writeBytes(array); - } - - public byte[] readByteArray() - { - byte[] abyte = new byte[this.readVarIntFromBuffer()]; - this.readBytes(abyte); - return abyte; - } - - public BlockPos readBlockPos() - { - return new BlockPos(this.readInt(), this.readInt(), this.readInt()); - } - - public void writeBlockPos(BlockPos pos) - { - this.writeInt(pos.getX()); - this.writeInt(pos.getY()); - this.writeInt(pos.getZ()); - } - -// public Text readChatComponent() throws IOException -// { -// return Text.toComponent(this.readNBTTagCompoundFromBuffer()); -// } -// -// public void writeChatComponent(Text component) throws IOException -// { -// this.writeNBTTagCompoundToBuffer(Text.toNbt(component)); -//// String s = ; -//// if(s.length() > 32767) { -//// s = component.getFormattedText(); -//// s = s.length() > 32720 ? s.substring(0, 32720) : s; -//// s = TextSerializer.toNbt(new TextComponent(s + ChatFormat.GRAY + ChatFormat.ITALIC + " [...]")); -//// } -//// this.writeString(s); -// } - - public > T readEnumValue(Class enumClass) - { - return (T)((Enum[])enumClass.getEnumConstants())[this.readVarIntFromBuffer()]; - } - - public > T readEnumOrNull(Class enumClass) - { - int n = this.readVarIntFromBuffer(); - return n < 0 ? null : (T)((Enum[])enumClass.getEnumConstants())[n]; - } - - public void writeEnumValue(Enum value) - { - this.writeVarIntToBuffer(value.ordinal()); - } - - public void writeEnumOrNull(Enum value) - { - this.writeVarIntToBuffer(value == null ? -1 : value.ordinal()); - } - - /** - * Reads a compressed int from the buffer. To do so it maximally reads 5 byte-sized chunks whose most significant - * bit dictates whether another byte should be read. - */ - public int readVarIntFromBuffer() - { - int i = 0; - int j = 0; - - while (true) - { - byte b0 = this.readByte(); - i |= (b0 & 127) << j++ * 7; - - if (j > 5) - { - throw new RuntimeException("VarInt too big"); - } - - if ((b0 & 128) != 128) - { - break; - } - } - - return i; - } - - public long readVarLong() - { - long i = 0L; - int j = 0; - - while (true) - { - byte b0 = this.readByte(); - i |= (long)(b0 & 127) << j++ * 7; - - if (j > 10) - { - throw new RuntimeException("VarLong too big"); - } - - if ((b0 & 128) != 128) - { - break; - } - } - - return i; - } - -// public void writeUuid(UUID uuid) -// { -// this.writeLong(uuid.getMostSignificantBits()); -// this.writeLong(uuid.getLeastSignificantBits()); -// } -// -// public UUID readUuid() -// { -// return new UUID(this.readLong(), this.readLong()); -// } - - /** - * Writes a compressed int to the buffer. The smallest number of bytes to fit the passed int will be written. Of - * each such byte only 7 bits will be used to describe the actual value since its most significant bit dictates - * whether the next byte is part of that same int. Micro-optimization for int values that are expected to have - * values below 128. - */ - public void writeVarIntToBuffer(int input) - { - while ((input & -128) != 0) - { - this.writeByte(input & 127 | 128); - input >>>= 7; - } - - this.writeByte(input); - } - - public void writeVarLong(long value) - { - while ((value & -128L) != 0L) - { - this.writeByte((int)(value & 127L) | 128); - value >>>= 7; - } - - this.writeByte((int)value); - } - - /** - * Writes a compressed NBTTagCompound to this buffer - */ - public void writeNBTTagCompoundToBuffer(NBTTagCompound nbt) - { - if (nbt == null) - { - this.writeByte(0); - } - else - { - try - { - NBTLoader.write(nbt, new ByteBufOutputStream(this.buf)); - } - catch (IOException ioexception) - { - throw new EncoderException(ioexception); - } - } - } - - /** - * Reads a compressed NBTTagCompound from this buffer - */ - public NBTTagCompound readNBTTagCompoundFromBuffer() throws IOException - { - int i = this.buf.readerIndex(); - byte b0 = this.readByte(); - - if (b0 == 0) - { - return null; - } - else - { - this.buf.readerIndex(i); - return NBTLoader.read(new ByteBufInputStream(this.buf), new NBTSizeTracker(2097152L)); - } - } - - /** - * Writes the ItemStack's ID (short), then size (byte), then damage. (short) - */ - public void writeItemStackToBuffer(ItemStack stack) - { - if (stack == null) - { - this.writeShort(-1); - } - else - { - this.writeShort(ItemRegistry.getIdFromItem(stack.getItem())); - this.writeVarIntToBuffer(stack.stackSize); - this.writeShort(stack.getMetadata()); - NBTTagCompound nbttagcompound = null; - - if (stack.getItem().isDamageable() || stack.getItem().getShareTag()) - { - nbttagcompound = stack.getTagCompound(); - } - - this.writeNBTTagCompoundToBuffer(nbttagcompound); - } - } - - /** - * Reads an ItemStack from this buffer - */ - public ItemStack readItemStackFromBuffer() throws IOException - { - ItemStack itemstack = null; - int i = this.readShort(); - - if (i >= 0) - { - int j = this.readVarIntFromBuffer(); - int k = this.readShort(); - itemstack = new ItemStack(ItemRegistry.getItemById(i), j, k); - itemstack.setTagCompound(this.readNBTTagCompoundFromBuffer()); - } - - return itemstack; - } - - /** - * Reads a string from this buffer. Expected parameter is maximum allowed string length. Will throw IOException if - * string length exceeds this value! - */ - public String readStringFromBuffer(int maxLength) - { - int i = this.readVarIntFromBuffer(); - - if (i > maxLength * 4) - { - throw new DecoderException("The received encoded string buffer length is longer than maximum allowed (" + i + " > " + maxLength * 4 + ")"); - } - else if (i < 0) - { - throw new DecoderException("The received encoded string buffer length is less than zero! Weird string!"); - } - else - { - byte[] abyte = new byte[i]; - this.readBytes(abyte); - String s = new String(abyte, UTF_8); // this.readBytes(i).array() - - if (s.length() > maxLength) - { - throw new DecoderException("The received string length is longer than maximum allowed (" + i + " > " + maxLength + ")"); - } - else - { - return s; - } - } - } - - public PacketBuffer writeString(String string) - { - byte[] abyte = string.getBytes(UTF_8); - - if (abyte.length > 32767) - { - throw new EncoderException("String too big (was " + string.length() + " bytes encoded, max " + 32767 + ")"); - } - else - { - this.writeVarIntToBuffer(abyte.length); - this.writeBytes(abyte); - return this; - } - } - - public int readableBytes() - { - return this.buf.readableBytes(); - } - - public ByteBuf ensureWritable(int p_ensureWritable_1_) - { - return this.buf.ensureWritable(p_ensureWritable_1_); - } - - public boolean readBoolean() - { - return this.buf.readBoolean(); - } - - public byte readByte() - { - return this.buf.readByte(); - } - - public short readUnsignedByte() - { - return this.buf.readUnsignedByte(); - } - - public short readShort() - { - return this.buf.readShort(); - } - - public int readUnsignedShort() - { - return this.buf.readUnsignedShort(); - } - - public int readInt() - { - return this.buf.readInt(); - } - - public long readUnsignedInt() - { - return this.buf.readUnsignedInt(); - } - - public long readLong() - { - return this.buf.readLong(); - } - - public float readFloat() - { - return this.buf.readFloat(); - } - - public double readDouble() - { - return this.buf.readDouble(); - } - - public ByteBuf readBytes(int p_readBytes_1_) - { - return this.buf.readBytes(p_readBytes_1_); - } - - public ByteBuf readBytes(byte[] p_readBytes_1_) - { - return this.buf.readBytes(p_readBytes_1_); - } - - public ByteBuf writeBoolean(boolean p_writeBoolean_1_) - { - return this.buf.writeBoolean(p_writeBoolean_1_); - } - - public ByteBuf writeByte(int p_writeByte_1_) - { - return this.buf.writeByte(p_writeByte_1_); - } - - public ByteBuf writeShort(int p_writeShort_1_) - { - return this.buf.writeShort(p_writeShort_1_); - } - - public ByteBuf writeInt(int p_writeInt_1_) - { - return this.buf.writeInt(p_writeInt_1_); - } - - public ByteBuf writeLong(long p_writeLong_1_) - { - return this.buf.writeLong(p_writeLong_1_); - } - - public ByteBuf writeFloat(float p_writeFloat_1_) - { - return this.buf.writeFloat(p_writeFloat_1_); - } - - public ByteBuf writeDouble(double p_writeDouble_1_) - { - return this.buf.writeDouble(p_writeDouble_1_); - } - - public ByteBuf writeBytes(ByteBuf p_writeBytes_1_) - { - return this.buf.writeBytes(p_writeBytes_1_); - } - - public ByteBuf writeBytes(ByteBuf p_writeBytes_1_, int p_writeBytes_2_, int p_writeBytes_3_) - { - return this.buf.writeBytes(p_writeBytes_1_, p_writeBytes_2_, p_writeBytes_3_); - } - - public ByteBuf writeBytes(byte[] p_writeBytes_1_) - { - return this.buf.writeBytes(p_writeBytes_1_); - } - - public ByteBuf writeBytes(byte[] p_writeBytes_1_, int p_writeBytes_2_, int p_writeBytes_3_) - { - return this.buf.writeBytes(p_writeBytes_1_, p_writeBytes_2_, p_writeBytes_3_); - } - - public boolean release() - { - return this.buf.release(); - } + public void release() { + this.buf.release(); + } } diff --git a/common/src/common/network/PacketDecoder.java b/common/src/common/network/PacketDecoder.java index e00089d..9d5f1c3 100755 --- a/common/src/common/network/PacketDecoder.java +++ b/common/src/common/network/PacketDecoder.java @@ -7,45 +7,26 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; -public class PacketDecoder extends ByteToMessageDecoder -{ - private final boolean client; +public class PacketDecoder extends ByteToMessageDecoder { + private final boolean client; - public PacketDecoder(boolean client) - { - this.client = client; - } + public PacketDecoder(boolean client) { + this.client = client; + } - protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws IOException, InstantiationException, IllegalAccessException, Exception - { - if (p_decode_2_.readableBytes() != 0) - { - PacketBuffer packetbuffer = new PacketBuffer(p_decode_2_); - int i = packetbuffer.readVarIntFromBuffer(); - Packet packet = ((PacketRegistry)p_decode_1_.channel().attr(NetConnection.ATTR_STATE).get()).getPacket(this.client, i); - - if (packet == null) - { - throw new IOException("Ungültige Paket-ID " + i); - } - else - { - packet.readPacketData(packetbuffer); - - if (packetbuffer.readableBytes() > 0) - { - throw new IOException("Paket " + ((PacketRegistry)p_decode_1_.channel().attr(NetConnection.ATTR_STATE).get()).ordinal() + "/" + i + " (" + packet.getClass() + ") war größer als erwartet, " + packetbuffer.readableBytes() + " weitere Bytes wurden beim Lesen von Paket " + i + " gefunden"); - } - else - { - p_decode_3_.add(packet); - -// if (Log.isTraceEnabled()) -// { -// Log.SYSTEM.info("EIN: [" + p_decode_1_.channel().attr(NetConnection.ATTR_STATE).get() + ":" + i + "] " + packet.getClass().getName()); -// } - } - } - } - } + protected void decode(ChannelHandlerContext context, ByteBuf buffer, List output) throws IOException, InstantiationException, IllegalAccessException, Exception { + if(buffer.readableBytes() == 0) + return; + PacketBuffer pbuf = new PacketBuffer(buffer); + int id = pbuf.readVarInt(); + Packet packet = context.channel().attr(NetConnection.ATTR_STATE).get().getPacket(this.client, id); + if(packet == null) + throw new IOException("Ungültige Paket-ID " + id); + packet.readPacketData(pbuf); + if(pbuf.readableBytes() > 0) + throw new IOException("Paket " + ((PacketRegistry)context.channel().attr(NetConnection.ATTR_STATE).get()).ordinal() + "/" + id + " (" + + packet.getClass() + ") war größer als erwartet, " + pbuf.readableBytes() + " weitere Bytes wurden beim Lesen von Paket " + id + " gefunden"); + output.add(packet); +// common.log.Log.SYSTEM.info("EIN: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + ":" + id + "] " + packet.getClass().getName()); + } } diff --git a/common/src/common/network/PacketEncoder.java b/common/src/common/network/PacketEncoder.java index fec4859..26f1190 100755 --- a/common/src/common/network/PacketEncoder.java +++ b/common/src/common/network/PacketEncoder.java @@ -2,46 +2,29 @@ package common.network; import java.io.IOException; -import common.log.Log; import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; -public class PacketEncoder extends MessageToByteEncoder -{ - private final boolean client; +public class PacketEncoder extends MessageToByteEncoder { + private final boolean client; - public PacketEncoder(boolean client) - { - this.client = client; - } + public PacketEncoder(boolean client) { + this.client = client; + } - protected void encode(ChannelHandlerContext p_encode_1_, Packet p_encode_2_, ByteBuf p_encode_3_) throws IOException, Exception - { - Integer integer = ((PacketRegistry)p_encode_1_.channel().attr(NetConnection.ATTR_STATE).get()).getId(this.client, p_encode_2_); - -// if (Log.isTraceEnabled()) -// { -// Log.SYSTEM.debug("AUS: [" + p_encode_1_.channel().attr(NetConnection.ATTR_STATE).get() + ":" + integer + "] " + p_encode_2_.getClass().getName()); -// } - - if (integer == null) - { - throw new IOException("Kann nicht registriertes Paket nicht serialisieren"); - } - else - { - PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_); - packetbuffer.writeVarIntToBuffer(integer.intValue()); - - try - { - p_encode_2_.writePacketData(packetbuffer); - } - catch (Throwable throwable) - { - Log.JNI.error(throwable, "Fehler beim Schreiben der Paketdaten"); - } - } - } + protected void encode(ChannelHandlerContext context, Packet packet, ByteBuf output) throws IOException, Exception { + Integer id = context.channel().attr(NetConnection.ATTR_STATE).get().getId(this.client, packet); + if(id == null) + throw new IOException("Kann nicht registriertes Paket nicht serialisieren"); +// common.log.Log.SYSTEM.debug("AUS: [" + context.channel().attr(NetConnection.ATTR_STATE).get() + ":" + id + "] " + packet.getClass().getName()); + PacketBuffer pbuf = new PacketBuffer(output); + pbuf.writeVarInt(id); + try { + packet.writePacketData(pbuf); + } + catch(Throwable t) { + throw new IOException("Fehler beim Schreiben der Paketdaten", t); + } + } } diff --git a/common/src/common/network/PacketPrepender.java b/common/src/common/network/PacketPrepender.java index 670f337..7a89749 100755 --- a/common/src/common/network/PacketPrepender.java +++ b/common/src/common/network/PacketPrepender.java @@ -4,23 +4,15 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.MessageToByteEncoder; -public class PacketPrepender extends MessageToByteEncoder -{ - protected void encode(ChannelHandlerContext p_encode_1_, ByteBuf p_encode_2_, ByteBuf p_encode_3_) throws Exception - { - int i = p_encode_2_.readableBytes(); - int j = PacketBuffer.getVarIntSize(i); - - if (j > 3) - { - throw new IllegalArgumentException("unable to fit " + i + " into " + 3); - } - else - { - PacketBuffer packetbuffer = new PacketBuffer(p_encode_3_); - packetbuffer.ensureWritable(j + i); - packetbuffer.writeVarIntToBuffer(i); - packetbuffer.writeBytes(p_encode_2_, p_encode_2_.readerIndex(), i); - } - } +public class PacketPrepender extends MessageToByteEncoder { + protected void encode(ChannelHandlerContext context, ByteBuf buffer, ByteBuf output) throws Exception { + int len = buffer.readableBytes(); + int vs = PacketBuffer.getVarIntSize(len); + if(vs > 3) + throw new IllegalArgumentException("unable to fit " + len + " into " + 3); + PacketBuffer pbuf = new PacketBuffer(output); + pbuf.ensureWritable(vs + len); + pbuf.writeVarInt(len); + pbuf.writeBuffer(buffer, buffer.readerIndex(), len); + } } diff --git a/common/src/common/network/PacketRegistry.java b/common/src/common/network/PacketRegistry.java index b6a4b59..a1930de 100755 --- a/common/src/common/network/PacketRegistry.java +++ b/common/src/common/network/PacketRegistry.java @@ -5,8 +5,10 @@ import java.util.Map; import common.collect.BiMap; import common.collect.HashBiMap; import common.collect.Maps; +import common.packet.CPacketPlayerPosition; +import common.packet.CPacketPlayerLook; +import common.packet.CPacketPlayerPosLook; import common.packet.CPacketAction; -import common.packet.CPacketBook; import common.packet.CPacketBreak; import common.packet.CPacketCheat; import common.packet.CPacketClick; @@ -27,34 +29,37 @@ import common.packet.RPacketDisconnect; import common.packet.RPacketEnableCompression; import common.packet.RPacketLoginSuccess; import common.packet.RPacketRequestEncrypt; -import common.packet.S14PacketEntity; -import common.packet.S18PacketEntityTeleport; -import common.packet.S19PacketEntityHeadLook; -import common.packet.S1APacketEntityStatus; -import common.packet.S1BPacketEntityAttach; -import common.packet.S1CPacketEntityMetadata; -import common.packet.S1DPacketEntityEffect; -import common.packet.S1EPacketRemoveEntityEffect; -import common.packet.S20PacketEntityProperties; -import common.packet.S27PacketExplosion; -import common.packet.S28PacketEffect; -import common.packet.S29PacketSoundEffect; -import common.packet.S2APacketParticles; -import common.packet.S2BPacketChangeGameState; -import common.packet.S2CPacketSpawnGlobalEntity; -import common.packet.S2DPacketOpenWindow; -import common.packet.S2EPacketCloseWindow; -import common.packet.S2FPacketSetSlot; -import common.packet.S30PacketWindowItems; -import common.packet.S31PacketWindowProperty; -import common.packet.S32PacketConfirmTransaction; -import common.packet.S33PacketUpdateSign; -import common.packet.S35PacketUpdateTileEntity; -import common.packet.S36PacketSignEditorOpen; -import common.packet.S38PacketPlayerListItem; -import common.packet.S39PacketPlayerAbilities; -import common.packet.S3APacketTabComplete; -import common.packet.S43PacketUpdateEntityNBT; +import common.packet.SPacketEntityRelMove; +import common.packet.SPacketEntityLook; +import common.packet.SPacketEntityLookMove; +import common.packet.SPacketEntity; +import common.packet.SPacketEntityTeleport; +import common.packet.SPacketEntityHeadLook; +import common.packet.SPacketEntityStatus; +import common.packet.SPacketEntityAttach; +import common.packet.SPacketEntityMetadata; +import common.packet.SPacketEntityEffect; +import common.packet.SPacketRemoveEntityEffect; +import common.packet.SPacketEntityProperties; +import common.packet.SPacketExplosion; +import common.packet.SPacketEffect; +import common.packet.SPacketSoundEffect; +import common.packet.SPacketParticles; +import common.packet.SPacketChangeGameState; +import common.packet.SPacketSpawnGlobalEntity; +import common.packet.SPacketOpenWindow; +import common.packet.SPacketCloseWindow; +import common.packet.SPacketSetSlot; +import common.packet.SPacketWindowItems; +import common.packet.SPacketWindowProperty; +import common.packet.SPacketConfirmTransaction; +import common.packet.SPacketUpdateSign; +import common.packet.SPacketUpdateTileEntity; +import common.packet.SPacketSignEditorOpen; +import common.packet.SPacketPlayerListItem; +import common.packet.SPacketPlayerAbilities; +import common.packet.SPacketTabComplete; +import common.packet.SPacketUpdateEntityNBT; import common.packet.SPacketAnimation; import common.packet.SPacketBiome; import common.packet.SPacketBlockAction; @@ -92,144 +97,122 @@ import common.packet.SPacketWorld; public enum PacketRegistry { - HANDSHAKE - { - { - this.client(HPacketHandshake.class); - } - }, - LOGIN - { - { - this.server(RPacketDisconnect.class); - this.server(RPacketRequestEncrypt.class); - this.server(RPacketLoginSuccess.class); - this.server(RPacketEnableCompression.class); - this.client(LPacketLogin.class); - this.client(LPacketStartEncrypt.class); - this.client(LPacketPasswordResponse.class); - } - }, - PLAY - { - { - this.server(SPacketKeepAlive.class); - this.server(SPacketJoinGame.class); - this.server(SPacketMessage.class); -// this.server(SPacketMessage.class); - this.server(SPacketTimeUpdate.class); - this.server(SPacketEntityEquipment.class); - this.server(SPacketUpdateHealth.class); - this.server(SPacketRespawn.class); - this.server(SPacketPlayerPosLook.class); - this.server(SPacketHeldItemChange.class); - this.server(SPacketAnimation.class); - this.server(SPacketSpawnPlayer.class); - this.server(SPacketCollectItem.class); - this.server(SPacketSpawnObject.class); - this.server(SPacketSpawnMob.class); -// this.server(SPacketSpawnPainting.class); -// this.server(SPacketSpawnExperienceOrb.class); - this.server(SPacketEntityVelocity.class); - this.server(SPacketDestroyEntities.class); - this.server(S14PacketEntity.class); - this.server(S14PacketEntity.S15PacketEntityRelMove.class); - this.server(S14PacketEntity.S16PacketEntityLook.class); - this.server(S14PacketEntity.S17PacketEntityLookMove.class); - this.server(S18PacketEntityTeleport.class); - this.server(S19PacketEntityHeadLook.class); - this.server(S1APacketEntityStatus.class); - this.server(S1BPacketEntityAttach.class); - this.server(S1CPacketEntityMetadata.class); - this.server(S1DPacketEntityEffect.class); - this.server(S1EPacketRemoveEntityEffect.class); - this.server(SPacketSetExperience.class); - this.server(S20PacketEntityProperties.class); - this.server(SPacketChunkData.class); - this.server(SPacketMultiBlockChange.class); - this.server(SPacketBlockChange.class); - this.server(SPacketBlockAction.class); - this.server(SPacketBlockBreakAnim.class); - this.server(SPacketMapChunkBulk.class); - this.server(S27PacketExplosion.class); - this.server(S28PacketEffect.class); - this.server(S29PacketSoundEffect.class); - this.server(S2APacketParticles.class); - this.server(S2BPacketChangeGameState.class); - this.server(S2CPacketSpawnGlobalEntity.class); - this.server(S2DPacketOpenWindow.class); - this.server(S2EPacketCloseWindow.class); - this.server(S2FPacketSetSlot.class); - this.server(S30PacketWindowItems.class); - this.server(S31PacketWindowProperty.class); - this.server(S32PacketConfirmTransaction.class); - this.server(S33PacketUpdateSign.class); -// this.server(S34PacketMaps.class); - this.server(S35PacketUpdateTileEntity.class); - this.server(S36PacketSignEditorOpen.class); -// this.server(S37PacketStatistics.class); - this.server(S38PacketPlayerListItem.class); - this.server(S39PacketPlayerAbilities.class); - this.server(S3APacketTabComplete.class); -// this.server(SPacketDisplay.class); - this.server(SPacketSkin.class); - this.server(SPacketDisconnect.class); - this.server(SPacketWorld.class); -// this.server(SPacketCapes.class); - this.server(SPacketCamera.class); - this.server(SPacketBiome.class); -// this.server(S42PacketTitle.class); - this.server(S43PacketUpdateEntityNBT.class); -// this.server(SPacketBook.class); - this.server(SPacketTrades.class); -// this.server(SPacketNotify.class); - this.server(SPacketDimensionName.class); - this.server(SPacketCharacterList.class); - this.server(SPacketServerTick.class); - this.server(SPacketLoading.class); - this.server(SPacketDisplayForm.class); - - this.client(CPacketKeepAlive.class); - this.client(CPacketMessage.class); - this.client(CPacketAction.class); - this.client(CPacketPlayer.class); - this.client(CPacketPlayer.C04PacketPlayerPosition.class); - this.client(CPacketPlayer.C05PacketPlayerLook.class); - this.client(CPacketPlayer.C06PacketPlayerPosLook.class); - this.client(CPacketBreak.class); - this.client(CPacketPlace.class); - this.client(CPacketInput.class); - this.client(CPacketClick.class); - this.client(CPacketCheat.class); - this.client(CPacketComplete.class); - this.client(CPacketSkin.class); - this.client(CPacketSign.class); - this.client(CPacketBook.class); - this.client(CPacketForm.class); - } - }; + HANDSHAKE {{ + this.client(HPacketHandshake.class); + }}, + LOGIN {{ + this.server(RPacketDisconnect.class); + this.server(RPacketRequestEncrypt.class); + this.server(RPacketLoginSuccess.class); + this.server(RPacketEnableCompression.class); + + this.client(LPacketLogin.class); + this.client(LPacketStartEncrypt.class); + this.client(LPacketPasswordResponse.class); + }}, + PLAY {{ + this.server(SPacketKeepAlive.class); + this.server(SPacketJoinGame.class); + this.server(SPacketMessage.class); + this.server(SPacketTimeUpdate.class); + this.server(SPacketEntityEquipment.class); + this.server(SPacketUpdateHealth.class); + this.server(SPacketRespawn.class); + this.server(SPacketPlayerPosLook.class); + this.server(SPacketHeldItemChange.class); + this.server(SPacketAnimation.class); + this.server(SPacketSpawnPlayer.class); + this.server(SPacketCollectItem.class); + this.server(SPacketSpawnObject.class); + this.server(SPacketSpawnMob.class); + this.server(SPacketEntityVelocity.class); + this.server(SPacketDestroyEntities.class); + this.server(SPacketEntity.class); + this.server(SPacketEntityRelMove.class); + this.server(SPacketEntityLook.class); + this.server(SPacketEntityLookMove.class); + this.server(SPacketEntityTeleport.class); + this.server(SPacketEntityHeadLook.class); + this.server(SPacketEntityStatus.class); + this.server(SPacketEntityAttach.class); + this.server(SPacketEntityMetadata.class); + this.server(SPacketEntityEffect.class); + this.server(SPacketRemoveEntityEffect.class); + this.server(SPacketSetExperience.class); + this.server(SPacketEntityProperties.class); + this.server(SPacketChunkData.class); + this.server(SPacketMultiBlockChange.class); + this.server(SPacketBlockChange.class); + this.server(SPacketBlockAction.class); + this.server(SPacketBlockBreakAnim.class); + this.server(SPacketMapChunkBulk.class); + this.server(SPacketExplosion.class); + this.server(SPacketEffect.class); + this.server(SPacketSoundEffect.class); + this.server(SPacketParticles.class); + this.server(SPacketChangeGameState.class); + this.server(SPacketSpawnGlobalEntity.class); + this.server(SPacketOpenWindow.class); + this.server(SPacketCloseWindow.class); + this.server(SPacketSetSlot.class); + this.server(SPacketWindowItems.class); + this.server(SPacketWindowProperty.class); + this.server(SPacketConfirmTransaction.class); + this.server(SPacketUpdateSign.class); + this.server(SPacketUpdateTileEntity.class); + this.server(SPacketSignEditorOpen.class); + this.server(SPacketPlayerListItem.class); + this.server(SPacketPlayerAbilities.class); + this.server(SPacketTabComplete.class); + this.server(SPacketSkin.class); + this.server(SPacketDisconnect.class); + this.server(SPacketWorld.class); + this.server(SPacketCamera.class); + this.server(SPacketBiome.class); + this.server(SPacketUpdateEntityNBT.class); + this.server(SPacketTrades.class); + this.server(SPacketDimensionName.class); + this.server(SPacketCharacterList.class); + this.server(SPacketServerTick.class); + this.server(SPacketLoading.class); + this.server(SPacketDisplayForm.class); + + this.client(CPacketKeepAlive.class); + this.client(CPacketMessage.class); + this.client(CPacketAction.class); + this.client(CPacketPlayer.class); + this.client(CPacketPlayerPosition.class); + this.client(CPacketPlayerLook.class); + this.client(CPacketPlayerPosLook.class); + this.client(CPacketBreak.class); + this.client(CPacketPlace.class); + this.client(CPacketInput.class); + this.client(CPacketClick.class); + this.client(CPacketCheat.class); + this.client(CPacketComplete.class); + this.client(CPacketSkin.class); + this.client(CPacketSign.class); + this.client(CPacketForm.class); + }}; private static final Map, PacketRegistry> STATES = Maps., PacketRegistry>newHashMap(); private final BiMap> server = HashBiMap.>create(); private final BiMap> client = HashBiMap.>create(); - protected void server(Class clazz) - { + protected void server(Class clazz) { if(this.server.containsValue(clazz)) throw new IllegalArgumentException("S-Paket " + clazz + " ist bereits bekannt unter ID " + this.server.inverse().get(clazz)); this.server.put(Integer.valueOf(this.server.size()), clazz); } - protected void client(Class clazz) - { + protected void client(Class clazz) { if(this.client.containsValue(clazz)) throw new IllegalArgumentException("C-Paket " + clazz + " ist bereits bekannt unter ID " + this.client.inverse().get(clazz)); this.client.put(Integer.valueOf(this.client.size()), clazz); } - public Integer getId(boolean client, Packet packet) - { + public Integer getId(boolean client, Packet packet) { return (client ? this.client : this.server).inverse().get(packet.getClass()); } @@ -238,19 +221,16 @@ public enum PacketRegistry return oclass == null ? null : oclass.newInstance(); } - public static PacketRegistry getType(Packet packetIn) - { - return STATES.get(packetIn.getClass()); + public static PacketRegistry getType(Packet packet) { + return STATES.get(packet.getClass()); } static { for(PacketRegistry reg : values()) { for(BiMap> map : new BiMap[] {reg.server, reg.client}) { for(Class clazz : map.values()) { - if(STATES.containsKey(clazz) && STATES.get(clazz) != reg) { - throw new Error("Paket " + clazz + " ist bereits zu ID " + STATES.get(clazz) - + " zugewiesen - kann nicht auf " + reg + " neu zuweisen"); - } + if(STATES.containsKey(clazz) && STATES.get(clazz) != reg) + throw new Error("Paket " + clazz + " ist bereits zu ID " + STATES.get(clazz) + " zugewiesen - kann nicht auf " + reg + " neu zuweisen"); try { clazz.newInstance(); } diff --git a/common/src/common/network/PacketSplitter.java b/common/src/common/network/PacketSplitter.java index 7540257..acb73d5 100755 --- a/common/src/common/network/PacketSplitter.java +++ b/common/src/common/network/PacketSplitter.java @@ -8,48 +8,32 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.handler.codec.CorruptedFrameException; -public class PacketSplitter extends ByteToMessageDecoder -{ - protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws Exception - { - p_decode_2_.markReaderIndex(); - byte[] abyte = new byte[3]; - - for (int i = 0; i < abyte.length; ++i) - { - if (!p_decode_2_.isReadable()) - { - p_decode_2_.resetReaderIndex(); - return; - } - - abyte[i] = p_decode_2_.readByte(); - - if (abyte[i] >= 0) - { - PacketBuffer packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(abyte)); - - try - { - int j = packetbuffer.readVarIntFromBuffer(); - - if (p_decode_2_.readableBytes() >= j) - { - p_decode_3_.add(p_decode_2_.readBytes(j)); - return; - } - - p_decode_2_.resetReaderIndex(); - } - finally - { - packetbuffer.release(); - } - - return; - } - } - - throw new CorruptedFrameException("length wider than 21-bit"); - } +public class PacketSplitter extends ByteToMessageDecoder { + protected void decode(ChannelHandlerContext context, ByteBuf buffer, List output) throws Exception { + buffer.markReaderIndex(); + byte[] data = new byte[3]; + for(int z = 0; z < data.length; z++) { + if(!buffer.isReadable()) { + buffer.resetReaderIndex(); + return; + } + data[z] = buffer.readByte(); + if(data[z] < 0) + continue; + PacketBuffer pbuf = new PacketBuffer(Unpooled.wrappedBuffer(data)); + try { + int len = pbuf.readVarInt(); + if(buffer.readableBytes() >= len) { + output.add(buffer.readBytes(len)); + return; + } + buffer.resetReaderIndex(); + } + finally { + pbuf.release(); + } + return; + } + throw new CorruptedFrameException("length wider than 21-bit"); + } } diff --git a/common/src/common/packet/APacketVarInt.java b/common/src/common/packet/APacketVarInt.java index e3196af..f68d407 100755 --- a/common/src/common/packet/APacketVarInt.java +++ b/common/src/common/packet/APacketVarInt.java @@ -16,11 +16,11 @@ public abstract class APacketVarInt implements Packet { } public final void readPacketData(PacketBuffer buf) throws IOException { - this.value = buf.readVarIntFromBuffer(); + this.value = buf.readVarInt(); } public final void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.value); + buf.writeVarInt(this.value); } public final int getValue() { diff --git a/common/src/common/packet/CPacketAction.java b/common/src/common/packet/CPacketAction.java index 1df60fb..39988f6 100755 --- a/common/src/common/packet/CPacketAction.java +++ b/common/src/common/packet/CPacketAction.java @@ -29,13 +29,13 @@ public class CPacketAction implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.action = buf.readEnumValue(Action.class); - this.auxData = buf.readVarIntFromBuffer(); + this.auxData = buf.readVarInt(); } public void writePacketData(PacketBuffer buf) throws IOException { buf.writeEnumValue(this.action); - buf.writeVarIntToBuffer(this.auxData); + buf.writeVarInt(this.auxData); } public void processPacket(IPlayer handler) diff --git a/common/src/common/packet/CPacketBook.java b/common/src/common/packet/CPacketBook.java deleted file mode 100755 index 771fa06..0000000 --- a/common/src/common/packet/CPacketBook.java +++ /dev/null @@ -1,52 +0,0 @@ -package common.packet; - -import java.io.IOException; - -import common.network.IPlayer; -import common.network.Packet; -import common.network.PacketBuffer; - -public class CPacketBook implements Packet -{ - private String[] pages; - - public CPacketBook() - { - } - - public CPacketBook(String[] pages) - { - this.pages = pages; - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - int pages = (int)buf.readByte(); - if(pages > 50) { - this.pages = new String[0]; - return; - } - this.pages = new String[pages]; - for(int z = 0; z < pages; z++) { - this.pages[z] = buf.readStringFromBuffer(1024); - } - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - buf.writeByte(this.pages.length); - for(int z = 0; z < this.pages.length; z++) { - buf.writeString(this.pages[z]); - } - } - - public void processPacket(IPlayer handler) - { - handler.processBook(this); - } - - public String[] getPages() - { - return this.pages; - } -} diff --git a/common/src/common/packet/CPacketCheat.java b/common/src/common/packet/CPacketCheat.java index f2b0715..2ce9395 100755 --- a/common/src/common/packet/CPacketCheat.java +++ b/common/src/common/packet/CPacketCheat.java @@ -30,13 +30,13 @@ public class CPacketCheat implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.stack = buf.readItemStackFromBuffer(); + this.stack = buf.readItemStack(); this.slot = buf.readByte(); } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeItemStackToBuffer(this.stack); + buf.writeItemStack(this.stack); buf.writeByte(this.slot); } diff --git a/common/src/common/packet/CPacketClick.java b/common/src/common/packet/CPacketClick.java index cb4e282..efdf80f 100755 --- a/common/src/common/packet/CPacketClick.java +++ b/common/src/common/packet/CPacketClick.java @@ -53,7 +53,7 @@ public class CPacketClick implements Packet this.usedButton = buf.readByte(); this.actionNumber = buf.readShort(); this.mode = buf.readByte(); - this.clickedItem = buf.readItemStackFromBuffer(); + this.clickedItem = buf.readItemStack(); } public void writePacketData(PacketBuffer buf) throws IOException @@ -63,7 +63,7 @@ public class CPacketClick implements Packet buf.writeByte(this.usedButton); buf.writeShort(this.actionNumber); buf.writeByte(this.mode); - buf.writeItemStackToBuffer(this.clickedItem); + buf.writeItemStack(this.clickedItem); } public int getWindowId() diff --git a/common/src/common/packet/CPacketComplete.java b/common/src/common/packet/CPacketComplete.java index 31b0cc6..83fd0f0 100755 --- a/common/src/common/packet/CPacketComplete.java +++ b/common/src/common/packet/CPacketComplete.java @@ -26,8 +26,8 @@ public class CPacketComplete implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.message = buf.readStringFromBuffer(32767); - this.entityId = buf.readVarIntFromBuffer(); + this.message = buf.readString(32767); + this.entityId = buf.readVarInt(); if(buf.readBoolean()) this.position = buf.readBlockPos(); } @@ -35,7 +35,7 @@ public class CPacketComplete implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeString(this.message.length() > 32767 ? this.message.substring(0, 32767) : this.message); - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeBoolean(this.position != null); if(this.position != null) buf.writeBlockPos(this.position); diff --git a/common/src/common/packet/CPacketForm.java b/common/src/common/packet/CPacketForm.java index 136fccc..127ddfb 100644 --- a/common/src/common/packet/CPacketForm.java +++ b/common/src/common/packet/CPacketForm.java @@ -23,12 +23,12 @@ public class CPacketForm implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.id = buf.readVarIntFromBuffer(); + this.id = buf.readVarInt(); if(!buf.readBoolean()) { this.data = null; return; } - this.data = new Object[buf.readVarIntFromBuffer()]; + this.data = new Object[buf.readVarInt()]; for(int z = 0; z < this.data.length; z++) { Object obj; switch(buf.readByte()) { @@ -36,10 +36,10 @@ public class CPacketForm implements Packet obj = buf.readBoolean(); break; case 1: - obj = buf.readVarIntFromBuffer(); + obj = buf.readVarInt(); break; default: - obj = buf.readStringFromBuffer(256); + obj = buf.readString(256); break; } this.data[z] = obj; @@ -48,11 +48,11 @@ public class CPacketForm implements Packet public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.id); + buf.writeVarInt(this.id); buf.writeBoolean(this.data != null); if(this.data == null) return; - buf.writeVarIntToBuffer(this.data.length); + buf.writeVarInt(this.data.length); for(int z = 0; z < this.data.length; z++) { Object obj = this.data[z]; if(obj instanceof Boolean) { @@ -61,7 +61,7 @@ public class CPacketForm implements Packet } else if(obj instanceof Integer) { buf.writeByte(1); - buf.writeVarIntToBuffer((Integer)obj); + buf.writeVarInt((Integer)obj); } else { buf.writeByte(2); diff --git a/common/src/common/packet/CPacketMessage.java b/common/src/common/packet/CPacketMessage.java index c7141ea..3b34e2d 100755 --- a/common/src/common/packet/CPacketMessage.java +++ b/common/src/common/packet/CPacketMessage.java @@ -24,7 +24,7 @@ public class CPacketMessage implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.type = buf.readEnumValue(Type.class); - this.message = buf.readStringFromBuffer(this.type.length); + this.message = buf.readString(this.type.length); } public void writePacketData(PacketBuffer buf) throws IOException diff --git a/common/src/common/packet/CPacketPlace.java b/common/src/common/packet/CPacketPlace.java index c082f6e..a2b8964 100755 --- a/common/src/common/packet/CPacketPlace.java +++ b/common/src/common/packet/CPacketPlace.java @@ -42,7 +42,7 @@ public class CPacketPlace implements Packet { this.position = buf.readBlockPos(); this.placedBlockDirection = buf.readUnsignedByte(); - this.stack = buf.readItemStackFromBuffer(); + this.stack = buf.readItemStack(); this.facingX = (float)buf.readUnsignedByte() / 16.0F; this.facingY = (float)buf.readUnsignedByte() / 16.0F; this.facingZ = (float)buf.readUnsignedByte() / 16.0F; @@ -52,7 +52,7 @@ public class CPacketPlace implements Packet { buf.writeBlockPos(this.position); buf.writeByte(this.placedBlockDirection); - buf.writeItemStackToBuffer(this.stack); + buf.writeItemStack(this.stack); buf.writeByte((int)(this.facingX * 16.0F)); buf.writeByte((int)(this.facingY * 16.0F)); buf.writeByte((int)(this.facingZ * 16.0F)); diff --git a/common/src/common/packet/CPacketPlayer.java b/common/src/common/packet/CPacketPlayer.java index 58c70e7..ccafdc3 100755 --- a/common/src/common/packet/CPacketPlayer.java +++ b/common/src/common/packet/CPacketPlayer.java @@ -85,108 +85,4 @@ public class CPacketPlayer implements Packet { this.moving = isMoving; } - - public static class C04PacketPlayerPosition extends CPacketPlayer - { - public C04PacketPlayerPosition() - { - this.moving = true; - } - - public C04PacketPlayerPosition(double posX, double posY, double posZ, boolean isOnGround) - { - this.x = posX; - this.y = posY; - this.z = posZ; - this.onGround = isOnGround; - this.moving = true; - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - this.x = buf.readDouble(); - this.y = buf.readDouble(); - this.z = buf.readDouble(); - super.readPacketData(buf); - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - buf.writeDouble(this.x); - buf.writeDouble(this.y); - buf.writeDouble(this.z); - super.writePacketData(buf); - } - } - - public static class C05PacketPlayerLook extends CPacketPlayer - { - public C05PacketPlayerLook() - { - this.rotating = true; - } - - public C05PacketPlayerLook(float playerYaw, float playerPitch, boolean isOnGround) - { - this.yaw = playerYaw; - this.pitch = playerPitch; - this.onGround = isOnGround; - this.rotating = true; - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - this.yaw = buf.readFloat(); - this.pitch = buf.readFloat(); - super.readPacketData(buf); - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - buf.writeFloat(this.yaw); - buf.writeFloat(this.pitch); - super.writePacketData(buf); - } - } - - public static class C06PacketPlayerPosLook extends CPacketPlayer - { - public C06PacketPlayerPosLook() - { - this.moving = true; - this.rotating = true; - } - - public C06PacketPlayerPosLook(double playerX, double playerY, double playerZ, float playerYaw, float playerPitch, boolean playerIsOnGround) - { - this.x = playerX; - this.y = playerY; - this.z = playerZ; - this.yaw = playerYaw; - this.pitch = playerPitch; - this.onGround = playerIsOnGround; - this.rotating = true; - this.moving = true; - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - this.x = buf.readDouble(); - this.y = buf.readDouble(); - this.z = buf.readDouble(); - this.yaw = buf.readFloat(); - this.pitch = buf.readFloat(); - super.readPacketData(buf); - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - buf.writeDouble(this.x); - buf.writeDouble(this.y); - buf.writeDouble(this.z); - buf.writeFloat(this.yaw); - buf.writeFloat(this.pitch); - super.writePacketData(buf); - } - } } diff --git a/common/src/common/packet/CPacketPlayerLook.java b/common/src/common/packet/CPacketPlayerLook.java new file mode 100644 index 0000000..47237f7 --- /dev/null +++ b/common/src/common/packet/CPacketPlayerLook.java @@ -0,0 +1,35 @@ +package common.packet; + +import java.io.IOException; + +import common.network.PacketBuffer; + +public class CPacketPlayerLook extends CPacketPlayer +{ + public CPacketPlayerLook() + { + this.rotating = true; + } + + public CPacketPlayerLook(float playerYaw, float playerPitch, boolean isOnGround) + { + this.yaw = playerYaw; + this.pitch = playerPitch; + this.onGround = isOnGround; + this.rotating = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + this.yaw = buf.readFloat(); + this.pitch = buf.readFloat(); + super.readPacketData(buf); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeFloat(this.yaw); + buf.writeFloat(this.pitch); + super.writePacketData(buf); + } +} \ No newline at end of file diff --git a/common/src/common/packet/CPacketPlayerPosLook.java b/common/src/common/packet/CPacketPlayerPosLook.java new file mode 100644 index 0000000..9b02b82 --- /dev/null +++ b/common/src/common/packet/CPacketPlayerPosLook.java @@ -0,0 +1,46 @@ +package common.packet; + +import java.io.IOException; + +import common.network.PacketBuffer; + +public class CPacketPlayerPosLook extends CPacketPlayer +{ + public CPacketPlayerPosLook() + { + this.moving = true; + this.rotating = true; + } + + public CPacketPlayerPosLook(double playerX, double playerY, double playerZ, float playerYaw, float playerPitch, boolean playerIsOnGround) + { + this.x = playerX; + this.y = playerY; + this.z = playerZ; + this.yaw = playerYaw; + this.pitch = playerPitch; + this.onGround = playerIsOnGround; + this.rotating = true; + this.moving = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + this.x = buf.readDouble(); + this.y = buf.readDouble(); + this.z = buf.readDouble(); + this.yaw = buf.readFloat(); + this.pitch = buf.readFloat(); + super.readPacketData(buf); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeDouble(this.x); + buf.writeDouble(this.y); + buf.writeDouble(this.z); + buf.writeFloat(this.yaw); + buf.writeFloat(this.pitch); + super.writePacketData(buf); + } +} \ No newline at end of file diff --git a/common/src/common/packet/CPacketPlayerPosition.java b/common/src/common/packet/CPacketPlayerPosition.java new file mode 100644 index 0000000..a82ad3e --- /dev/null +++ b/common/src/common/packet/CPacketPlayerPosition.java @@ -0,0 +1,38 @@ +package common.packet; + +import java.io.IOException; + +import common.network.PacketBuffer; + +public class CPacketPlayerPosition extends CPacketPlayer +{ + public CPacketPlayerPosition() + { + this.moving = true; + } + + public CPacketPlayerPosition(double posX, double posY, double posZ, boolean isOnGround) + { + this.x = posX; + this.y = posY; + this.z = posZ; + this.onGround = isOnGround; + this.moving = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + this.x = buf.readDouble(); + this.y = buf.readDouble(); + this.z = buf.readDouble(); + super.readPacketData(buf); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeDouble(this.x); + buf.writeDouble(this.y); + buf.writeDouble(this.z); + super.writePacketData(buf); + } +} \ No newline at end of file diff --git a/common/src/common/packet/CPacketSign.java b/common/src/common/packet/CPacketSign.java index 3653f78..9e01415 100755 --- a/common/src/common/packet/CPacketSign.java +++ b/common/src/common/packet/CPacketSign.java @@ -34,7 +34,7 @@ public class CPacketSign implements Packet for (int i = 0; i < 4; ++i) { - this.lines[i] = buf.readStringFromBuffer(50); + this.lines[i] = buf.readString(50); } } diff --git a/common/src/common/packet/CPacketSkin.java b/common/src/common/packet/CPacketSkin.java index 30e476c..d587918 100755 --- a/common/src/common/packet/CPacketSkin.java +++ b/common/src/common/packet/CPacketSkin.java @@ -29,7 +29,7 @@ public class CPacketSkin implements Packet { public void readPacketData(PacketBuffer buf) throws IOException { if(buf.readBoolean()) { this.texture = null; - this.character = buf.readStringFromBuffer(64); + this.character = buf.readString(64); } else { this.texture = buf.readByteArray(); diff --git a/common/src/common/packet/HPacketHandshake.java b/common/src/common/packet/HPacketHandshake.java index e2a0018..f94e44e 100755 --- a/common/src/common/packet/HPacketHandshake.java +++ b/common/src/common/packet/HPacketHandshake.java @@ -17,7 +17,7 @@ public class HPacketHandshake implements Packet { } public void readPacketData(PacketBuffer buf) throws IOException { - this.protocol = buf.readVarIntFromBuffer(); + this.protocol = buf.readVarInt(); int r = buf.readableBytes(); if(r > 0) { this.protocol = 0; @@ -27,7 +27,7 @@ public class HPacketHandshake implements Packet { } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.protocol); + buf.writeVarInt(this.protocol); } public void processPacket(IHandshakeHandler handler) { diff --git a/common/src/common/packet/LPacketLogin.java b/common/src/common/packet/LPacketLogin.java index 997d370..50c647d 100644 --- a/common/src/common/packet/LPacketLogin.java +++ b/common/src/common/packet/LPacketLogin.java @@ -10,7 +10,7 @@ public class LPacketLogin implements Packet { } public void readPacketData(PacketBuffer buf) throws IOException { - buf.readStringFromBuffer(16); + buf.readString(16); } public void writePacketData(PacketBuffer buf) throws IOException { diff --git a/common/src/common/packet/LPacketPasswordResponse.java b/common/src/common/packet/LPacketPasswordResponse.java index 073009c..60dc63c 100755 --- a/common/src/common/packet/LPacketPasswordResponse.java +++ b/common/src/common/packet/LPacketPasswordResponse.java @@ -29,9 +29,9 @@ public class LPacketPasswordResponse implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.user = buf.readStringFromBuffer(IPlayer.MAX_USER_LENGTH); - this.access = buf.readStringFromBuffer(IPlayer.MAX_PASS_LENGTH); - this.password = buf.readStringFromBuffer(IPlayer.MAX_PASS_LENGTH); + this.user = buf.readString(IPlayer.MAX_USER_LENGTH); + this.access = buf.readString(IPlayer.MAX_PASS_LENGTH); + this.password = buf.readString(IPlayer.MAX_PASS_LENGTH); } /** diff --git a/common/src/common/packet/RPacketDisconnect.java b/common/src/common/packet/RPacketDisconnect.java index 3e1c8cb..36f8aad 100755 --- a/common/src/common/packet/RPacketDisconnect.java +++ b/common/src/common/packet/RPacketDisconnect.java @@ -24,7 +24,7 @@ public class RPacketDisconnect implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.reason = buf.readStringFromBuffer(8192); + this.reason = buf.readString(8192); } /** diff --git a/common/src/common/packet/S14PacketEntity.java b/common/src/common/packet/S14PacketEntity.java deleted file mode 100755 index 68507af..0000000 --- a/common/src/common/packet/S14PacketEntity.java +++ /dev/null @@ -1,208 +0,0 @@ -package common.packet; - -import java.io.IOException; - -import common.entity.Entity; -import common.network.IClientPlayer; -import common.network.Packet; -import common.network.PacketBuffer; -import common.world.World; - -public class S14PacketEntity implements Packet -{ - protected int entityId; - protected byte posX; - protected byte posY; - protected byte posZ; - protected byte yaw; - protected byte pitch; - protected boolean onGround; - protected boolean rotation; - - public S14PacketEntity() - { - } - - public S14PacketEntity(int entityIdIn) - { - this.entityId = entityIdIn; - } - - /** - * Reads the raw packet data from the data stream. - */ - public void readPacketData(PacketBuffer buf) throws IOException - { - this.entityId = buf.readVarIntFromBuffer(); - } - - /** - * Writes the raw packet data to the data stream. - */ - public void writePacketData(PacketBuffer buf) throws IOException - { - buf.writeVarIntToBuffer(this.entityId); - } - - /** - * Passes this Packet on to the NetHandler for processing. - */ - public void processPacket(IClientPlayer handler) - { - handler.handleEntityMovement(this); - } - - public String toString() - { - return "Entity_" + super.toString(); - } - - public Entity getEntity(World worldIn) - { - return worldIn.getEntityByID(this.entityId); - } - - public byte getPosX() - { - return this.posX; - } - - public byte getPosY() - { - return this.posY; - } - - public byte getPosZ() - { - return this.posZ; - } - - public byte getYaw() - { - return this.yaw; - } - - public byte getPitch() - { - return this.pitch; - } - - public boolean hasRotations() - { - return this.rotation; - } - - public boolean getOnGround() - { - return this.onGround; - } - - public static class S15PacketEntityRelMove extends S14PacketEntity - { - public S15PacketEntityRelMove() - { - } - - public S15PacketEntityRelMove(int entityIdIn, byte x, byte y, byte z, boolean onGroundIn) - { - super(entityIdIn); - this.posX = x; - this.posY = y; - this.posZ = z; - this.onGround = onGroundIn; - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - super.readPacketData(buf); - this.posX = buf.readByte(); - this.posY = buf.readByte(); - this.posZ = buf.readByte(); - this.onGround = buf.readBoolean(); - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - super.writePacketData(buf); - buf.writeByte(this.posX); - buf.writeByte(this.posY); - buf.writeByte(this.posZ); - buf.writeBoolean(this.onGround); - } - } - - public static class S16PacketEntityLook extends S14PacketEntity - { - public S16PacketEntityLook() - { - this.rotation = true; - } - - public S16PacketEntityLook(int entityIdIn, byte yawIn, byte pitchIn, boolean onGroundIn) - { - super(entityIdIn); - this.yaw = yawIn; - this.pitch = pitchIn; - this.rotation = true; - this.onGround = onGroundIn; - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - super.readPacketData(buf); - this.yaw = buf.readByte(); - this.pitch = buf.readByte(); - this.onGround = buf.readBoolean(); - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - super.writePacketData(buf); - buf.writeByte(this.yaw); - buf.writeByte(this.pitch); - buf.writeBoolean(this.onGround); - } - } - - public static class S17PacketEntityLookMove extends S14PacketEntity - { - public S17PacketEntityLookMove() - { - this.rotation = true; - } - - public S17PacketEntityLookMove(int p_i45973_1_, byte p_i45973_2_, byte p_i45973_3_, byte p_i45973_4_, byte p_i45973_5_, byte p_i45973_6_, boolean p_i45973_7_) - { - super(p_i45973_1_); - this.posX = p_i45973_2_; - this.posY = p_i45973_3_; - this.posZ = p_i45973_4_; - this.yaw = p_i45973_5_; - this.pitch = p_i45973_6_; - this.onGround = p_i45973_7_; - this.rotation = true; - } - - public void readPacketData(PacketBuffer buf) throws IOException - { - super.readPacketData(buf); - this.posX = buf.readByte(); - this.posY = buf.readByte(); - this.posZ = buf.readByte(); - this.yaw = buf.readByte(); - this.pitch = buf.readByte(); - this.onGround = buf.readBoolean(); - } - - public void writePacketData(PacketBuffer buf) throws IOException - { - super.writePacketData(buf); - buf.writeByte(this.posX); - buf.writeByte(this.posY); - buf.writeByte(this.posZ); - buf.writeByte(this.yaw); - buf.writeByte(this.pitch); - buf.writeBoolean(this.onGround); - } - } -} diff --git a/common/src/common/packet/SPacketAnimation.java b/common/src/common/packet/SPacketAnimation.java index ad62a60..de8b50d 100755 --- a/common/src/common/packet/SPacketAnimation.java +++ b/common/src/common/packet/SPacketAnimation.java @@ -33,14 +33,14 @@ public class SPacketAnimation implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.type = buf.readUnsignedByte(); // this.par = buf.readVarIntFromBuffer(); } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeByte(this.type); // buf.writeVarIntToBuffer(this.par); } diff --git a/common/src/common/packet/SPacketBlockAction.java b/common/src/common/packet/SPacketBlockAction.java index 239d6eb..083cf7f 100755 --- a/common/src/common/packet/SPacketBlockAction.java +++ b/common/src/common/packet/SPacketBlockAction.java @@ -36,7 +36,7 @@ public class SPacketBlockAction implements Packet this.blockPosition = buf.readBlockPos(); this.instrument = buf.readUnsignedByte(); this.pitch = buf.readUnsignedByte(); - this.block = BlockRegistry.getBlockById(buf.readVarIntFromBuffer() & 4095); + this.block = BlockRegistry.getBlockById(buf.readVarInt() & 4095); } /** @@ -47,7 +47,7 @@ public class SPacketBlockAction implements Packet buf.writeBlockPos(this.blockPosition); buf.writeByte(this.instrument); buf.writeByte(this.pitch); - buf.writeVarIntToBuffer(BlockRegistry.getIdFromBlock(this.block) & 4095); + buf.writeVarInt(BlockRegistry.getIdFromBlock(this.block) & 4095); } /** diff --git a/common/src/common/packet/SPacketBlockBreakAnim.java b/common/src/common/packet/SPacketBlockBreakAnim.java index ccebc7e..1b1acec 100755 --- a/common/src/common/packet/SPacketBlockBreakAnim.java +++ b/common/src/common/packet/SPacketBlockBreakAnim.java @@ -29,7 +29,7 @@ public class SPacketBlockBreakAnim implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.breakerId = buf.readVarIntFromBuffer(); + this.breakerId = buf.readVarInt(); this.position = buf.readBlockPos(); this.progress = buf.readUnsignedByte(); } @@ -39,7 +39,7 @@ public class SPacketBlockBreakAnim implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.breakerId); + buf.writeVarInt(this.breakerId); buf.writeBlockPos(this.position); buf.writeByte(this.progress); } diff --git a/common/src/common/packet/SPacketBlockChange.java b/common/src/common/packet/SPacketBlockChange.java index 9ab2a01..ca79376 100755 --- a/common/src/common/packet/SPacketBlockChange.java +++ b/common/src/common/packet/SPacketBlockChange.java @@ -31,7 +31,7 @@ public class SPacketBlockChange implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.blockPosition = buf.readBlockPos(); - this.blockState = (State)BlockRegistry.STATEMAP.getByValue(buf.readVarIntFromBuffer()); + this.blockState = (State)BlockRegistry.STATEMAP.getByValue(buf.readVarInt()); } /** @@ -40,7 +40,7 @@ public class SPacketBlockChange implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeBlockPos(this.blockPosition); - buf.writeVarIntToBuffer(BlockRegistry.STATEMAP.get(this.blockState)); + buf.writeVarInt(BlockRegistry.STATEMAP.get(this.blockState)); } /** diff --git a/common/src/common/packet/SPacketCamera.java b/common/src/common/packet/SPacketCamera.java index 40edc45..d72765c 100755 --- a/common/src/common/packet/SPacketCamera.java +++ b/common/src/common/packet/SPacketCamera.java @@ -23,12 +23,12 @@ public class SPacketCamera implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); } public void processPacket(IClientPlayer handler) diff --git a/common/src/common/packet/S2BPacketChangeGameState.java b/common/src/common/packet/SPacketChangeGameState.java similarity index 76% rename from common/src/common/packet/S2BPacketChangeGameState.java rename to common/src/common/packet/SPacketChangeGameState.java index 488573a..2485d8a 100755 --- a/common/src/common/packet/S2BPacketChangeGameState.java +++ b/common/src/common/packet/SPacketChangeGameState.java @@ -7,26 +7,26 @@ import common.network.Packet; import common.network.PacketBuffer; import common.util.ExtMath; -public class S2BPacketChangeGameState implements Packet +public class SPacketChangeGameState implements Packet { private Action action; private int param; - public S2BPacketChangeGameState() + public SPacketChangeGameState() { } - public S2BPacketChangeGameState(Action action) + public SPacketChangeGameState(Action action) { this(action, 0); } - public S2BPacketChangeGameState(Action action, float param) + public SPacketChangeGameState(Action action, float param) { this(action, (int)(param * 1000.0f)); } - public S2BPacketChangeGameState(Action action, int param) + public SPacketChangeGameState(Action action, int param) { this.action = action; this.param = param; @@ -35,13 +35,13 @@ public class S2BPacketChangeGameState implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.action = buf.readEnumValue(Action.class); - this.param = buf.readVarIntFromBuffer(); + this.param = buf.readVarInt(); } public void writePacketData(PacketBuffer buf) throws IOException { buf.writeEnumValue(this.action); - buf.writeVarIntToBuffer(this.param); + buf.writeVarInt(this.param); } public void processPacket(IClientPlayer handler) diff --git a/common/src/common/packet/SPacketCharacterList.java b/common/src/common/packet/SPacketCharacterList.java index 8978d9d..c27e226 100644 --- a/common/src/common/packet/SPacketCharacterList.java +++ b/common/src/common/packet/SPacketCharacterList.java @@ -40,31 +40,31 @@ public class SPacketCharacterList implements Packet { } public void readPacketData(PacketBuffer buf) throws IOException { - int n = buf.readVarIntFromBuffer(); + int n = buf.readVarInt(); for(int z = 0; z < n; z++) { - int id = buf.readVarIntFromBuffer(); - String name = buf.readStringFromBuffer(IPlayer.MAX_NICK_LENGTH); + int id = buf.readVarInt(); + String name = buf.readString(IPlayer.MAX_NICK_LENGTH); if(name.isEmpty()) { this.players.put(id, null); continue; } - String info = buf.readStringFromBuffer(IPlayer.MAX_INFO_LENGTH); + String info = buf.readString(IPlayer.MAX_INFO_LENGTH); info = info.isEmpty() ? null : info; Alignment align = buf.readEnumValue(Alignment.class); - String dim = buf.readStringFromBuffer(256); + String dim = buf.readString(256); BlockPos pos = buf.readBlockPos(); - String type = buf.readStringFromBuffer(256); - int level = buf.readVarIntFromBuffer(); + String type = buf.readString(256); + int level = buf.readVarInt(); this.players.put(id, new PlayerCharacter(name, info, align, dim, pos, type, level)); } - this.selected = buf.readVarIntFromBuffer(); + this.selected = buf.readVarInt(); } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.players.size()); + buf.writeVarInt(this.players.size()); for(Entry data : this.players.entrySet()) { PlayerCharacter chr = data.getValue(); - buf.writeVarIntToBuffer(data.getKey()); + buf.writeVarInt(data.getKey()); if(chr == null) { buf.writeString(""); continue; @@ -75,9 +75,9 @@ public class SPacketCharacterList implements Packet { buf.writeString(chr.dim); buf.writeBlockPos(chr.pos); buf.writeString(chr.type); - buf.writeVarIntToBuffer(chr.level); + buf.writeVarInt(chr.level); } - buf.writeVarIntToBuffer(this.selected); + buf.writeVarInt(this.selected); } public void processPacket(IClientPlayer handler) { diff --git a/common/src/common/packet/SPacketChunkData.java b/common/src/common/packet/SPacketChunkData.java index 66438d6..3aac135 100755 --- a/common/src/common/packet/SPacketChunkData.java +++ b/common/src/common/packet/SPacketChunkData.java @@ -34,9 +34,9 @@ public class SPacketChunkData implements Packet this.biomes = buf.readBoolean(); this.extractedData = new SPacketChunkData.Extracted(); this.extractedData.data = buf.readByteArray(); - this.extractedData.extend = new int[buf.readVarIntFromBuffer()]; + this.extractedData.extend = new int[buf.readVarInt()]; for(int z = 0; z < this.extractedData.extend.length; z++) { - this.extractedData.extend[z] = buf.readVarIntFromBuffer(); + this.extractedData.extend[z] = buf.readVarInt(); } } @@ -49,9 +49,9 @@ public class SPacketChunkData implements Packet buf.writeInt(this.chunkZ); buf.writeBoolean(this.biomes); buf.writeByteArray(this.extractedData.data); - buf.writeVarIntToBuffer(this.extractedData.extend.length); + buf.writeVarInt(this.extractedData.extend.length); for(int z = 0; z < this.extractedData.extend.length; z++) { - buf.writeVarIntToBuffer(this.extractedData.extend[z]); + buf.writeVarInt(this.extractedData.extend[z]); } } diff --git a/common/src/common/packet/S2EPacketCloseWindow.java b/common/src/common/packet/SPacketCloseWindow.java similarity index 84% rename from common/src/common/packet/S2EPacketCloseWindow.java rename to common/src/common/packet/SPacketCloseWindow.java index 7629715..28b01f9 100755 --- a/common/src/common/packet/S2EPacketCloseWindow.java +++ b/common/src/common/packet/SPacketCloseWindow.java @@ -6,15 +6,15 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S2EPacketCloseWindow implements Packet +public class SPacketCloseWindow implements Packet { private int windowId; - public S2EPacketCloseWindow() + public SPacketCloseWindow() { } - public S2EPacketCloseWindow(int windowIdIn) + public SPacketCloseWindow(int windowIdIn) { this.windowId = windowIdIn; } diff --git a/common/src/common/packet/SPacketCollectItem.java b/common/src/common/packet/SPacketCollectItem.java index 4c0deb7..ea5d18f 100755 --- a/common/src/common/packet/SPacketCollectItem.java +++ b/common/src/common/packet/SPacketCollectItem.java @@ -26,8 +26,8 @@ public class SPacketCollectItem implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.collectedItemEntityId = buf.readVarIntFromBuffer(); - this.entityId = buf.readVarIntFromBuffer(); + this.collectedItemEntityId = buf.readVarInt(); + this.entityId = buf.readVarInt(); } /** @@ -35,8 +35,8 @@ public class SPacketCollectItem implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.collectedItemEntityId); - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.collectedItemEntityId); + buf.writeVarInt(this.entityId); } /** diff --git a/common/src/common/packet/S32PacketConfirmTransaction.java b/common/src/common/packet/SPacketConfirmTransaction.java similarity index 86% rename from common/src/common/packet/S32PacketConfirmTransaction.java rename to common/src/common/packet/SPacketConfirmTransaction.java index 2bf7c0f..e09cd3e 100755 --- a/common/src/common/packet/S32PacketConfirmTransaction.java +++ b/common/src/common/packet/SPacketConfirmTransaction.java @@ -6,17 +6,17 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S32PacketConfirmTransaction implements Packet +public class SPacketConfirmTransaction implements Packet { private int windowId; private short actionNumber; private boolean matching; - public S32PacketConfirmTransaction() + public SPacketConfirmTransaction() { } - public S32PacketConfirmTransaction(int windowIdIn, short actionNumberIn, boolean matching) + public SPacketConfirmTransaction(int windowIdIn, short actionNumberIn, boolean matching) { this.windowId = windowIdIn; this.actionNumber = actionNumberIn; diff --git a/common/src/common/packet/SPacketDestroyEntities.java b/common/src/common/packet/SPacketDestroyEntities.java index 9927461..aafef94 100755 --- a/common/src/common/packet/SPacketDestroyEntities.java +++ b/common/src/common/packet/SPacketDestroyEntities.java @@ -24,11 +24,11 @@ public class SPacketDestroyEntities implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityIDs = new int[buf.readVarIntFromBuffer()]; + this.entityIDs = new int[buf.readVarInt()]; for (int i = 0; i < this.entityIDs.length; ++i) { - this.entityIDs[i] = buf.readVarIntFromBuffer(); + this.entityIDs[i] = buf.readVarInt(); } } @@ -37,11 +37,11 @@ public class SPacketDestroyEntities implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityIDs.length); + buf.writeVarInt(this.entityIDs.length); for (int i = 0; i < this.entityIDs.length; ++i) { - buf.writeVarIntToBuffer(this.entityIDs[i]); + buf.writeVarInt(this.entityIDs[i]); } } diff --git a/common/src/common/packet/SPacketDimensionName.java b/common/src/common/packet/SPacketDimensionName.java index feb1c80..2523147 100755 --- a/common/src/common/packet/SPacketDimensionName.java +++ b/common/src/common/packet/SPacketDimensionName.java @@ -25,8 +25,8 @@ public class SPacketDimensionName implements Packet { } public void readPacketData(PacketBuffer buf) throws IOException { - this.fullName = buf.readStringFromBuffer(64); - this.customName = buf.readStringFromBuffer(64); + this.fullName = buf.readString(64); + this.customName = buf.readString(64); this.customName = this.customName.isEmpty() ? null : this.customName; } diff --git a/common/src/common/packet/SPacketDisconnect.java b/common/src/common/packet/SPacketDisconnect.java index 133acdc..f558fc0 100755 --- a/common/src/common/packet/SPacketDisconnect.java +++ b/common/src/common/packet/SPacketDisconnect.java @@ -17,7 +17,7 @@ public class SPacketDisconnect implements Packet { } public void readPacketData(PacketBuffer buf) throws IOException { - this.message = buf.readStringFromBuffer(2048); + this.message = buf.readString(2048); } public void writePacketData(PacketBuffer buf) throws IOException { diff --git a/common/src/common/packet/SPacketDisplayForm.java b/common/src/common/packet/SPacketDisplayForm.java index 372e8af..5128331 100644 --- a/common/src/common/packet/SPacketDisplayForm.java +++ b/common/src/common/packet/SPacketDisplayForm.java @@ -31,36 +31,36 @@ public class SPacketDisplayForm implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.id = buf.readVarIntFromBuffer(); - this.title = buf.readStringFromBuffer(256); - this.data = new Triplet[buf.readVarIntFromBuffer()]; + this.id = buf.readVarInt(); + this.title = buf.readString(256); + this.data = new Triplet[buf.readVarInt()]; for(int z = 0; z < this.data.length; z++) { - String name = buf.readStringFromBuffer(64); + String name = buf.readString(64); Object obj; switch(buf.readByte()) { case 0: obj = buf.readBoolean(); break; case 1: - String[] strs = new String[buf.readVarIntFromBuffer()]; + String[] strs = new String[buf.readVarInt()]; obj = strs; for(int n = 0; n < strs.length; n++) { - strs[n] = buf.readStringFromBuffer(128); + strs[n] = buf.readString(128); } break; default: - obj = buf.readStringFromBuffer(256); + obj = buf.readString(256); break; } - this.data[z] = new Triplet(name, obj, buf.readVarIntFromBuffer()); + this.data[z] = new Triplet(name, obj, buf.readVarInt()); } } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.id); + buf.writeVarInt(this.id); buf.writeString(this.title); - buf.writeVarIntToBuffer(this.data.length); + buf.writeVarInt(this.data.length); for(int z = 0; z < this.data.length; z++) { buf.writeString(this.data[z].first); Object obj = this.data[z].second; @@ -71,7 +71,7 @@ public class SPacketDisplayForm implements Packet else if(obj instanceof String[]) { buf.writeByte(1); String[] strs = (String[])obj; - buf.writeVarIntToBuffer(strs.length); + buf.writeVarInt(strs.length); for(int n = 0; n < strs.length; n++) { buf.writeString(strs[n]); } @@ -80,7 +80,7 @@ public class SPacketDisplayForm implements Packet buf.writeByte(2); buf.writeString((String)obj); } - buf.writeVarIntToBuffer(this.data[z].third); + buf.writeVarInt(this.data[z].third); } } diff --git a/common/src/common/packet/S28PacketEffect.java b/common/src/common/packet/SPacketEffect.java similarity index 84% rename from common/src/common/packet/S28PacketEffect.java rename to common/src/common/packet/SPacketEffect.java index cd826e2..9c81fb1 100755 --- a/common/src/common/packet/S28PacketEffect.java +++ b/common/src/common/packet/SPacketEffect.java @@ -7,15 +7,15 @@ import common.network.Packet; import common.network.PacketBuffer; import common.util.BlockPos; -public class S28PacketEffect implements Packet { +public class SPacketEffect implements Packet { private int soundType; private BlockPos soundPos; private int soundData; - public S28PacketEffect() { + public SPacketEffect() { } - public S28PacketEffect(int soundTypeIn, BlockPos soundPosIn, int soundDataIn) { + public SPacketEffect(int soundTypeIn, BlockPos soundPosIn, int soundDataIn) { this.soundType = soundTypeIn; this.soundPos = soundPosIn; this.soundData = soundDataIn; diff --git a/common/src/common/packet/SPacketEntity.java b/common/src/common/packet/SPacketEntity.java new file mode 100755 index 0000000..7b05088 --- /dev/null +++ b/common/src/common/packet/SPacketEntity.java @@ -0,0 +1,99 @@ +package common.packet; + +import java.io.IOException; + +import common.entity.Entity; +import common.network.IClientPlayer; +import common.network.Packet; +import common.network.PacketBuffer; +import common.world.World; + +public class SPacketEntity implements Packet +{ + protected int entityId; + protected byte posX; + protected byte posY; + protected byte posZ; + protected byte yaw; + protected byte pitch; + protected boolean onGround; + protected boolean rotation; + + public SPacketEntity() + { + } + + public SPacketEntity(int entityIdIn) + { + this.entityId = entityIdIn; + } + + /** + * Reads the raw packet data from the data stream. + */ + public void readPacketData(PacketBuffer buf) throws IOException + { + this.entityId = buf.readVarInt(); + } + + /** + * Writes the raw packet data to the data stream. + */ + public void writePacketData(PacketBuffer buf) throws IOException + { + buf.writeVarInt(this.entityId); + } + + /** + * Passes this Packet on to the NetHandler for processing. + */ + public void processPacket(IClientPlayer handler) + { + handler.handleEntityMovement(this); + } + + public String toString() + { + return "Entity_" + super.toString(); + } + + public Entity getEntity(World worldIn) + { + return worldIn.getEntityByID(this.entityId); + } + + public byte getPosX() + { + return this.posX; + } + + public byte getPosY() + { + return this.posY; + } + + public byte getPosZ() + { + return this.posZ; + } + + public byte getYaw() + { + return this.yaw; + } + + public byte getPitch() + { + return this.pitch; + } + + public boolean hasRotations() + { + return this.rotation; + } + + public boolean getOnGround() + { + return this.onGround; + } +} diff --git a/common/src/common/packet/S1BPacketEntityAttach.java b/common/src/common/packet/SPacketEntityAttach.java similarity index 88% rename from common/src/common/packet/S1BPacketEntityAttach.java rename to common/src/common/packet/SPacketEntityAttach.java index 24c0807..618311a 100755 --- a/common/src/common/packet/S1BPacketEntityAttach.java +++ b/common/src/common/packet/SPacketEntityAttach.java @@ -7,17 +7,17 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S1BPacketEntityAttach implements Packet +public class SPacketEntityAttach implements Packet { private int leash; private int entityId; private int vehicleEntityId; - public S1BPacketEntityAttach() + public SPacketEntityAttach() { } - public S1BPacketEntityAttach(int leashIn, Entity entityIn, Entity vehicle) + public SPacketEntityAttach(int leashIn, Entity entityIn, Entity vehicle) { this.leash = leashIn; this.entityId = entityIn.getId(); diff --git a/common/src/common/packet/S1DPacketEntityEffect.java b/common/src/common/packet/SPacketEntityEffect.java similarity index 77% rename from common/src/common/packet/S1DPacketEntityEffect.java rename to common/src/common/packet/SPacketEntityEffect.java index faf5dc6..ce38939 100755 --- a/common/src/common/packet/S1DPacketEntityEffect.java +++ b/common/src/common/packet/SPacketEntityEffect.java @@ -8,7 +8,7 @@ import common.network.PacketBuffer; import common.potion.Potion; import common.potion.PotionEffect; -public class S1DPacketEntityEffect implements Packet +public class SPacketEntityEffect implements Packet { private int entityId; private Potion effectId; @@ -17,11 +17,11 @@ public class S1DPacketEntityEffect implements Packet private int remaining; private boolean particles; - public S1DPacketEntityEffect() + public SPacketEntityEffect() { } - public S1DPacketEntityEffect(int entityIdIn, PotionEffect effect) + public SPacketEntityEffect(int entityIdIn, PotionEffect effect) { this.entityId = entityIdIn; this.effectId = effect.getPotion(); @@ -45,11 +45,11 @@ public class S1DPacketEntityEffect implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.effectId = buf.readEnumValue(Potion.class); - this.amplifier = buf.readVarIntFromBuffer(); - this.duration = buf.readVarIntFromBuffer(); - this.remaining = buf.readVarIntFromBuffer(); + this.amplifier = buf.readVarInt(); + this.duration = buf.readVarInt(); + this.remaining = buf.readVarInt(); this.particles = buf.readBoolean(); } @@ -58,11 +58,11 @@ public class S1DPacketEntityEffect implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeEnumValue(this.effectId); - buf.writeVarIntToBuffer(this.amplifier); - buf.writeVarIntToBuffer(this.duration); - buf.writeVarIntToBuffer(this.remaining); + buf.writeVarInt(this.amplifier); + buf.writeVarInt(this.duration); + buf.writeVarInt(this.remaining); buf.writeBoolean(this.particles); } diff --git a/common/src/common/packet/SPacketEntityEquipment.java b/common/src/common/packet/SPacketEntityEquipment.java index 0ee5fd8..8497508 100755 --- a/common/src/common/packet/SPacketEntityEquipment.java +++ b/common/src/common/packet/SPacketEntityEquipment.java @@ -29,9 +29,9 @@ public class SPacketEntityEquipment implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityID = buf.readVarIntFromBuffer(); + this.entityID = buf.readVarInt(); this.equipmentSlot = buf.readShort(); - this.itemStack = buf.readItemStackFromBuffer(); + this.itemStack = buf.readItemStack(); } /** @@ -39,9 +39,9 @@ public class SPacketEntityEquipment implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityID); + buf.writeVarInt(this.entityID); buf.writeShort(this.equipmentSlot); - buf.writeItemStackToBuffer(this.itemStack); + buf.writeItemStack(this.itemStack); } /** diff --git a/common/src/common/packet/S19PacketEntityHeadLook.java b/common/src/common/packet/SPacketEntityHeadLook.java similarity index 79% rename from common/src/common/packet/S19PacketEntityHeadLook.java rename to common/src/common/packet/SPacketEntityHeadLook.java index 885659e..76f5ddf 100755 --- a/common/src/common/packet/S19PacketEntityHeadLook.java +++ b/common/src/common/packet/SPacketEntityHeadLook.java @@ -8,16 +8,16 @@ import common.network.Packet; import common.network.PacketBuffer; import common.world.World; -public class S19PacketEntityHeadLook implements Packet +public class SPacketEntityHeadLook implements Packet { private int entityId; private byte yaw; - public S19PacketEntityHeadLook() + public SPacketEntityHeadLook() { } - public S19PacketEntityHeadLook(Entity entityIn, byte p_i45214_2_) + public SPacketEntityHeadLook(Entity entityIn, byte p_i45214_2_) { this.entityId = entityIn.getId(); this.yaw = p_i45214_2_; @@ -28,7 +28,7 @@ public class S19PacketEntityHeadLook implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.yaw = buf.readByte(); } @@ -37,7 +37,7 @@ public class S19PacketEntityHeadLook implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeByte(this.yaw); } diff --git a/common/src/common/packet/SPacketEntityLook.java b/common/src/common/packet/SPacketEntityLook.java new file mode 100644 index 0000000..e9ffbb0 --- /dev/null +++ b/common/src/common/packet/SPacketEntityLook.java @@ -0,0 +1,38 @@ +package common.packet; + +import java.io.IOException; + +import common.network.PacketBuffer; + +public class SPacketEntityLook extends SPacketEntity +{ + public SPacketEntityLook() + { + this.rotation = true; + } + + public SPacketEntityLook(int entityIdIn, byte yawIn, byte pitchIn, boolean onGroundIn) + { + super(entityIdIn); + this.yaw = yawIn; + this.pitch = pitchIn; + this.rotation = true; + this.onGround = onGroundIn; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + super.readPacketData(buf); + this.yaw = buf.readByte(); + this.pitch = buf.readByte(); + this.onGround = buf.readBoolean(); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + super.writePacketData(buf); + buf.writeByte(this.yaw); + buf.writeByte(this.pitch); + buf.writeBoolean(this.onGround); + } +} \ No newline at end of file diff --git a/common/src/common/packet/SPacketEntityLookMove.java b/common/src/common/packet/SPacketEntityLookMove.java new file mode 100644 index 0000000..878aa46 --- /dev/null +++ b/common/src/common/packet/SPacketEntityLookMove.java @@ -0,0 +1,47 @@ +package common.packet; + +import java.io.IOException; + +import common.network.PacketBuffer; + +public class SPacketEntityLookMove extends SPacketEntity +{ + public SPacketEntityLookMove() + { + this.rotation = true; + } + + public SPacketEntityLookMove(int p_i45973_1_, byte p_i45973_2_, byte p_i45973_3_, byte p_i45973_4_, byte p_i45973_5_, byte p_i45973_6_, boolean p_i45973_7_) + { + super(p_i45973_1_); + this.posX = p_i45973_2_; + this.posY = p_i45973_3_; + this.posZ = p_i45973_4_; + this.yaw = p_i45973_5_; + this.pitch = p_i45973_6_; + this.onGround = p_i45973_7_; + this.rotation = true; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + super.readPacketData(buf); + this.posX = buf.readByte(); + this.posY = buf.readByte(); + this.posZ = buf.readByte(); + this.yaw = buf.readByte(); + this.pitch = buf.readByte(); + this.onGround = buf.readBoolean(); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + super.writePacketData(buf); + buf.writeByte(this.posX); + buf.writeByte(this.posY); + buf.writeByte(this.posZ); + buf.writeByte(this.yaw); + buf.writeByte(this.pitch); + buf.writeBoolean(this.onGround); + } +} \ No newline at end of file diff --git a/common/src/common/packet/S1CPacketEntityMetadata.java b/common/src/common/packet/SPacketEntityMetadata.java similarity index 82% rename from common/src/common/packet/S1CPacketEntityMetadata.java rename to common/src/common/packet/SPacketEntityMetadata.java index 645e1a2..fc748e1 100755 --- a/common/src/common/packet/S1CPacketEntityMetadata.java +++ b/common/src/common/packet/SPacketEntityMetadata.java @@ -8,16 +8,16 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S1CPacketEntityMetadata implements Packet +public class SPacketEntityMetadata implements Packet { private int entityId; private List field_149378_b; - public S1CPacketEntityMetadata() + public SPacketEntityMetadata() { } - public S1CPacketEntityMetadata(int entityIdIn, DataWatcher p_i45217_2_, boolean p_i45217_3_) + public SPacketEntityMetadata(int entityIdIn, DataWatcher p_i45217_2_, boolean p_i45217_3_) { this.entityId = entityIdIn; @@ -36,7 +36,7 @@ public class S1CPacketEntityMetadata implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.field_149378_b = DataWatcher.readWatchedListFromPacketBuffer(buf); } @@ -45,7 +45,7 @@ public class S1CPacketEntityMetadata implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); DataWatcher.writeWatchedListToPacketBuffer(this.field_149378_b, buf); } diff --git a/common/src/common/packet/S20PacketEntityProperties.java b/common/src/common/packet/SPacketEntityProperties.java similarity index 72% rename from common/src/common/packet/S20PacketEntityProperties.java rename to common/src/common/packet/SPacketEntityProperties.java index f3ca49a..2c6c11f 100755 --- a/common/src/common/packet/S20PacketEntityProperties.java +++ b/common/src/common/packet/SPacketEntityProperties.java @@ -11,22 +11,22 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S20PacketEntityProperties implements Packet +public class SPacketEntityProperties implements Packet { private int entityId; - private final List field_149444_b = Lists.newArrayList(); + private final List field_149444_b = Lists.newArrayList(); - public S20PacketEntityProperties() + public SPacketEntityProperties() { } - public S20PacketEntityProperties(int entityIdIn, Collection p_i45236_2_) + public SPacketEntityProperties(int entityIdIn, Collection p_i45236_2_) { this.entityId = entityIdIn; for (AttributeInstance iattributeinstance : p_i45236_2_) { - this.field_149444_b.add(new S20PacketEntityProperties.Snapshot(iattributeinstance.getAttribute().getUnlocalizedName(), iattributeinstance.getBaseValue(), iattributeinstance.getModifiers())); + this.field_149444_b.add(new SPacketEntityProperties.Snapshot(iattributeinstance.getAttribute().getUnlocalizedName(), iattributeinstance.getBaseValue(), iattributeinstance.getModifiers())); } } @@ -35,15 +35,15 @@ public class S20PacketEntityProperties implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); int i = buf.readInt(); for (int j = 0; j < i; ++j) { - String s = buf.readStringFromBuffer(64); + String s = buf.readString(64); double d0 = buf.readDouble(); List list = Lists.newArrayList(); - int k = buf.readVarIntFromBuffer(); + int k = buf.readVarInt(); for (int l = 0; l < k; ++l) { @@ -51,7 +51,7 @@ public class S20PacketEntityProperties implements Packet list.add(new AttributeModifier(id, "Unknown synced attribute modifier", buf.readDouble(), buf.readBoolean())); } - this.field_149444_b.add(new S20PacketEntityProperties.Snapshot(s, d0, list)); + this.field_149444_b.add(new SPacketEntityProperties.Snapshot(s, d0, list)); } } @@ -60,14 +60,14 @@ public class S20PacketEntityProperties implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeInt(this.field_149444_b.size()); - for (S20PacketEntityProperties.Snapshot s20packetentityproperties$snapshot : this.field_149444_b) + for (SPacketEntityProperties.Snapshot s20packetentityproperties$snapshot : this.field_149444_b) { buf.writeString(s20packetentityproperties$snapshot.func_151409_a()); buf.writeDouble(s20packetentityproperties$snapshot.func_151410_b()); - buf.writeVarIntToBuffer(s20packetentityproperties$snapshot.func_151408_c().size()); + buf.writeVarInt(s20packetentityproperties$snapshot.func_151408_c().size()); for (AttributeModifier attributemodifier : s20packetentityproperties$snapshot.func_151408_c()) { @@ -91,7 +91,7 @@ public class S20PacketEntityProperties implements Packet return this.entityId; } - public List func_149441_d() + public List func_149441_d() { return this.field_149444_b; } diff --git a/common/src/common/packet/SPacketEntityRelMove.java b/common/src/common/packet/SPacketEntityRelMove.java new file mode 100644 index 0000000..4c5a9fa --- /dev/null +++ b/common/src/common/packet/SPacketEntityRelMove.java @@ -0,0 +1,39 @@ +package common.packet; + +import java.io.IOException; + +import common.network.PacketBuffer; + +public class SPacketEntityRelMove extends SPacketEntity +{ + public SPacketEntityRelMove() + { + } + + public SPacketEntityRelMove(int entityIdIn, byte x, byte y, byte z, boolean onGroundIn) + { + super(entityIdIn); + this.posX = x; + this.posY = y; + this.posZ = z; + this.onGround = onGroundIn; + } + + public void readPacketData(PacketBuffer buf) throws IOException + { + super.readPacketData(buf); + this.posX = buf.readByte(); + this.posY = buf.readByte(); + this.posZ = buf.readByte(); + this.onGround = buf.readBoolean(); + } + + public void writePacketData(PacketBuffer buf) throws IOException + { + super.writePacketData(buf); + buf.writeByte(this.posX); + buf.writeByte(this.posY); + buf.writeByte(this.posZ); + buf.writeBoolean(this.onGround); + } +} \ No newline at end of file diff --git a/common/src/common/packet/S1APacketEntityStatus.java b/common/src/common/packet/SPacketEntityStatus.java similarity index 87% rename from common/src/common/packet/S1APacketEntityStatus.java rename to common/src/common/packet/SPacketEntityStatus.java index 1775cec..6c201c1 100755 --- a/common/src/common/packet/S1APacketEntityStatus.java +++ b/common/src/common/packet/SPacketEntityStatus.java @@ -8,16 +8,16 @@ import common.network.Packet; import common.network.PacketBuffer; import common.world.World; -public class S1APacketEntityStatus implements Packet +public class SPacketEntityStatus implements Packet { private int entityId; private byte logicOpcode; - public S1APacketEntityStatus() + public SPacketEntityStatus() { } - public S1APacketEntityStatus(Entity entityIn, byte opCodeIn) + public SPacketEntityStatus(Entity entityIn, byte opCodeIn) { this.entityId = entityIn.getId(); this.logicOpcode = opCodeIn; diff --git a/common/src/common/packet/S18PacketEntityTeleport.java b/common/src/common/packet/SPacketEntityTeleport.java similarity index 86% rename from common/src/common/packet/S18PacketEntityTeleport.java rename to common/src/common/packet/SPacketEntityTeleport.java index 67f4118..204fa21 100755 --- a/common/src/common/packet/S18PacketEntityTeleport.java +++ b/common/src/common/packet/SPacketEntityTeleport.java @@ -8,7 +8,7 @@ import common.network.Packet; import common.network.PacketBuffer; import common.util.ExtMath; -public class S18PacketEntityTeleport implements Packet +public class SPacketEntityTeleport implements Packet { private int entityId; private int posX; @@ -18,11 +18,11 @@ public class S18PacketEntityTeleport implements Packet private byte pitch; private boolean onGround; - public S18PacketEntityTeleport() + public SPacketEntityTeleport() { } - public S18PacketEntityTeleport(Entity entityIn) + public SPacketEntityTeleport(Entity entityIn) { this.entityId = entityIn.getId(); this.posX = ExtMath.floord(entityIn.posX * 32.0D); @@ -33,7 +33,7 @@ public class S18PacketEntityTeleport implements Packet this.onGround = entityIn.onGround; } - public S18PacketEntityTeleport(int entityIdIn, int posXIn, int posYIn, int posZIn, byte yawIn, byte pitchIn, boolean onGroundIn) + public SPacketEntityTeleport(int entityIdIn, int posXIn, int posYIn, int posZIn, byte yawIn, byte pitchIn, boolean onGroundIn) { this.entityId = entityIdIn; this.posX = posXIn; @@ -49,7 +49,7 @@ public class S18PacketEntityTeleport implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.posX = buf.readInt(); this.posY = buf.readInt(); this.posZ = buf.readInt(); @@ -63,7 +63,7 @@ public class S18PacketEntityTeleport implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeInt(this.posX); buf.writeInt(this.posY); buf.writeInt(this.posZ); diff --git a/common/src/common/packet/SPacketEntityVelocity.java b/common/src/common/packet/SPacketEntityVelocity.java index 8b6520c..60818b0 100755 --- a/common/src/common/packet/SPacketEntityVelocity.java +++ b/common/src/common/packet/SPacketEntityVelocity.java @@ -68,7 +68,7 @@ public class SPacketEntityVelocity implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityID = buf.readVarIntFromBuffer(); + this.entityID = buf.readVarInt(); this.motionX = buf.readShort(); this.motionY = buf.readShort(); this.motionZ = buf.readShort(); @@ -79,7 +79,7 @@ public class SPacketEntityVelocity implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityID); + buf.writeVarInt(this.entityID); buf.writeShort(this.motionX); buf.writeShort(this.motionY); buf.writeShort(this.motionZ); diff --git a/common/src/common/packet/S27PacketExplosion.java b/common/src/common/packet/SPacketExplosion.java similarity index 93% rename from common/src/common/packet/S27PacketExplosion.java rename to common/src/common/packet/SPacketExplosion.java index 85f90ee..d9fa7cf 100755 --- a/common/src/common/packet/S27PacketExplosion.java +++ b/common/src/common/packet/SPacketExplosion.java @@ -11,7 +11,7 @@ import common.network.PacketBuffer; import common.util.BlockPos; import common.util.Vec3; -public class S27PacketExplosion implements Packet +public class SPacketExplosion implements Packet { private double posX; private double posY; @@ -23,11 +23,11 @@ public class S27PacketExplosion implements Packet private float field_149159_h; private boolean altSound; - public S27PacketExplosion() + public SPacketExplosion() { } - public S27PacketExplosion(double p_i45193_1_, double y, double z, float strengthIn, List affectedBlocksIn, Vec3 p_i45193_9_, boolean altSound) + public SPacketExplosion(double p_i45193_1_, double y, double z, float strengthIn, List affectedBlocksIn, Vec3 p_i45193_9_, boolean altSound) { this.posX = p_i45193_1_; this.posY = y; diff --git a/common/src/common/packet/SPacketJoinGame.java b/common/src/common/packet/SPacketJoinGame.java index 1f452fd..ffef6cc 100755 --- a/common/src/common/packet/SPacketJoinGame.java +++ b/common/src/common/packet/SPacketJoinGame.java @@ -26,14 +26,14 @@ public class SPacketJoinGame implements Packet { public void readPacketData(PacketBuffer buf) throws IOException { this.entityId = buf.readInt(); - this.dimension = buf.readNBTTagCompoundFromBuffer(); + this.dimension = buf.readTag(); this.type = buf.readUnsignedShort(); this.editor = buf.readBoolean(); } public void writePacketData(PacketBuffer buf) throws IOException { buf.writeInt(this.entityId); - buf.writeNBTTagCompoundToBuffer(this.dimension); + buf.writeTag(this.dimension); buf.writeShort(this.type & 65535); buf.writeBoolean(this.editor); } diff --git a/common/src/common/packet/SPacketLoading.java b/common/src/common/packet/SPacketLoading.java index 4daa761..2a090f9 100644 --- a/common/src/common/packet/SPacketLoading.java +++ b/common/src/common/packet/SPacketLoading.java @@ -29,10 +29,10 @@ public class SPacketLoading implements Packet { } public void readPacketData(PacketBuffer buf) throws IOException { - this.message = buf.readStringFromBuffer(128); + this.message = buf.readString(128); this.message = this.message != null && this.message.isEmpty() ? null : this.message; if(this.message == null) { - this.task = buf.readStringFromBuffer(128); + this.task = buf.readString(128); this.task = this.task != null && this.task.isEmpty() ? null : this.task; this.total = buf.readInt(); this.progress = buf.readInt(); diff --git a/common/src/common/packet/SPacketMapChunkBulk.java b/common/src/common/packet/SPacketMapChunkBulk.java index 4ba19d2..8adceef 100755 --- a/common/src/common/packet/SPacketMapChunkBulk.java +++ b/common/src/common/packet/SPacketMapChunkBulk.java @@ -30,7 +30,7 @@ public class SPacketMapChunkBulk implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.sky = buf.readBoolean(); - int i = buf.readVarIntFromBuffer(); + int i = buf.readVarInt(); this.xPositions = new int[i]; this.zPositions = new int[i]; this.chunksData = new SPacketChunkData.Extracted[i]; @@ -40,9 +40,9 @@ public class SPacketMapChunkBulk implements Packet this.xPositions[j] = buf.readInt(); this.zPositions[j] = buf.readInt(); this.chunksData[j] = new SPacketChunkData.Extracted(); - this.chunksData[j].extend = new int[buf.readVarIntFromBuffer()]; + this.chunksData[j].extend = new int[buf.readVarInt()]; for(int z = 0; z < this.chunksData[j].extend.length; z++) { - this.chunksData[j].extend[z] = buf.readVarIntFromBuffer(); + this.chunksData[j].extend[z] = buf.readVarInt(); } this.chunksData[j].data = new byte[SPacketChunkData.getSize(this.chunksData[j].extend.length, this.sky, true)]; } @@ -59,15 +59,15 @@ public class SPacketMapChunkBulk implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeBoolean(this.sky); - buf.writeVarIntToBuffer(this.chunksData.length); + buf.writeVarInt(this.chunksData.length); for (int i = 0; i < this.xPositions.length; ++i) { buf.writeInt(this.xPositions[i]); buf.writeInt(this.zPositions[i]); - buf.writeVarIntToBuffer(this.chunksData[i].extend.length); + buf.writeVarInt(this.chunksData[i].extend.length); for(int z = 0; z < this.chunksData[i].extend.length; z++) { - buf.writeVarIntToBuffer(this.chunksData[i].extend[z]); + buf.writeVarInt(this.chunksData[i].extend[z]); } } diff --git a/common/src/common/packet/SPacketMessage.java b/common/src/common/packet/SPacketMessage.java index 3832c29..4b72178 100755 --- a/common/src/common/packet/SPacketMessage.java +++ b/common/src/common/packet/SPacketMessage.java @@ -23,7 +23,7 @@ public class SPacketMessage implements Packet { } public void readPacketData(PacketBuffer buf) throws IOException { - this.message = buf.readStringFromBuffer(32767); + this.message = buf.readString(32767); this.type = buf.readEnumValue(Type.class); } diff --git a/common/src/common/packet/SPacketMultiBlockChange.java b/common/src/common/packet/SPacketMultiBlockChange.java index 6694b98..df86ebb 100755 --- a/common/src/common/packet/SPacketMultiBlockChange.java +++ b/common/src/common/packet/SPacketMultiBlockChange.java @@ -35,11 +35,11 @@ public class SPacketMultiBlockChange implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.chunkPosCoord = new ChunkPos(buf.readInt(), buf.readInt()); - this.changedBlocks = new SPacketMultiBlockChange.BlockUpdateData[buf.readVarIntFromBuffer()]; + this.changedBlocks = new SPacketMultiBlockChange.BlockUpdateData[buf.readVarInt()]; for (int i = 0; i < this.changedBlocks.length; ++i) { - this.changedBlocks[i] = new SPacketMultiBlockChange.BlockUpdateData(buf.readLong(), (State)BlockRegistry.STATEMAP.getByValue(buf.readVarIntFromBuffer())); + this.changedBlocks[i] = new SPacketMultiBlockChange.BlockUpdateData(buf.readLong(), (State)BlockRegistry.STATEMAP.getByValue(buf.readVarInt())); } } @@ -50,12 +50,12 @@ public class SPacketMultiBlockChange implements Packet { buf.writeInt(this.chunkPosCoord.x); buf.writeInt(this.chunkPosCoord.z); - buf.writeVarIntToBuffer(this.changedBlocks.length); + buf.writeVarInt(this.changedBlocks.length); for (SPacketMultiBlockChange.BlockUpdateData s22packetmultiblockchange$blockupdatedata : this.changedBlocks) { buf.writeLong(s22packetmultiblockchange$blockupdatedata.getRawPos()); - buf.writeVarIntToBuffer(BlockRegistry.STATEMAP.get(s22packetmultiblockchange$blockupdatedata.getBlockState())); + buf.writeVarInt(BlockRegistry.STATEMAP.get(s22packetmultiblockchange$blockupdatedata.getBlockState())); } } diff --git a/common/src/common/packet/S2DPacketOpenWindow.java b/common/src/common/packet/SPacketOpenWindow.java similarity index 79% rename from common/src/common/packet/S2DPacketOpenWindow.java rename to common/src/common/packet/SPacketOpenWindow.java index 6fb2370..c66e944 100755 --- a/common/src/common/packet/S2DPacketOpenWindow.java +++ b/common/src/common/packet/SPacketOpenWindow.java @@ -7,7 +7,7 @@ import common.network.Packet; import common.network.PacketBuffer; import common.util.BlockPos; -public class S2DPacketOpenWindow implements Packet +public class SPacketOpenWindow implements Packet { private int windowId; private String inventoryType; @@ -16,16 +16,16 @@ public class S2DPacketOpenWindow implements Packet private int entityId; private BlockPos tilePos; - public S2DPacketOpenWindow() + public SPacketOpenWindow() { } - public S2DPacketOpenWindow(int incomingWindowId, String incomingWindowTitle, String windowTitleIn) + public SPacketOpenWindow(int incomingWindowId, String incomingWindowTitle, String windowTitleIn) { this(incomingWindowId, incomingWindowTitle, windowTitleIn, 0); } - public S2DPacketOpenWindow(int windowIdIn, String guiId, String windowTitleIn, int slotCountIn) + public SPacketOpenWindow(int windowIdIn, String guiId, String windowTitleIn, int slotCountIn) { this.windowId = windowIdIn; this.inventoryType = guiId; @@ -33,13 +33,13 @@ public class S2DPacketOpenWindow implements Packet this.slotCount = slotCountIn; } - public S2DPacketOpenWindow(int windowIdIn, String guiId, String windowTitleIn, int slotCountIn, int incomingEntityId) + public SPacketOpenWindow(int windowIdIn, String guiId, String windowTitleIn, int slotCountIn, int incomingEntityId) { this(windowIdIn, guiId, windowTitleIn, slotCountIn); this.entityId = incomingEntityId; } - public S2DPacketOpenWindow(int windowIdIn, String guiId, String windowTitleIn, int slotCountIn, BlockPos incomingTilePos) + public SPacketOpenWindow(int windowIdIn, String guiId, String windowTitleIn, int slotCountIn, BlockPos incomingTilePos) { this(windowIdIn, guiId, windowTitleIn, slotCountIn); this.tilePos = incomingTilePos; @@ -59,8 +59,8 @@ public class S2DPacketOpenWindow implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.windowId = buf.readUnsignedByte(); - this.inventoryType = buf.readStringFromBuffer(32); - this.windowTitle = buf.readStringFromBuffer(256); + this.inventoryType = buf.readString(32); + this.windowTitle = buf.readString(256); this.slotCount = buf.readUnsignedByte(); if (this.inventoryType.equals("EntityHorse")) diff --git a/common/src/common/packet/S2APacketParticles.java b/common/src/common/packet/SPacketParticles.java similarity index 90% rename from common/src/common/packet/S2APacketParticles.java rename to common/src/common/packet/SPacketParticles.java index 0d6329c..f2fd4ba 100755 --- a/common/src/common/packet/S2APacketParticles.java +++ b/common/src/common/packet/SPacketParticles.java @@ -7,7 +7,7 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S2APacketParticles implements Packet +public class SPacketParticles implements Packet { private ParticleType particleType; private float xCoord; @@ -25,11 +25,11 @@ public class S2APacketParticles implements Packet */ private int[] particleArguments; - public S2APacketParticles() + public SPacketParticles() { } - public S2APacketParticles(ParticleType particleTypeIn, boolean longDistanceIn, float x, float y, float z, float xOffsetIn, float yOffset, float zOffset, float particleSpeedIn, int particleCountIn, int[] particleArgumentsIn) + public SPacketParticles(ParticleType particleTypeIn, boolean longDistanceIn, float x, float y, float z, float xOffsetIn, float yOffset, float zOffset, float particleSpeedIn, int particleCountIn, int[] particleArgumentsIn) { this.particleType = particleTypeIn; this.longDistance = longDistanceIn; @@ -70,7 +70,7 @@ public class S2APacketParticles implements Packet for (int j = 0; j < i; ++j) { - this.particleArguments[j] = buf.readVarIntFromBuffer(); + this.particleArguments[j] = buf.readVarInt(); } } @@ -93,7 +93,7 @@ public class S2APacketParticles implements Packet for (int j = 0; j < i; ++j) { - buf.writeVarIntToBuffer(this.particleArguments[j]); + buf.writeVarInt(this.particleArguments[j]); } } diff --git a/common/src/common/packet/S39PacketPlayerAbilities.java b/common/src/common/packet/SPacketPlayerAbilities.java similarity index 84% rename from common/src/common/packet/S39PacketPlayerAbilities.java rename to common/src/common/packet/SPacketPlayerAbilities.java index 24f0537..d7b7d34 100755 --- a/common/src/common/packet/S39PacketPlayerAbilities.java +++ b/common/src/common/packet/SPacketPlayerAbilities.java @@ -7,14 +7,14 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S39PacketPlayerAbilities implements Packet { +public class SPacketPlayerAbilities implements Packet { private boolean flying; private boolean noClip; - public S39PacketPlayerAbilities() { + public SPacketPlayerAbilities() { } - public S39PacketPlayerAbilities(EntityNPC capabilities) { + public SPacketPlayerAbilities(EntityNPC capabilities) { this.flying = capabilities.flying; this.noClip = capabilities.noclip; } diff --git a/common/src/common/packet/S38PacketPlayerListItem.java b/common/src/common/packet/SPacketPlayerListItem.java similarity index 70% rename from common/src/common/packet/S38PacketPlayerListItem.java rename to common/src/common/packet/SPacketPlayerListItem.java index f83caa5..2bc0601 100755 --- a/common/src/common/packet/S38PacketPlayerListItem.java +++ b/common/src/common/packet/SPacketPlayerListItem.java @@ -11,36 +11,36 @@ import common.network.IPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S38PacketPlayerListItem implements Packet { +public class SPacketPlayerListItem implements Packet { private final Map players = Maps.newHashMap(); - public S38PacketPlayerListItem() { + public SPacketPlayerListItem() { } - public S38PacketPlayerListItem(boolean remove, IPlayer... conns) { + public SPacketPlayerListItem(boolean remove, IPlayer... conns) { for(IPlayer conn : conns) { this.players.put(conn.getUser(), remove ? -1 : conn.getLatency()); } } - public S38PacketPlayerListItem(Iterable conns) { + public SPacketPlayerListItem(Iterable conns) { for(IPlayer conn : conns) { this.players.put(((IPlayer)conn).getUser(), ((IPlayer)conn).getLatency()); } } public void readPacketData(PacketBuffer buf) throws IOException { - int n = buf.readVarIntFromBuffer(); + int n = buf.readVarInt(); for(int z = 0; z < n; z++) { - this.players.put(buf.readStringFromBuffer(16), buf.readVarIntFromBuffer()); + this.players.put(buf.readString(16), buf.readVarInt()); } } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.players.size()); + buf.writeVarInt(this.players.size()); for(Entry data : this.players.entrySet()) { buf.writeString(data.getKey()); - buf.writeVarIntToBuffer(data.getValue()); + buf.writeVarInt(data.getValue()); } } diff --git a/common/src/common/packet/S1EPacketRemoveEntityEffect.java b/common/src/common/packet/SPacketRemoveEntityEffect.java similarity index 79% rename from common/src/common/packet/S1EPacketRemoveEntityEffect.java rename to common/src/common/packet/SPacketRemoveEntityEffect.java index 9cd091e..7a27c9d 100755 --- a/common/src/common/packet/S1EPacketRemoveEntityEffect.java +++ b/common/src/common/packet/SPacketRemoveEntityEffect.java @@ -8,16 +8,16 @@ import common.network.PacketBuffer; import common.potion.Potion; import common.potion.PotionEffect; -public class S1EPacketRemoveEntityEffect implements Packet +public class SPacketRemoveEntityEffect implements Packet { private int entityId; private Potion effectId; - public S1EPacketRemoveEntityEffect() + public SPacketRemoveEntityEffect() { } - public S1EPacketRemoveEntityEffect(int entityIdIn, PotionEffect effect) + public SPacketRemoveEntityEffect(int entityIdIn, PotionEffect effect) { this.entityId = entityIdIn; this.effectId = effect.getPotion(); @@ -28,7 +28,7 @@ public class S1EPacketRemoveEntityEffect implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.effectId = buf.readEnumValue(Potion.class); } @@ -37,7 +37,7 @@ public class S1EPacketRemoveEntityEffect implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeEnumValue(this.effectId); } diff --git a/common/src/common/packet/SPacketRespawn.java b/common/src/common/packet/SPacketRespawn.java index 3e8d3fd..215269f 100755 --- a/common/src/common/packet/SPacketRespawn.java +++ b/common/src/common/packet/SPacketRespawn.java @@ -32,14 +32,14 @@ public class SPacketRespawn implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.dimension = buf.readNBTTagCompoundFromBuffer(); + this.dimension = buf.readTag(); this.type = buf.readUnsignedShort(); this.editor = buf.readBoolean(); } public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeNBTTagCompoundToBuffer(this.dimension); + buf.writeTag(this.dimension); buf.writeShort(this.type & 65535); buf.writeBoolean(this.editor); } diff --git a/common/src/common/packet/SPacketSetExperience.java b/common/src/common/packet/SPacketSetExperience.java index 1b60ca9..b2f2b06 100755 --- a/common/src/common/packet/SPacketSetExperience.java +++ b/common/src/common/packet/SPacketSetExperience.java @@ -29,8 +29,8 @@ public class SPacketSetExperience implements Packet public void readPacketData(PacketBuffer buf) throws IOException { this.progress = buf.readFloat(); - this.level = buf.readVarIntFromBuffer(); - this.totalExperience = buf.readVarIntFromBuffer(); + this.level = buf.readVarInt(); + this.totalExperience = buf.readVarInt(); } /** @@ -39,8 +39,8 @@ public class SPacketSetExperience implements Packet public void writePacketData(PacketBuffer buf) throws IOException { buf.writeFloat(this.progress); - buf.writeVarIntToBuffer(this.level); - buf.writeVarIntToBuffer(this.totalExperience); + buf.writeVarInt(this.level); + buf.writeVarInt(this.totalExperience); } /** diff --git a/common/src/common/packet/S2FPacketSetSlot.java b/common/src/common/packet/SPacketSetSlot.java similarity index 82% rename from common/src/common/packet/S2FPacketSetSlot.java rename to common/src/common/packet/SPacketSetSlot.java index def36be..0eaf219 100755 --- a/common/src/common/packet/S2FPacketSetSlot.java +++ b/common/src/common/packet/SPacketSetSlot.java @@ -7,17 +7,17 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S2FPacketSetSlot implements Packet +public class SPacketSetSlot implements Packet { private int windowId; private int slot; private ItemStack item; - public S2FPacketSetSlot() + public SPacketSetSlot() { } - public S2FPacketSetSlot(int windowIdIn, int slotIn, ItemStack itemIn) + public SPacketSetSlot(int windowIdIn, int slotIn, ItemStack itemIn) { this.windowId = windowIdIn; this.slot = slotIn; @@ -39,7 +39,7 @@ public class S2FPacketSetSlot implements Packet { this.windowId = buf.readByte(); this.slot = buf.readShort(); - this.item = buf.readItemStackFromBuffer(); + this.item = buf.readItemStack(); } /** @@ -49,7 +49,7 @@ public class S2FPacketSetSlot implements Packet { buf.writeByte(this.windowId); buf.writeShort(this.slot); - buf.writeItemStackToBuffer(this.item); + buf.writeItemStack(this.item); } public int getWindowId() diff --git a/common/src/common/packet/S36PacketSignEditorOpen.java b/common/src/common/packet/SPacketSignEditorOpen.java similarity index 85% rename from common/src/common/packet/S36PacketSignEditorOpen.java rename to common/src/common/packet/SPacketSignEditorOpen.java index 1059d0c..b7b09e9 100755 --- a/common/src/common/packet/S36PacketSignEditorOpen.java +++ b/common/src/common/packet/SPacketSignEditorOpen.java @@ -7,15 +7,15 @@ import common.network.Packet; import common.network.PacketBuffer; import common.util.BlockPos; -public class S36PacketSignEditorOpen implements Packet +public class SPacketSignEditorOpen implements Packet { private BlockPos signPosition; - public S36PacketSignEditorOpen() + public SPacketSignEditorOpen() { } - public S36PacketSignEditorOpen(BlockPos signPositionIn) + public SPacketSignEditorOpen(BlockPos signPositionIn) { this.signPosition = signPositionIn; } diff --git a/common/src/common/packet/SPacketSkin.java b/common/src/common/packet/SPacketSkin.java index 2efdcc9..4cf14f1 100755 --- a/common/src/common/packet/SPacketSkin.java +++ b/common/src/common/packet/SPacketSkin.java @@ -40,7 +40,7 @@ public class SPacketSkin implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.id = buf.readVarIntFromBuffer(); + this.id = buf.readVarInt(); // this.model = buf.readEnumValue(ModelType.class); this.texture = buf.readByteArray(); if(this.texture.length == 0) { @@ -53,7 +53,7 @@ public class SPacketSkin implements Packet public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.id); + buf.writeVarInt(this.id); // buf.writeEnumValue(this.model); buf.writeByteArray(this.texture == null ? new byte[0] : this.texture); } diff --git a/common/src/common/packet/S29PacketSoundEffect.java b/common/src/common/packet/SPacketSoundEffect.java similarity index 90% rename from common/src/common/packet/S29PacketSoundEffect.java rename to common/src/common/packet/SPacketSoundEffect.java index c39ca1a..d6ecedf 100755 --- a/common/src/common/packet/S29PacketSoundEffect.java +++ b/common/src/common/packet/SPacketSoundEffect.java @@ -7,7 +7,7 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S29PacketSoundEffect implements Packet +public class SPacketSoundEffect implements Packet { private SoundEvent sound; private int posX; @@ -15,12 +15,12 @@ public class S29PacketSoundEffect implements Packet private int posZ; private float soundVolume; - public S29PacketSoundEffect() + public SPacketSoundEffect() { this.sound = null; } - public S29PacketSoundEffect(SoundEvent sound, double soundX, double soundY, double soundZ, float volume) + public SPacketSoundEffect(SoundEvent sound, double soundX, double soundY, double soundZ, float volume) { this.sound = sound; if(this.sound == null) { diff --git a/common/src/common/packet/S2CPacketSpawnGlobalEntity.java b/common/src/common/packet/SPacketSpawnGlobalEntity.java similarity index 82% rename from common/src/common/packet/S2CPacketSpawnGlobalEntity.java rename to common/src/common/packet/SPacketSpawnGlobalEntity.java index 4741c44..baf214a 100755 --- a/common/src/common/packet/S2CPacketSpawnGlobalEntity.java +++ b/common/src/common/packet/SPacketSpawnGlobalEntity.java @@ -8,7 +8,7 @@ import common.network.Packet; import common.network.PacketBuffer; import common.util.ExtMath; -public class S2CPacketSpawnGlobalEntity implements Packet +public class SPacketSpawnGlobalEntity implements Packet { private int entityId; private int x; @@ -17,11 +17,11 @@ public class S2CPacketSpawnGlobalEntity implements Packet private int type; private int data; - public S2CPacketSpawnGlobalEntity() + public SPacketSpawnGlobalEntity() { } - public S2CPacketSpawnGlobalEntity(Entity entityIn, int type, int data) + public SPacketSpawnGlobalEntity(Entity entityIn, int type, int data) { this.entityId = entityIn.getId(); this.x = ExtMath.floord(entityIn.posX * 32.0D); @@ -36,12 +36,12 @@ public class S2CPacketSpawnGlobalEntity implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.type = buf.readByte(); this.x = buf.readInt(); this.y = buf.readInt(); this.z = buf.readInt(); - this.data = buf.readVarIntFromBuffer(); + this.data = buf.readVarInt(); } /** @@ -49,12 +49,12 @@ public class S2CPacketSpawnGlobalEntity implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeByte(this.type); buf.writeInt(this.x); buf.writeInt(this.y); buf.writeInt(this.z); - buf.writeVarIntToBuffer(this.data); + buf.writeVarInt(this.data); } /** diff --git a/common/src/common/packet/SPacketSpawnMob.java b/common/src/common/packet/SPacketSpawnMob.java index b26ba57..5542cb0 100755 --- a/common/src/common/packet/SPacketSpawnMob.java +++ b/common/src/common/packet/SPacketSpawnMob.java @@ -84,7 +84,7 @@ public class SPacketSpawnMob implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.type = buf.readUnsignedShort(); this.x = buf.readInt(); this.y = buf.readInt(); @@ -100,7 +100,7 @@ public class SPacketSpawnMob implements Packet public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeShort(this.type & 65535); buf.writeInt(this.x); buf.writeInt(this.y); diff --git a/common/src/common/packet/SPacketSpawnObject.java b/common/src/common/packet/SPacketSpawnObject.java index 6af450a..6ae2456 100755 --- a/common/src/common/packet/SPacketSpawnObject.java +++ b/common/src/common/packet/SPacketSpawnObject.java @@ -106,7 +106,7 @@ public class SPacketSpawnObject implements Packet public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.type = buf.readUnsignedShort(); this.x = buf.readInt(); this.y = buf.readInt(); @@ -123,7 +123,7 @@ public class SPacketSpawnObject implements Packet public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeShort(this.type & 65535); buf.writeInt(this.x); buf.writeInt(this.y); diff --git a/common/src/common/packet/SPacketSpawnPlayer.java b/common/src/common/packet/SPacketSpawnPlayer.java index 7c1ab02..a12ede6 100755 --- a/common/src/common/packet/SPacketSpawnPlayer.java +++ b/common/src/common/packet/SPacketSpawnPlayer.java @@ -52,7 +52,7 @@ public class SPacketSpawnPlayer implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); + this.entityId = buf.readVarInt(); this.type = buf.readUnsignedShort(); this.x = buf.readInt(); this.y = buf.readInt(); @@ -75,7 +75,7 @@ public class SPacketSpawnPlayer implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); + buf.writeVarInt(this.entityId); buf.writeShort(this.type & 65535); buf.writeInt(this.x); buf.writeInt(this.y); diff --git a/common/src/common/packet/S3APacketTabComplete.java b/common/src/common/packet/SPacketTabComplete.java similarity index 74% rename from common/src/common/packet/S3APacketTabComplete.java rename to common/src/common/packet/SPacketTabComplete.java index 76beea3..88ef0e2 100755 --- a/common/src/common/packet/S3APacketTabComplete.java +++ b/common/src/common/packet/SPacketTabComplete.java @@ -6,15 +6,15 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S3APacketTabComplete implements Packet +public class SPacketTabComplete implements Packet { private String[] matches; - public S3APacketTabComplete() + public SPacketTabComplete() { } - public S3APacketTabComplete(String[] matchesIn) + public SPacketTabComplete(String[] matchesIn) { this.matches = matchesIn; } @@ -24,11 +24,11 @@ public class S3APacketTabComplete implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.matches = new String[buf.readVarIntFromBuffer()]; + this.matches = new String[buf.readVarInt()]; for (int i = 0; i < this.matches.length; ++i) { - this.matches[i] = buf.readStringFromBuffer(32767); + this.matches[i] = buf.readString(32767); } } @@ -37,7 +37,7 @@ public class S3APacketTabComplete implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.matches.length); + buf.writeVarInt(this.matches.length); for (String s : this.matches) { diff --git a/common/src/common/packet/SPacketTimeUpdate.java b/common/src/common/packet/SPacketTimeUpdate.java index 3885c3a..4ed2a98 100755 --- a/common/src/common/packet/SPacketTimeUpdate.java +++ b/common/src/common/packet/SPacketTimeUpdate.java @@ -20,7 +20,7 @@ public class SPacketTimeUpdate implements Packet { public void readPacketData(PacketBuffer buf) throws IOException { this.worldTime = buf.readLong(); - this.serverInfo = buf.readStringFromBuffer(512); + this.serverInfo = buf.readString(512); } public void writePacketData(PacketBuffer buf) throws IOException { diff --git a/common/src/common/packet/SPacketTrades.java b/common/src/common/packet/SPacketTrades.java index 94a5e65..2b1f8fb 100755 --- a/common/src/common/packet/SPacketTrades.java +++ b/common/src/common/packet/SPacketTrades.java @@ -35,13 +35,13 @@ public class SPacketTrades implements Packet for (int j = 0; j < i; ++j) { - ItemStack itemstack = buf.readItemStackFromBuffer(); - ItemStack itemstack1 = buf.readItemStackFromBuffer(); + ItemStack itemstack = buf.readItemStack(); + ItemStack itemstack1 = buf.readItemStack(); ItemStack itemstack2 = null; if (buf.readBoolean()) { - itemstack2 = buf.readItemStackFromBuffer(); + itemstack2 = buf.readItemStack(); } // boolean flag = buf.readBoolean(); @@ -69,14 +69,14 @@ public class SPacketTrades implements Packet for (int i = 0; i < this.recipes.size(); ++i) { MerchantRecipe merchantrecipe = (MerchantRecipe)this.recipes.get(i); - buf.writeItemStackToBuffer(merchantrecipe.getItemToBuy()); - buf.writeItemStackToBuffer(merchantrecipe.getItemToSell()); + buf.writeItemStack(merchantrecipe.getItemToBuy()); + buf.writeItemStack(merchantrecipe.getItemToSell()); ItemStack itemstack = merchantrecipe.getSecondItemToBuy(); buf.writeBoolean(itemstack != null); if (itemstack != null) { - buf.writeItemStackToBuffer(itemstack); + buf.writeItemStack(itemstack); } // buf.writeBoolean(merchantrecipe.isRecipeDisabled()); diff --git a/common/src/common/packet/S43PacketUpdateEntityNBT.java b/common/src/common/packet/SPacketUpdateEntityNBT.java similarity index 72% rename from common/src/common/packet/S43PacketUpdateEntityNBT.java rename to common/src/common/packet/SPacketUpdateEntityNBT.java index ad56eac..d68a4d8 100755 --- a/common/src/common/packet/S43PacketUpdateEntityNBT.java +++ b/common/src/common/packet/SPacketUpdateEntityNBT.java @@ -9,16 +9,16 @@ import common.network.Packet; import common.network.PacketBuffer; import common.world.World; -public class S43PacketUpdateEntityNBT implements Packet +public class SPacketUpdateEntityNBT implements Packet { private int entityId; private NBTTagCompound tagCompound; - public S43PacketUpdateEntityNBT() + public SPacketUpdateEntityNBT() { } - public S43PacketUpdateEntityNBT(int entityIdIn, NBTTagCompound tagCompoundIn) + public SPacketUpdateEntityNBT(int entityIdIn, NBTTagCompound tagCompoundIn) { this.entityId = entityIdIn; this.tagCompound = tagCompoundIn; @@ -29,8 +29,8 @@ public class S43PacketUpdateEntityNBT implements Packet */ public void readPacketData(PacketBuffer buf) throws IOException { - this.entityId = buf.readVarIntFromBuffer(); - this.tagCompound = buf.readNBTTagCompoundFromBuffer(); + this.entityId = buf.readVarInt(); + this.tagCompound = buf.readTag(); } /** @@ -38,8 +38,8 @@ public class S43PacketUpdateEntityNBT implements Packet */ public void writePacketData(PacketBuffer buf) throws IOException { - buf.writeVarIntToBuffer(this.entityId); - buf.writeNBTTagCompoundToBuffer(this.tagCompound); + buf.writeVarInt(this.entityId); + buf.writeTag(this.tagCompound); } /** diff --git a/common/src/common/packet/S33PacketUpdateSign.java b/common/src/common/packet/SPacketUpdateSign.java similarity index 88% rename from common/src/common/packet/S33PacketUpdateSign.java rename to common/src/common/packet/SPacketUpdateSign.java index 8c75e28..25a586b 100755 --- a/common/src/common/packet/S33PacketUpdateSign.java +++ b/common/src/common/packet/SPacketUpdateSign.java @@ -8,18 +8,18 @@ import common.network.PacketBuffer; import common.util.BlockPos; import common.world.World; -public class S33PacketUpdateSign implements Packet +public class SPacketUpdateSign implements Packet { private World world; private BlockPos blockPos; private String[] lines; // private String command; - public S33PacketUpdateSign() + public SPacketUpdateSign() { } - public S33PacketUpdateSign(World worldIn, BlockPos blockPosIn, String[] linesIn) + public SPacketUpdateSign(World worldIn, BlockPos blockPosIn, String[] linesIn) { this.world = worldIn; this.blockPos = blockPosIn; @@ -37,7 +37,7 @@ public class S33PacketUpdateSign implements Packet for (int i = 0; i < 4; ++i) { - this.lines[i] = buf.readStringFromBuffer(64); + this.lines[i] = buf.readString(64); } // this.command = buf.readStringFromBuffer(1024); diff --git a/common/src/common/packet/S35PacketUpdateTileEntity.java b/common/src/common/packet/SPacketUpdateTileEntity.java similarity index 84% rename from common/src/common/packet/S35PacketUpdateTileEntity.java rename to common/src/common/packet/SPacketUpdateTileEntity.java index dc1f0c3..99cd78d 100755 --- a/common/src/common/packet/S35PacketUpdateTileEntity.java +++ b/common/src/common/packet/SPacketUpdateTileEntity.java @@ -10,17 +10,17 @@ import common.network.PacketBuffer; import common.tileentity.TileEntity; import common.util.BlockPos; -public class S35PacketUpdateTileEntity implements Packet +public class SPacketUpdateTileEntity implements Packet { private BlockPos blockPos; private int type; private NBTTagCompound nbt; - public S35PacketUpdateTileEntity() + public SPacketUpdateTileEntity() { } - public S35PacketUpdateTileEntity(TileEntity tile) + public SPacketUpdateTileEntity(TileEntity tile) { this.blockPos = tile.getPos(); this.type = TileRegistry.CLASS_TO_ID.get(tile.getClass()); @@ -34,7 +34,7 @@ public class S35PacketUpdateTileEntity implements Packet { this.blockPos = buf.readBlockPos(); this.type = buf.readUnsignedByte(); - this.nbt = buf.readNBTTagCompoundFromBuffer(); + this.nbt = buf.readTag(); } /** @@ -44,7 +44,7 @@ public class S35PacketUpdateTileEntity implements Packet { buf.writeBlockPos(this.blockPos); buf.writeByte((byte)this.type); - buf.writeNBTTagCompoundToBuffer(this.nbt); + buf.writeTag(this.nbt); } /** diff --git a/common/src/common/packet/S30PacketWindowItems.java b/common/src/common/packet/SPacketWindowItems.java similarity index 84% rename from common/src/common/packet/S30PacketWindowItems.java rename to common/src/common/packet/SPacketWindowItems.java index c3e37f3..ad38bca 100755 --- a/common/src/common/packet/S30PacketWindowItems.java +++ b/common/src/common/packet/SPacketWindowItems.java @@ -8,16 +8,16 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S30PacketWindowItems implements Packet +public class SPacketWindowItems implements Packet { private int windowId; private ItemStack[] itemStacks; - public S30PacketWindowItems() + public SPacketWindowItems() { } - public S30PacketWindowItems(int windowIdIn, List p_i45186_2_) + public SPacketWindowItems(int windowIdIn, List p_i45186_2_) { this.windowId = windowIdIn; this.itemStacks = new ItemStack[p_i45186_2_.size()]; @@ -40,7 +40,7 @@ public class S30PacketWindowItems implements Packet for (int j = 0; j < i; ++j) { - this.itemStacks[j] = buf.readItemStackFromBuffer(); + this.itemStacks[j] = buf.readItemStack(); } } @@ -54,7 +54,7 @@ public class S30PacketWindowItems implements Packet for (ItemStack itemstack : this.itemStacks) { - buf.writeItemStackToBuffer(itemstack); + buf.writeItemStack(itemstack); } } diff --git a/common/src/common/packet/S31PacketWindowProperty.java b/common/src/common/packet/SPacketWindowProperty.java similarity index 87% rename from common/src/common/packet/S31PacketWindowProperty.java rename to common/src/common/packet/SPacketWindowProperty.java index e8b02ff..ef546c5 100755 --- a/common/src/common/packet/S31PacketWindowProperty.java +++ b/common/src/common/packet/SPacketWindowProperty.java @@ -6,17 +6,17 @@ import common.network.IClientPlayer; import common.network.Packet; import common.network.PacketBuffer; -public class S31PacketWindowProperty implements Packet +public class SPacketWindowProperty implements Packet { private int windowId; private int varIndex; private int varValue; - public S31PacketWindowProperty() + public SPacketWindowProperty() { } - public S31PacketWindowProperty(int windowIdIn, int varIndexIn, int varValueIn) + public SPacketWindowProperty(int windowIdIn, int varIndexIn, int varValueIn) { this.windowId = windowIdIn; this.varIndex = varIndexIn; diff --git a/common/src/common/packet/SPacketWorld.java b/common/src/common/packet/SPacketWorld.java index 17ff613..6b79517 100755 --- a/common/src/common/packet/SPacketWorld.java +++ b/common/src/common/packet/SPacketWorld.java @@ -26,14 +26,14 @@ public class SPacketWorld implements Packet { public void readPacketData(PacketBuffer buf) throws IOException { this.gravity = buf.readFloat(); - this.timeFactor = buf.readVarIntFromBuffer(); + this.timeFactor = buf.readVarInt(); int flags = buf.readUnsignedByte(); this.dayCycle = (flags & 1) > 0; } public void writePacketData(PacketBuffer buf) throws IOException { buf.writeFloat(this.gravity); - buf.writeVarIntToBuffer(this.timeFactor); + buf.writeVarInt(this.timeFactor); buf.writeByte(this.dayCycle ? 1 : 0); } diff --git a/common/src/common/tileentity/TileEntityBanner.java b/common/src/common/tileentity/TileEntityBanner.java index 90e0668..c4c7b1b 100755 --- a/common/src/common/tileentity/TileEntityBanner.java +++ b/common/src/common/tileentity/TileEntityBanner.java @@ -11,7 +11,7 @@ import common.item.ItemStack; import common.nbt.NBTTagCompound; import common.nbt.NBTTagList; import common.network.Packet; -import common.packet.S35PacketUpdateTileEntity; +import common.packet.SPacketUpdateTileEntity; public class TileEntityBanner extends TileEntity { @@ -94,7 +94,7 @@ public class TileEntityBanner extends TileEntity */ public Packet getDescriptionPacket() { - return new S35PacketUpdateTileEntity(this); + return new SPacketUpdateTileEntity(this); } public int getBaseColor() diff --git a/common/src/common/tileentity/TileEntityBeacon.java b/common/src/common/tileentity/TileEntityBeacon.java index 19b6433..9cdb493 100755 --- a/common/src/common/tileentity/TileEntityBeacon.java +++ b/common/src/common/tileentity/TileEntityBeacon.java @@ -8,7 +8,7 @@ import common.entity.types.EntityLiving; import common.init.Blocks; import common.nbt.NBTTagCompound; import common.network.Packet; -import common.packet.S35PacketUpdateTileEntity; +import common.packet.SPacketUpdateTileEntity; import common.potion.Potion; import common.potion.PotionEffect; import common.util.BlockPos; @@ -280,7 +280,7 @@ public class TileEntityBeacon extends TileEntity implements ITickable */ public Packet getDescriptionPacket() { - return new S35PacketUpdateTileEntity(this); + return new SPacketUpdateTileEntity(this); } public double getMaxRenderDistanceSquared() diff --git a/common/src/common/tileentity/TileEntityMachine.java b/common/src/common/tileentity/TileEntityMachine.java index 45d9d6b..84fb12c 100755 --- a/common/src/common/tileentity/TileEntityMachine.java +++ b/common/src/common/tileentity/TileEntityMachine.java @@ -9,7 +9,7 @@ import common.item.ItemStack; import common.nbt.NBTTagCompound; import common.nbt.NBTTagList; import common.network.Packet; -import common.packet.S35PacketUpdateTileEntity; +import common.packet.SPacketUpdateTileEntity; import common.rng.Random; import common.util.ExtMath; @@ -326,7 +326,7 @@ public abstract class TileEntityMachine extends TileEntityLockable implements IH public Packet getDescriptionPacket() { - return new S35PacketUpdateTileEntity(this); + return new SPacketUpdateTileEntity(this); } public int getColor() { diff --git a/common/src/common/tileentity/TileEntityMobSpawner.java b/common/src/common/tileentity/TileEntityMobSpawner.java index 0847f04..0168d35 100755 --- a/common/src/common/tileentity/TileEntityMobSpawner.java +++ b/common/src/common/tileentity/TileEntityMobSpawner.java @@ -8,7 +8,7 @@ import common.init.EntityRegistry; import common.model.ParticleType; import common.nbt.NBTTagCompound; import common.network.Packet; -import common.packet.S35PacketUpdateTileEntity; +import common.packet.SPacketUpdateTileEntity; import common.util.BlockPos; import common.util.BoundingBox; import common.world.World; @@ -29,7 +29,7 @@ public class TileEntityMobSpawner extends TileEntity implements ITickable public Packet getDescriptionPacket() { - return new S35PacketUpdateTileEntity(this); + return new SPacketUpdateTileEntity(this); } public boolean receiveClientEvent(int id, int type) diff --git a/common/src/common/tileentity/TileEntitySign.java b/common/src/common/tileentity/TileEntitySign.java index 4c5301a..b567287 100755 --- a/common/src/common/tileentity/TileEntitySign.java +++ b/common/src/common/tileentity/TileEntitySign.java @@ -3,7 +3,7 @@ package common.tileentity; import common.entity.npc.EntityNPC; import common.nbt.NBTTagCompound; import common.network.Packet; -import common.packet.S33PacketUpdateSign; +import common.packet.SPacketUpdateSign; public class TileEntitySign extends TileEntity { public final String[] signText = new String[] {"", "", "", ""}; @@ -95,7 +95,7 @@ public class TileEntitySign extends TileEntity { String[] aichatcomponent = new String[4]; System.arraycopy(this.signText, 0, aichatcomponent, 0, 4); // Sign sign = Server.getServer().getSigns().getEntry(new WorldPos(this).toString()); - return new S33PacketUpdateSign(this.worldObj, this.pos, aichatcomponent); + return new SPacketUpdateSign(this.worldObj, this.pos, aichatcomponent); } // public boolean hasSpecialNBT() { diff --git a/common/src/common/tileentity/TileEntitySkull.java b/common/src/common/tileentity/TileEntitySkull.java index 48f9349..cd55919 100755 --- a/common/src/common/tileentity/TileEntitySkull.java +++ b/common/src/common/tileentity/TileEntitySkull.java @@ -2,7 +2,7 @@ package common.tileentity; import common.nbt.NBTTagCompound; import common.network.Packet; -import common.packet.S35PacketUpdateTileEntity; +import common.packet.SPacketUpdateTileEntity; public class TileEntitySkull extends TileEntity { @@ -36,7 +36,7 @@ public class TileEntitySkull extends TileEntity */ public Packet getDescriptionPacket() { - return new S35PacketUpdateTileEntity(this); + return new SPacketUpdateTileEntity(this); } // public void setUser(String user) diff --git a/server/src/server/Server.java b/server/src/server/Server.java index e7f5598..96774ac 100755 --- a/server/src/server/Server.java +++ b/server/src/server/Server.java @@ -56,10 +56,10 @@ import common.network.PacketSplitter; import common.network.NetHandler.ThreadQuickExitException; import common.packet.RPacketEnableCompression; import common.packet.RPacketLoginSuccess; -import common.packet.S1DPacketEntityEffect; -import common.packet.S2BPacketChangeGameState; -import common.packet.S38PacketPlayerListItem; -import common.packet.S39PacketPlayerAbilities; +import common.packet.SPacketEntityEffect; +import common.packet.SPacketChangeGameState; +import common.packet.SPacketPlayerListItem; +import common.packet.SPacketPlayerAbilities; import common.packet.SPacketDisconnect; import common.packet.SPacketHeldItemChange; import common.packet.SPacketJoinGame; @@ -655,7 +655,7 @@ public final class Server implements IThreadListener { } this.networkTick(); if(++this.pingTimer > 600) { - this.sendPacket(new S38PacketPlayerListItem((List)this.getPlayers())); + this.sendPacket(new SPacketPlayerListItem((List)this.getPlayers())); this.pingTimer = 0; } if(Config.saveInterval > 0 && ++this.saveTimer >= Config.saveInterval) { @@ -867,22 +867,22 @@ public final class Server implements IThreadListener { conn.sendPacket(new SPacketWorld(WorldServer.clampGravity(), Config.dayCycle, Config.timeFlow)); // conn.initializeStats(); - this.sendPacket(new S38PacketPlayerListItem(false, conn)); + this.sendPacket(new SPacketPlayerListItem(false, conn)); world.spawnEntityInWorld(player); this.preparePlayer(player, null); for(int i = 0; i < this.players.size(); ++i) { Player other = this.players.get(i); - conn.sendPacket(new S38PacketPlayerListItem(false, other)); + conn.sendPacket(new SPacketPlayerListItem(false, other)); } conn.sendPacket(new SPacketSkin(player.getId(), player.getSkin())); // , player.getModel())); conn.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotYaw, player.rotPitch); this.updateTimeAndWeatherForPlayer(conn, world); for(PotionEffect effect : player.getEffects()) { - conn.sendPacket(new S1DPacketEntityEffect(player.getId(), effect)); + conn.sendPacket(new SPacketEntityEffect(player.getId(), effect)); } - conn.sendPacket(new S39PacketPlayerAbilities(player)); + conn.sendPacket(new SPacketPlayerAbilities(player)); conn.addSelfToInternalCraftingInventory(); conn.onConnect(); return null; @@ -897,7 +897,7 @@ public final class Server implements IThreadListener { world.removePlayer(player); this.players.remove(conn); this.usermap.remove(conn.getUser()); - this.sendPacket(new S38PacketPlayerListItem(true, conn)); + this.sendPacket(new SPacketPlayerListItem(true, conn)); } private void preparePlayer(EntityNPC player, WorldServer oldWorld) { @@ -1060,7 +1060,7 @@ public final class Server implements IThreadListener { this.updateTimeAndWeatherForPlayer(conn, world); this.syncPlayerInventory(nplayer); for(PotionEffect effect : nplayer.getEffects()) { - conn.sendPacket(new S1DPacketEntityEffect(nplayer.getId(), effect)); + conn.sendPacket(new SPacketEntityEffect(nplayer.getId(), effect)); } conn.sendPlayerAbilities(); return oldTag; @@ -1087,7 +1087,7 @@ public final class Server implements IThreadListener { this.updateTimeAndWeatherForPlayer((Player)player.connection, newWorld); this.syncPlayerInventory(player); for(PotionEffect effect : player.getEffects()) { - player.connection.sendPacket(new S1DPacketEntityEffect(player.getId(), effect)); + player.connection.sendPacket(new SPacketEntityEffect(player.getId(), effect)); } player.connection.sendPlayerAbilities(); } @@ -1171,11 +1171,11 @@ public final class Server implements IThreadListener { private void updateTimeAndWeatherForPlayer(Player conn, WorldServer world) { conn.sendPacket(new SPacketTimeUpdate(world.getDayTime(), this.getInfo())); - conn.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.SET_WEATHER, world.getWeather().getID())); - conn.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.RAIN_STRENGTH, world.getRainStrength())); - conn.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.DARKNESS, world.getDarkness())); - conn.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.FOG_STRENGTH, world.getFogStrength())); - conn.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.TEMPERATURE, world.getTempOffset())); + conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.SET_WEATHER, world.getWeather().getID())); + conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.RAIN_STRENGTH, world.getRainStrength())); + conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.DARKNESS, world.getDarkness())); + conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.FOG_STRENGTH, world.getFogStrength())); + conn.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.TEMPERATURE, world.getTempOffset())); } public void syncPlayerInventory(EntityNPC player) { diff --git a/server/src/server/network/Player.java b/server/src/server/network/Player.java index f2a7bfb..2429ab0 100755 --- a/server/src/server/network/Player.java +++ b/server/src/server/network/Player.java @@ -48,13 +48,11 @@ import common.log.Log; import common.material.Material; import common.nbt.NBTTagCompound; import common.nbt.NBTTagList; -import common.nbt.NBTTagString; import common.network.IPlayer; import common.network.NetConnection; import common.network.NetHandler; import common.network.Packet; import common.packet.CPacketAction; -import common.packet.CPacketBook; import common.packet.CPacketBreak; import common.packet.CPacketCheat; import common.packet.CPacketClick; @@ -67,21 +65,21 @@ import common.packet.CPacketPlace; import common.packet.CPacketPlayer; import common.packet.CPacketSign; import common.packet.CPacketSkin; -import common.packet.S18PacketEntityTeleport; -import common.packet.S1APacketEntityStatus; -import common.packet.S1BPacketEntityAttach; -import common.packet.S1DPacketEntityEffect; -import common.packet.S1EPacketRemoveEntityEffect; -import common.packet.S29PacketSoundEffect; -import common.packet.S2DPacketOpenWindow; -import common.packet.S2EPacketCloseWindow; -import common.packet.S2FPacketSetSlot; -import common.packet.S30PacketWindowItems; -import common.packet.S31PacketWindowProperty; -import common.packet.S32PacketConfirmTransaction; -import common.packet.S36PacketSignEditorOpen; -import common.packet.S39PacketPlayerAbilities; -import common.packet.S3APacketTabComplete; +import common.packet.SPacketEntityTeleport; +import common.packet.SPacketEntityStatus; +import common.packet.SPacketEntityAttach; +import common.packet.SPacketEntityEffect; +import common.packet.SPacketRemoveEntityEffect; +import common.packet.SPacketSoundEffect; +import common.packet.SPacketOpenWindow; +import common.packet.SPacketCloseWindow; +import common.packet.SPacketSetSlot; +import common.packet.SPacketWindowItems; +import common.packet.SPacketWindowProperty; +import common.packet.SPacketConfirmTransaction; +import common.packet.SPacketSignEditorOpen; +import common.packet.SPacketPlayerAbilities; +import common.packet.SPacketTabComplete; import common.packet.SPacketAnimation; import common.packet.SPacketBlockChange; import common.packet.SPacketCharacterList; @@ -429,7 +427,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer this.entity.openContainer.onCraftGuiOpened(this); IInventory iinventory = ((ContainerMerchant)this.entity.openContainer).getMerchantInventory(); String ichatcomponent = npc.getName(); - this.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "trade", ichatcomponent, iinventory.getSizeInventory())); + this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "trade", ichatcomponent, iinventory.getSizeInventory())); MerchantRecipeList merchantrecipelist = npc.getTrades(this.entity); if (merchantrecipelist != null) @@ -445,7 +443,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer { if (!this.isChangingQuantityOnly) { - this.sendPacket(new S2FPacketSetSlot(-1, -1, this.entity.inventory.getItemStack())); + this.sendPacket(new SPacketSetSlot(-1, -1, this.entity.inventory.getItemStack())); } } @@ -553,7 +551,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer { if (this.entity != null) { - this.sendPacket(new S39PacketPlayerAbilities(this.entity)); + this.sendPacket(new SPacketPlayerAbilities(this.entity)); this.entity.updateEffectMeta(); } } @@ -707,20 +705,20 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer public void mountEntity(Entity entityIn) { - this.sendPacket(new S1BPacketEntityAttach(0, this.entity, this.entity.vehicle)); + this.sendPacket(new SPacketEntityAttach(0, this.entity, this.entity.vehicle)); this.setPlayerLocation(this.entity.posX, this.entity.posY, this.entity.posZ, this.entity.rotYaw, this.entity.rotPitch); } public void openEditSign(TileEntitySign signTile) { signTile.setPlayer(this.entity); - this.sendPacket(new S36PacketSignEditorOpen(signTile.getPos())); + this.sendPacket(new SPacketSignEditorOpen(signTile.getPos())); } public void displayGui(IInteractionObject guiOwner) { this.getNextWindowId(); - this.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, guiOwner.getGuiID(), guiOwner.getCommandName())); + this.sendPacket(new SPacketOpenWindow(this.currentWindowId, guiOwner.getGuiID(), guiOwner.getCommandName())); this.entity.openContainer = guiOwner.createContainer(this.entity.inventory, this.entity); this.entity.openContainer.windowId = this.currentWindowId; this.entity.openContainer.onCraftGuiOpened(this); @@ -740,7 +738,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer if (ilockablecontainer.isLocked() && !this.entity.canOpen(ilockablecontainer.getLockCode())) // && !this.isSpectator()) { this.addHotbar(TextColor.RED + "%s ist verschlossen!", chestInventory.getCommandName()); - this.sendPacket(new S29PacketSoundEffect(SoundEvent.DOOR, this.entity.posX, this.entity.posY, this.entity.posZ, 1.0F)); + this.sendPacket(new SPacketSoundEffect(SoundEvent.DOOR, this.entity.posX, this.entity.posY, this.entity.posZ, 1.0F)); return; } } @@ -749,18 +747,18 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer if (chestInventory instanceof TileEntityMachine) { - this.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "machine_" + ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getCommandName(), chestInventory.getSizeInventory(), + this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "machine_" + ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getCommandName(), chestInventory.getSizeInventory(), ((TileEntityMachine)chestInventory).getPos())); this.entity.openContainer = ((IInteractionObject)chestInventory).createContainer(this.entity.inventory, this.entity); } else if (chestInventory instanceof IInteractionObject) { - this.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getCommandName(), chestInventory.getSizeInventory())); + this.sendPacket(new SPacketOpenWindow(this.currentWindowId, ((IInteractionObject)chestInventory).getGuiID(), chestInventory.getCommandName(), chestInventory.getSizeInventory())); this.entity.openContainer = ((IInteractionObject)chestInventory).createContainer(this.entity.inventory, this.entity); } else { - this.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "container", chestInventory.getCommandName(), chestInventory.getSizeInventory())); + this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "container", chestInventory.getCommandName(), chestInventory.getSizeInventory())); this.entity.openContainer = new ContainerChest(this.entity.inventory, chestInventory, this.entity); } @@ -776,7 +774,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer } this.getNextWindowId(); - this.sendPacket(new S2DPacketOpenWindow(this.currentWindowId, "EntityHorse", horseInventory.getCommandName(), horseInventory.getSizeInventory(), horse.getId())); + this.sendPacket(new SPacketOpenWindow(this.currentWindowId, "EntityHorse", horseInventory.getCommandName(), horseInventory.getSizeInventory(), horse.getId())); this.entity.openContainer = new ContainerHorseInventory(this.entity.inventory, horseInventory, horse, this.entity); this.entity.openContainer.windowId = this.currentWindowId; this.entity.openContainer.onCraftGuiOpened(this); @@ -794,7 +792,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer public void closeScreen() { - this.sendPacket(new S2EPacketCloseWindow(this.entity.openContainer.windowId)); + this.sendPacket(new SPacketCloseWindow(this.entity.openContainer.windowId)); this.closeContainer(); } @@ -813,7 +811,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer public void onItemUseFinish() { - this.sendPacket(new S1APacketEntityStatus(this.entity, (byte)9)); + this.sendPacket(new SPacketEntityStatus(this.entity, (byte)9)); } // /** @@ -831,17 +829,17 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer public void onNewEffect(PotionEffect id) { - this.sendPacket(new S1DPacketEntityEffect(this.entity.getId(), id)); + this.sendPacket(new SPacketEntityEffect(this.entity.getId(), id)); } public void onChangedEffect(PotionEffect id, boolean added) { - this.sendPacket(new S1DPacketEntityEffect(this.entity.getId(), id)); + this.sendPacket(new SPacketEntityEffect(this.entity.getId(), id)); } public void onFinishedEffect(PotionEffect effect) { - this.sendPacket(new S1EPacketRemoveEntityEffect(this.entity.getId(), effect)); + this.sendPacket(new SPacketRemoveEntityEffect(this.entity.getId(), effect)); } public void setPositionAndUpdate(double x, double y, double z) @@ -866,7 +864,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer public void playSound(SoundEvent name, float volume) { - this.server.sendNearExcept(this.entity, this.entity.posX, this.entity.posY, this.entity.posZ, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, this.entity.worldObj.dimension.getDimensionId(), new S29PacketSoundEffect(name, this.entity.posX, this.entity.posY, this.entity.posZ, volume)); + this.server.sendNearExcept(this.entity, this.entity.posX, this.entity.posY, this.entity.posZ, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, this.entity.worldObj.dimension.getDimensionId(), new SPacketSoundEffect(name, this.entity.posX, this.entity.posY, this.entity.posZ, volume)); } @@ -886,7 +884,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer { if (!this.isChangingQuantityOnly) { - this.sendPacket(new S2FPacketSetSlot(containerToSend.windowId, slotInd, stack)); + this.sendPacket(new SPacketSetSlot(containerToSend.windowId, slotInd, stack)); } } } @@ -898,20 +896,20 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer public void updateCraftingInventory(Container containerToSend, List itemsList) { - this.sendPacket(new S30PacketWindowItems(containerToSend.windowId, itemsList)); - this.sendPacket(new S2FPacketSetSlot(-1, -1, this.entity.inventory.getItemStack())); + this.sendPacket(new SPacketWindowItems(containerToSend.windowId, itemsList)); + this.sendPacket(new SPacketSetSlot(-1, -1, this.entity.inventory.getItemStack())); } public void sendProgressBarUpdate(Container containerIn, int varToUpdate, int newValue) { - this.sendPacket(new S31PacketWindowProperty(containerIn.windowId, varToUpdate, newValue)); + this.sendPacket(new SPacketWindowProperty(containerIn.windowId, varToUpdate, newValue)); } public void sendAllWindowProperties(Container p_175173_1_, IInventory p_175173_2_) { for (int i = 0; i < p_175173_2_.getFieldCount(); ++i) { - this.sendPacket(new S31PacketWindowProperty(p_175173_1_.windowId, i, p_175173_2_.getField(i))); + this.sendPacket(new SPacketWindowProperty(p_175173_1_.windowId, i, p_175173_2_.getField(i))); } } @@ -2055,13 +2053,13 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer { NetHandler.checkThread(packetIn, this, this.server); if(this.charEditor || !this.isAdmin()) { - this.entity.connection.sendPacket(new S3APacketTabComplete(new String[0])); + this.entity.connection.sendPacket(new SPacketTabComplete(new String[0])); return; } this.pointedEntity = packetIn.getEntityId(); this.pointedPosition = packetIn.getPosition(); if(packetIn.getMessage().startsWith(" ")) { - this.entity.connection.sendPacket(new S3APacketTabComplete(new String[0])); + this.entity.connection.sendPacket(new SPacketTabComplete(new String[0])); return; } List list = Lists.newArrayList(); @@ -2074,7 +2072,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer list.add(s1); } list.addAll(this.completeCommand(packetIn.getMessage())); - this.entity.connection.sendPacket(new S3APacketTabComplete(list.toArray(new String[list.size()]))); + this.entity.connection.sendPacket(new SPacketTabComplete(list.toArray(new String[list.size()]))); } private static boolean isFinite(double value) { @@ -2154,7 +2152,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer if (d3 > 4.0D) { Entity entity = this.entity.vehicle; - this.entity.connection.sendPacket(new S18PacketEntityTeleport(entity)); + this.entity.connection.sendPacket(new SPacketEntityTeleport(entity)); this.setPlayerLocation(this.entity.posX, this.entity.posY, this.entity.posZ, this.entity.rotYaw, this.entity.rotPitch); } @@ -2480,7 +2478,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer if (!ItemStack.areItemStacksEqual(this.entity.inventory.getCurrentItem(), packetIn.getStack())) { - this.sendPacket(new S2FPacketSetSlot(this.entity.openContainer.windowId, slot.slotNumber, this.entity.inventory.getCurrentItem())); + this.sendPacket(new SPacketSetSlot(this.entity.openContainer.windowId, slot.slotNumber, this.entity.inventory.getCurrentItem())); } } } @@ -2943,7 +2941,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer if (ItemStack.areItemStacksEqual(packetIn.getClickedItem(), itemstack)) { - this.entity.connection.sendPacket(new S32PacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), true)); + this.entity.connection.sendPacket(new SPacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), true)); this.isChangingQuantityOnly = true; this.entity.openContainer.detectAndSendChanges(); this.updateHeldItem(); @@ -2952,7 +2950,7 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer else { this.transactions.addKey(this.entity.openContainer.windowId, Short.valueOf(packetIn.getActionNumber())); - this.entity.connection.sendPacket(new S32PacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), false)); + this.entity.connection.sendPacket(new SPacketConfirmTransaction(packetIn.getWindowId(), packetIn.getActionNumber(), false)); this.entity.openContainer.setCanCraft(this.entity, false); List list1 = Lists.newArrayList(); @@ -3141,34 +3139,6 @@ public class Player extends NetHandler implements ICrafting, Executor, IPlayer // this.lastSkinUpdate = System.currentTimeMillis(); } - public void processBook(CPacketBook packetIn) { - NetHandler.checkThread(packetIn, this, this.server); - if(this.charEditor) - return; - - String[] pages = packetIn.getPages(); -// if (!ItemWritableBook.isNBTValid(itemstack1.getTagCompound())) -// throw new IOException("Fehlerhafter Buch-Tag!"); - ItemStack itemstack = this.entity.inventory.getCurrentItem(); - if (itemstack != null && itemstack.getItem() == Items.writable_book) - { - if(pages.length == 0) { - if(itemstack.hasTagCompound()) { - itemstack.getTagCompound().removeTag("pages"); - if(itemstack.getTagCompound().hasNoTags()) - itemstack.setTagCompound(null); - } - } - else { - NBTTagList list = new NBTTagList(); - for(String page : pages) { - list.appendTag(new NBTTagString(page)); - } - itemstack.setTagInfo("pages", list); - } - } - } - public void processForm(CPacketForm packet) { NetHandler.checkThread(packet, this, this.server); if(this.charEditor || this.form == null || packet.getId() != this.currentFormId) diff --git a/server/src/server/world/WorldServer.java b/server/src/server/world/WorldServer.java index 0d79a09..ee652d8 100755 --- a/server/src/server/world/WorldServer.java +++ b/server/src/server/world/WorldServer.java @@ -47,13 +47,13 @@ import common.nbt.NBTTagInt; import common.nbt.NBTTagList; import common.network.IPlayer; import common.network.Packet; -import common.packet.S1APacketEntityStatus; -import common.packet.S27PacketExplosion; -import common.packet.S28PacketEffect; -import common.packet.S29PacketSoundEffect; -import common.packet.S2APacketParticles; -import common.packet.S2BPacketChangeGameState; -import common.packet.S2CPacketSpawnGlobalEntity; +import common.packet.SPacketEntityStatus; +import common.packet.SPacketExplosion; +import common.packet.SPacketEffect; +import common.packet.SPacketSoundEffect; +import common.packet.SPacketParticles; +import common.packet.SPacketChangeGameState; +import common.packet.SPacketSpawnGlobalEntity; import common.packet.SPacketBiome; import common.packet.SPacketBlockAction; import common.packet.SPacketBlockBreakAnim; @@ -1113,7 +1113,7 @@ public final class WorldServer extends AWorldServer { EntityLightning entity = new EntityLightning(this, x, y, z, color, damage, fire, summoner); this.effects.add(entity); this.server.sendNear(entity.posX, entity.posY, entity.posZ, 512.0D, this.dimension.getDimensionId(), - new S2CPacketSpawnGlobalEntity(entity, 1, entity.color)); + new SPacketSpawnGlobalEntity(entity, 1, entity.color)); if(fire && Config.fire) { BlockPos pos = new BlockPos(entity); if(this.isAreaLoaded(pos, 10)) { @@ -1129,7 +1129,7 @@ public final class WorldServer extends AWorldServer { } public void setEntityState(Entity entityIn, byte state) { - this.sendToAllTrackingAndSelf(entityIn, new S1APacketEntityStatus(entityIn, state)); + this.sendToAllTrackingAndSelf(entityIn, new SPacketEntityStatus(entityIn, state)); } public Explosion newExplosion(Entity entityIn, double x, double y, double z, float strength, boolean isFlaming, boolean isSmoking, boolean altSound) { @@ -1143,7 +1143,7 @@ public final class WorldServer extends AWorldServer { for(EntityNPC entityplayer : this.players) { if(entityplayer.getDistanceSq(x, y, z) < 4096.0D) { - entityplayer.connection.sendPacket(new S27PacketExplosion(x, y, z, strength, explosion.getAffectedBlockPositions(), + entityplayer.connection.sendPacket(new SPacketExplosion(x, y, z, strength, explosion.getAffectedBlockPositions(), (Vec3)explosion.getPlayerKnockbackMap().get(entityplayer), altSound)); } } @@ -1196,7 +1196,7 @@ public final class WorldServer extends AWorldServer { public void setWeather(Weather weather) { this.weather = weather; // this.dataModified = true; - this.server.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.SET_WEATHER, + this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.SET_WEATHER, weather.getID()), this.dimension.getDimensionId()); } @@ -1268,15 +1268,15 @@ public final class WorldServer extends AWorldServer { } if(prevRain != this.rain || force) { - this.server.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.RAIN_STRENGTH, this.rain), this.dimension.getDimensionId()); + this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.RAIN_STRENGTH, this.rain), this.dimension.getDimensionId()); } if(prevDarkness != this.darkness || force) { - this.server.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.DARKNESS, this.darkness), this.dimension.getDimensionId()); + this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.DARKNESS, this.darkness), this.dimension.getDimensionId()); } if(prevFog != this.fog || force) { - this.server.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.FOG_STRENGTH, this.fog), this.dimension.getDimensionId()); + this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.FOG_STRENGTH, this.fog), this.dimension.getDimensionId()); } } @@ -1292,7 +1292,7 @@ public final class WorldServer extends AWorldServer { } if(prevTemp != this.temp || force) { - this.server.sendPacket(new S2BPacketChangeGameState(S2BPacketChangeGameState.Action.TEMPERATURE, this.temp), this.dimension.getDimensionId()); + this.server.sendPacket(new SPacketChangeGameState(SPacketChangeGameState.Action.TEMPERATURE, this.temp), this.dimension.getDimensionId()); } } @@ -1308,7 +1308,7 @@ public final class WorldServer extends AWorldServer { public void spawnParticle(ParticleType particleType, boolean longDistance, double xCoord, double yCoord, double zCoord, int numberOfParticles, double xOffset, double yOffset, double zOffset, double particleSpeed, int[] particleArguments) { - Packet packet = new S2APacketParticles(particleType, longDistance, (float)xCoord, (float)yCoord, (float)zCoord, (float)xOffset, + Packet packet = new SPacketParticles(particleType, longDistance, (float)xCoord, (float)yCoord, (float)zCoord, (float)xOffset, (float)yOffset, (float)zOffset, (float)particleSpeed, numberOfParticles, particleArguments); for(int i = 0; i < this.players.size(); ++i) { @@ -1719,15 +1719,15 @@ public final class WorldServer extends AWorldServer { } for(EntityNPC player : this.players) { player.attackEntityFrom(DamageSource.causeExterminatusDamage(null), 5000); - Packet packet = new S2APacketParticles(ParticleType.EXPLOSION_HUGE, true, + Packet packet = new SPacketParticles(ParticleType.EXPLOSION_HUGE, true, (float)player.posX, (float)this.getSeaLevel() + 4.0f, (float)player.posZ, (float)128.0, (float)2.0, (float)128.0, (float)0.15, 1000, new int[0]); player.connection.sendPacket(packet); - packet = new S2APacketParticles(ParticleType.CLOUD, true, + packet = new SPacketParticles(ParticleType.CLOUD, true, (float)player.posX, (float)this.getSeaLevel() + 4.0f, (float)player.posZ, (float)128.0, (float)2.0, (float)128.0, (float)0.15, 1000, new int[0]); player.connection.sendPacket(packet); - packet = new S28PacketEffect(1025, new BlockPos(player.posX, (double)this.getSeaLevel() + 4.0, player.posZ), 0); + packet = new SPacketEffect(1025, new BlockPos(player.posX, (double)this.getSeaLevel() + 4.0, player.posZ), 0); player.connection.sendPacket(packet); } return true; @@ -1803,7 +1803,7 @@ public final class WorldServer extends AWorldServer { public void playSound(SoundEvent sound, double x, double y, double z, float volume) { - this.server.sendNear(x, y, z, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, this.dimension.getDimensionId(), new S29PacketSoundEffect(sound, x, y, z, volume)); + this.server.sendNear(x, y, z, volume > 1.0F ? (double)(16.0F * volume) : 16.0D, this.dimension.getDimensionId(), new SPacketSoundEffect(sound, x, y, z, volume)); } public void markBlockRangeForRenderUpdate(int x1, int y1, int z1, int x2, int y2, int z2) @@ -1816,7 +1816,7 @@ public final class WorldServer extends AWorldServer { public void playAuxSFX(EntityNPC player, int sfxType, BlockPos blockPosIn, int data) { - this.server.sendNearExcept(player, (double)blockPosIn.getX(), (double)blockPosIn.getY(), (double)blockPosIn.getZ(), 64.0D, this.dimension.getDimensionId(), new S28PacketEffect(sfxType, blockPosIn, data)); + this.server.sendNearExcept(player, (double)blockPosIn.getX(), (double)blockPosIn.getY(), (double)blockPosIn.getZ(), 64.0D, this.dimension.getDimensionId(), new SPacketEffect(sfxType, blockPosIn, data)); } // public void broadcastSound(int soundID, BlockPos pos, int data)