protocolsupport.protocol.serializer.VarNumberSerializer Java Examples
The following examples show how to use
protocolsupport.protocol.serializer.VarNumberSerializer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpawnObject.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void writeToClient() { ClientBoundPacketData serializer = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_OBJECT); VarNumberSerializer.writeVarInt(serializer, entity.getId()); UUIDSerializer.writeUUID2L(serializer, entity.getUUID()); serializer.writeByte(flatteningEntityIdTable.getRemap(rType.getNetworkTypeId())); serializer.writeDouble(x); serializer.writeDouble(y); serializer.writeDouble(z); serializer.writeByte(pitch); serializer.writeByte(yaw); serializer.writeInt(rObjectdata); serializer.writeShort(motX); serializer.writeShort(motY); serializer.writeShort(motZ); codec.write(serializer); }
Example #2
Source File: ParticleDataSerializer.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
protected ParticleDataSerializer() { register(Particle.class, (to, particle) -> {}, ProtocolVersionsHelper.UP_1_13); register(ParticleDust.class, (to, particle) -> { to.writeFloat(particle.getRed()); to.writeFloat(particle.getGreen()); to.writeFloat(particle.getBlue()); to.writeFloat(particle.getScale()); }, ProtocolVersionsHelper.UP_1_13); Arrays.stream(ProtocolVersionsHelper.UP_1_13) .forEach(version -> { FlatteningBlockDataTable flatteningBlockDataTable = FlatteningBlockData.REGISTRY.getTable(version); register(ParticleBlock.class, (to, particle) -> VarNumberSerializer.writeVarInt(to, flatteningBlockDataTable.getBlockDataRemap(particle.getBlockData())), version); register(ParticleFallingDust.class, (to, particle) -> VarNumberSerializer.writeFixedSizeVarInt(to, flatteningBlockDataTable.getBlockDataRemap(particle.getBlockData())), version); register(ParticleItem.class, (to, particle) -> ItemStackSerializer.writeItemStack(to, version, particle.getItemStack()), version); }); }
Example #3
Source File: PlayerMovePacket.java From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 | 6 votes |
@Override public void readFromClientData(ConnectionImpl connection, ByteBuf clientdata) { this.entityId = VarNumberSerializer.readSVarLong(clientdata); this.x = clientdata.readFloatLE(); this.y = clientdata.readFloatLE(); this.z = clientdata.readFloatLE(); this.pitch = clientdata.readFloatLE(); this.headYaw = clientdata.readFloatLE(); this.mode = clientdata.readByte(); this.onGround = clientdata.readBoolean(); VarNumberSerializer.readVarInt(clientdata); if (mode == 2) { VarNumberSerializer.readSVarInt(clientdata); VarNumberSerializer.readSVarInt(clientdata); } }
Example #4
Source File: CombatEvent.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void writeToClient() { ClientBoundPacketData combatevent = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_COMBAT_EVENT); MiscSerializer.writeVarIntEnum(combatevent, type); switch (type) { case ENTER_COMBAT: { break; } case END_COMBAT: { VarNumberSerializer.writeVarInt(combatevent, duration); combatevent.writeInt(entityId); break; } case ENTITY_DEAD: { VarNumberSerializer.writeVarInt(combatevent, playerId); combatevent.writeInt(entityId); StringSerializer.writeVarIntUTF8String(combatevent, message); break; } } }
Example #5
Source File: SpawnLiving.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void writeToClient() { ClientBoundPacketData spawnliving = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_LIVING); VarNumberSerializer.writeVarInt(spawnliving, entity.getId()); spawnliving.writeByte(LegacyEntityId.getIntId(rType)); spawnliving.writeInt((int) (x * 32)); spawnliving.writeInt((int) (y * 32)); spawnliving.writeInt((int) (z * 32)); spawnliving.writeByte(yaw); spawnliving.writeByte(pitch); spawnliving.writeByte(headPitch); spawnliving.writeShort(motX); spawnliving.writeShort(motY); spawnliving.writeShort(motZ); NetworkEntityMetadataSerializer.writeLegacyData(spawnliving, version, I18NData.DEFAULT_LOCALE, NetworkEntityMetadataList.EMPTY); codec.write(spawnliving); }
Example #6
Source File: WorldParticle.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void writeToClient() { particle = remapper.getRemap(particle.getClass()).apply(particle); if (particle != null) { ClientBoundPacketData spawnparticle = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WORLD_PARTICLES); spawnparticle.writeInt(LegacyParticle.IntId.getId(particle)); spawnparticle.writeBoolean(longdist); spawnparticle.writeFloat((float) x); spawnparticle.writeFloat((float) y); spawnparticle.writeFloat((float) z); spawnparticle.writeFloat(particle.getOffsetX()); spawnparticle.writeFloat(particle.getOffsetY()); spawnparticle.writeFloat(particle.getOffsetZ()); spawnparticle.writeFloat(particle.getData()); spawnparticle.writeInt(particle.getCount()); for (int data : LegacyParticle.IntId.getData(particle)) { VarNumberSerializer.writeVarInt(spawnparticle, data); } codec.write(spawnparticle); } }
Example #7
Source File: SpawnObject.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void writeSpawnObject() { ClientBoundPacketData spawnobject = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_OBJECT); VarNumberSerializer.writeVarInt(spawnobject, entity.getId()); UUIDSerializer.writeUUID2L(spawnobject, entity.getUUID()); spawnobject.writeByte(LegacyEntityId.getObjectIntId(rType)); spawnobject.writeDouble(x); spawnobject.writeDouble(y); spawnobject.writeDouble(z); spawnobject.writeByte(pitch); spawnobject.writeByte(yaw); spawnobject.writeInt(rObjectdata); spawnobject.writeShort(motX); spawnobject.writeShort(motY); spawnobject.writeShort(motZ); codec.write(spawnobject); }
Example #8
Source File: MiddleStartGame.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void readServerData(ByteBuf serverdata) { player = NetworkEntity.createPlayer(serverdata.readInt()); int gmdata = serverdata.readByte(); gamemodeCurrent = GameMode.getById(gmdata & 0xFFFFFFF7); hardcore = (gmdata & 0x8) == 0x8; gamemodePrevious = GameMode.getById(serverdata.readByte()); worlds = ArraySerializer.readVarIntVarIntUTF8StringArray(serverdata); dimensions = ItemStackSerializer.readDirectTag(serverdata); dimension = StringSerializer.readVarIntUTF8String(serverdata); world = StringSerializer.readVarIntUTF8String(serverdata); hashedSeed = serverdata.readLong(); serverdata.readByte(); maxplayers = TabAPI.getMaxTabSize(); renderDistance = VarNumberSerializer.readVarInt(serverdata); reducedDebugInfo = serverdata.readBoolean(); respawnScreenEnabled = serverdata.readBoolean(); worldDebug = serverdata.readBoolean(); worldFlat = serverdata.readBoolean(); }
Example #9
Source File: ChunkSectonBlockData.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
public static ChunkSectonBlockData readFromStream(ByteBuf stream) { short nonAirBlockCount = stream.readShort(); byte bitsPerBlock = stream.readByte(); short[] palette = ChunkConstants.GLOBAL_PALETTE; if (bitsPerBlock != ChunkConstants.GLOBAL_PALETTE_BITS_PER_BLOCK) { palette = new short[VarNumberSerializer.readVarInt(stream)]; for (int i = 0; i < palette.length; i++) { palette[i] = (short) VarNumberSerializer.readVarInt(stream); } } long[] blockdata = new long[VarNumberSerializer.readVarInt(stream)]; for (int i = 0; i < blockdata.length; i++) { blockdata[i] = stream.readLong(); } return new ChunkSectonBlockData(nonAirBlockCount, palette, bitsPerBlock, blockdata); }
Example #10
Source File: SpawnObject.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void writeSpawnObject() { ClientBoundPacketData spawnobject = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_OBJECT); VarNumberSerializer.writeVarInt(spawnobject, entity.getId()); spawnobject.writeByte(LegacyEntityId.getObjectIntId(rType)); spawnobject.writeInt((int) (x * 32)); spawnobject.writeInt((int) (y * 32)); spawnobject.writeInt((int) (z * 32)); spawnobject.writeByte(pitch); spawnobject.writeByte(yaw); spawnobject.writeInt(rObjectdata); if (rObjectdata > 0) { spawnobject.writeShort(motX); spawnobject.writeShort(motY); spawnobject.writeShort(motZ); } codec.write(spawnobject); }
Example #11
Source File: UseEntity.java From ProtocolSupport with GNU Affero General Public License v3.0 | 6 votes |
@Override protected void readClientData(ByteBuf clientdata) { entityId = VarNumberSerializer.readVarInt(clientdata); action = MiscSerializer.readVarIntEnum(clientdata, Action.CONSTANT_LOOKUP); switch (action) { case INTERACT: { hand = MiscSerializer.readVarIntEnum(clientdata, UsedHand.CONSTANT_LOOKUP); break; } case INTERACT_AT: { interactedAt = new Vector(clientdata.readFloat(), clientdata.readFloat(), clientdata.readFloat()); hand = MiscSerializer.readVarIntEnum(clientdata, UsedHand.CONSTANT_LOOKUP); break; } case ATTACK: { break; } } }
Example #12
Source File: UseEntity.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void readClientData(ByteBuf clientdata) { entityId = VarNumberSerializer.readVarInt(clientdata); action = MiscSerializer.readVarIntEnum(clientdata, Action.CONSTANT_LOOKUP); if (action == Action.INTERACT_AT) { interactedAt = new Vector(clientdata.readFloat(), clientdata.readFloat(), clientdata.readFloat()); } }
Example #13
Source File: BlockPlace.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void readClientData(ByteBuf clientdata) { PositionSerializer.readLegacyPositionLTo(clientdata, position); face = VarNumberSerializer.readVarInt(clientdata); hand = MiscSerializer.readVarIntEnum(clientdata, UsedHand.CONSTANT_LOOKUP); cX = clientdata.readUnsignedByte() / 16.0F; cY = clientdata.readUnsignedByte() / 16.0F; cZ = clientdata.readUnsignedByte() / 16.0F; }
Example #14
Source File: StartGame.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData startgame = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_START_GAME); startgame.writeInt(player.getId()); startgame.writeByte(gamemodeCurrent.getId() | (hardcore ? 0x8 : 0)); startgame.writeInt(LegacyDimension.getId(dimension)); startgame.writeByte(maxplayers); StringSerializer.writeVarIntUTF8String(startgame, "default"); VarNumberSerializer.writeVarInt(startgame, renderDistance); startgame.writeBoolean(reducedDebugInfo); codec.write(startgame); }
Example #15
Source File: EntityAction.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void readClientData(ByteBuf clientdata) { entityId = VarNumberSerializer.readVarInt(clientdata); int actionId = VarNumberSerializer.readVarInt(clientdata); jumpBoost = VarNumberSerializer.readVarInt(clientdata); if (version == ProtocolVersion.MINECRAFT_1_8) { action = actionById8.get(actionId); } else { action = Action.CONSTANT_LOOKUP.getByOrdinal(actionId); } }
Example #16
Source File: MiddleUpdateCommandMinecart.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
public static ServerBoundPacketData create(int entityId, String command, boolean trackOutput) { ServerBoundPacketData updatecommandminecart = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_UPDATE_COMMAND_MINECART); VarNumberSerializer.writeVarInt(updatecommandminecart, entityId); StringSerializer.writeVarIntUTF8String(updatecommandminecart, command); updatecommandminecart.writeBoolean(trackOutput); return updatecommandminecart; }
Example #17
Source File: LoginCustomPayload.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void readClientData(ByteBuf clientdata) { id = VarNumberSerializer.readVarInt(clientdata); if (clientdata.readBoolean()) { data = MiscSerializer.readAllBytesSlice(clientdata, 1048576); } else { data = null; } }
Example #18
Source File: MiddleJigsawGenerate.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToServer() { ServerBoundPacketData jigsawgenerate = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_JIGSAW_GENERATE); PositionSerializer.writePosition(jigsawgenerate, position); levels = VarNumberSerializer.readVarInt(jigsawgenerate); keep = jigsawgenerate.readBoolean(); codec.read(jigsawgenerate); }
Example #19
Source File: EncapsulatedProtocolUtils.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
public static void writeInfo(ByteBuf to, EncapsulatedProtocolInfo info) { VarNumberSerializer.writeVarInt(to, CURRENT_VERSION); if (info.getAddress() != null) { to.writeBoolean(true); byte[] addr = info.getAddress().getAddress().getAddress(); VarNumberSerializer.writeVarInt(to, addr.length); to.writeBytes(addr); VarNumberSerializer.writeVarInt(to, info.getAddress().getPort()); } else { to.writeBoolean(false); } to.writeBoolean(info.hasCompression()); }
Example #20
Source File: SetExperience.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData setexperience = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SET_EXPERIENCE); setexperience.writeFloat(exp); VarNumberSerializer.writeVarInt(setexperience, level); VarNumberSerializer.writeVarInt(setexperience, totalExp); codec.write(setexperience); }
Example #21
Source File: BlockBreakAnimation.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData blockbreakanimation = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_BLOCK_BREAK_ANIMATION); VarNumberSerializer.writeVarInt(blockbreakanimation, entityId); PositionSerializer.writePosition(blockbreakanimation, position); blockbreakanimation.writeByte(stage); codec.write(blockbreakanimation); }
Example #22
Source File: MiddleSpawnObject.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void readServerData(ByteBuf serverdata) { int entityId = VarNumberSerializer.readVarInt(serverdata); UUID uuid = UUIDSerializer.readUUID2L(serverdata); int typeId = serverdata.readUnsignedByte(); NetworkEntityType type = NetworkEntityType.getObjectByNetworkTypeId(typeId); x = serverdata.readDouble(); y = serverdata.readDouble(); z = serverdata.readDouble(); pitch = serverdata.readByte(); yaw = serverdata.readByte(); objectdata = serverdata.readInt(); motX = serverdata.readShort(); motY = serverdata.readShort(); motZ = serverdata.readShort(); if (type == NetworkEntityType.NONE) { if (ServerPlatform.get().getMiscUtils().isDebugging()) { ProtocolSupport.logWarning(MessageFormat.format( "Attempted to spawn unknown object entity type id {0} at {1},{2},{3}", typeId, x, y, z )); } throw CancelMiddlePacketException.INSTANCE; } entity = NetworkEntity.createObject(uuid, entityId, type); }
Example #23
Source File: Title.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { if (action != Action.SET_ACTION_BAR) { ClientBoundPacketData title = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TITLE); int actionId = action.ordinal(); VarNumberSerializer.writeVarInt(title, actionId > 2 ? actionId - 1 : actionId); switch (action) { case SET_TITLE: case SET_SUBTITLE: { StringSerializer.writeVarIntUTF8String(title, ChatAPI.toJSON(LegacyChatJson.convert(version, clientCache.getLocale(), message))); break; } case SET_TIMES: { title.writeInt(fadeIn); title.writeInt(stay); title.writeInt(fadeOut); break; } case HIDE: case RESET: { break; } default: { throw new EncoderException("Should not reach here"); } } codec.write(title); } else { codec.write(Chat.create(MessagePosition.HOTBAR, LegacyChatJson.convert(version, clientCache.getLocale(), message))); } }
Example #24
Source File: SpawnNamed.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData spawnnamed = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_NAMED); VarNumberSerializer.writeVarInt(spawnnamed, entity.getId()); UUIDSerializer.writeUUID2L(spawnnamed, entity.getUUID()); spawnnamed.writeInt((int) (x * 32)); spawnnamed.writeInt((int) (y * 32)); spawnnamed.writeInt((int) (z * 32)); spawnnamed.writeByte(yaw); spawnnamed.writeByte(pitch); spawnnamed.writeShort(0); NetworkEntityMetadataSerializer.writeLegacyData(spawnnamed, version, I18NData.DEFAULT_LOCALE, NetworkEntityMetadataList.EMPTY); codec.write(spawnnamed); }
Example #25
Source File: BlockAction.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData blockaction = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_BLOCK_ACTION); PositionSerializer.writeLegacyPositionL(blockaction, position); blockaction.writeByte(actionId); blockaction.writeByte(actionParam); VarNumberSerializer.writeVarInt(blockaction, BlockRemappingHelper.remapPreFlatteningBlockId(blockDataRemappingTable, blockId)); codec.write(blockaction); }
Example #26
Source File: SpawnObject.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeSpawnThunderbolt() { ClientBoundPacketData spawnglobal = ClientBoundPacketData.create(PacketType.CLIENTBOUND_LEGACY_PLAY_SPAWN_GLOBAL); VarNumberSerializer.writeVarInt(spawnglobal, entity.getId()); spawnglobal.writeByte(1); spawnglobal.writeInt((int) (x * 32)); spawnglobal.writeInt((int) (y * 32)); spawnglobal.writeInt((int) (z * 32)); codec.write(spawnglobal); }
Example #27
Source File: SpawnPainting.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData spawnpainting = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_PAINTING); VarNumberSerializer.writeVarInt(spawnpainting, entity.getId()); UUIDSerializer.writeUUID2L(spawnpainting, entity.getUUID()); StringSerializer.writeVarIntUTF8String(spawnpainting, LegacyPainting.getName(type)); PositionSerializer.writeLegacyPositionL(spawnpainting, position); spawnpainting.writeByte(direction); codec.write(spawnpainting); }
Example #28
Source File: MiddleTabComplete.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToServer() { ServerBoundPacketData tabcomplete = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_TAB_COMPLETE); VarNumberSerializer.writeVarInt(tabcomplete, id); StringSerializer.writeVarIntUTF8String(tabcomplete, string); codec.read(tabcomplete); }
Example #29
Source File: EntitySound.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData entitysound = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ENTITY_SOUND); VarNumberSerializer.writeVarInt(entitysound, id); VarNumberSerializer.writeVarInt(entitysound, category); VarNumberSerializer.writeVarInt(entitysound, entityId); entitysound.writeFloat(volume); entitysound.writeFloat(pitch); codec.write(entitysound); }
Example #30
Source File: SpawnNamed.java From ProtocolSupport with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void writeToClient() { ClientBoundPacketData spawnnamed = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_NAMED); VarNumberSerializer.writeVarInt(spawnnamed, entity.getId()); UUIDSerializer.writeUUID2L(spawnnamed, entity.getUUID()); spawnnamed.writeDouble(x); spawnnamed.writeDouble(y); spawnnamed.writeDouble(z); spawnnamed.writeByte(yaw); spawnnamed.writeByte(pitch); NetworkEntityMetadataSerializer.writeData(spawnnamed, version, I18NData.DEFAULT_LOCALE, NetworkEntityMetadataList.EMPTY); codec.write(spawnnamed); }