use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld in project ViaVersion by ViaVersion.
the class Protocol1_11To1_10 method registerPackets.
@Override
protected void registerPackets() {
entityRewriter.register();
itemRewriter.register();
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Type
map(Type.BYTE);
// Track Entity
handler(entityRewriter.objectTrackerHandler());
}
});
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Entity UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.UNSIGNED_BYTE, Type.VAR_INT);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// 12 - Metadata
map(Types1_9.METADATA_LIST);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityId = wrapper.get(Type.VAR_INT, 0);
// Change Type :)
int type = wrapper.get(Type.VAR_INT, 1);
Entity1_11Types.EntityType entType = MetadataRewriter1_11To1_10.rewriteEntityType(type, wrapper.get(Types1_9.METADATA_LIST, 0));
if (entType != null) {
wrapper.set(Type.VAR_INT, 1, entType.getId());
// Register Type ID
wrapper.user().getEntityTracker(Protocol1_11To1_10.class).addEntity(entityId, entType);
entityRewriter.handleMetadata(entityId, wrapper.get(Types1_9.METADATA_LIST, 0), wrapper.user());
}
}
});
}
});
new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
registerClientbound(ClientboundPackets1_9_3.COLLECT_ITEM, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Collected entity id
map(Type.VAR_INT);
// 1 - Collector entity id
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// 2 - Pickup Count
wrapper.write(Type.VAR_INT, 1);
}
});
}
});
entityRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_9.METADATA_LIST);
registerClientbound(ClientboundPackets1_9_3.ENTITY_TELEPORT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - x
map(Type.DOUBLE);
// 2 - y
map(Type.DOUBLE);
// 3 - z
map(Type.DOUBLE);
// 4 - yaw
map(Type.BYTE);
// 5 - pitch
map(Type.BYTE);
// 6 - onGround
map(Type.BOOLEAN);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int entityID = wrapper.get(Type.VAR_INT, 0);
if (Via.getConfig().isHologramPatch()) {
EntityTracker1_11 tracker = wrapper.user().getEntityTracker(Protocol1_11To1_10.class);
if (tracker.isHologram(entityID)) {
Double newValue = wrapper.get(Type.DOUBLE, 1);
newValue -= (Via.getConfig().getHologramYOffset());
wrapper.set(Type.DOUBLE, 1, newValue);
}
}
}
});
}
});
entityRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
registerClientbound(ClientboundPackets1_9_3.TITLE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Action
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int action = wrapper.get(Type.VAR_INT, 0);
// Handle the new ActionBar
if (action >= 2) {
wrapper.set(Type.VAR_INT, 0, action + 1);
}
}
});
}
});
registerClientbound(ClientboundPackets1_9_3.BLOCK_ACTION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Position
map(Type.POSITION);
// 1 - Action ID
map(Type.UNSIGNED_BYTE);
// 2 - Action Param
map(Type.UNSIGNED_BYTE);
// 3 - Block Type
map(Type.VAR_INT);
// Cheap hack to ensure it's always right block
handler(new PacketHandler() {
@Override
public void handle(final PacketWrapper actionWrapper) throws Exception {
if (Via.getConfig().isPistonAnimationPatch()) {
int id = actionWrapper.get(Type.VAR_INT, 0);
if (id == 33 || id == 29) {
actionWrapper.cancel();
}
}
}
});
}
});
registerClientbound(ClientboundPackets1_9_3.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Position
map(Type.POSITION);
// 1 - Action
map(Type.UNSIGNED_BYTE);
// 2 - NBT data
map(Type.NBT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
CompoundTag tag = wrapper.get(Type.NBT, 0);
if (wrapper.get(Type.UNSIGNED_BYTE, 0) == 1)
EntityIdRewriter.toClientSpawner(tag);
if (tag.contains("id"))
// Handle new identifier
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier((String) tag.get("id").getValue()));
}
});
}
});
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_9_3_4Type(clientWorld));
if (chunk.getBlockEntities() == null)
return;
for (CompoundTag tag : chunk.getBlockEntities()) {
if (tag.contains("id")) {
String identifier = ((StringTag) tag.get("id")).getValue();
if (identifier.equals("MobSpawner")) {
EntityIdRewriter.toClientSpawner(tag);
}
// Handle new identifier
((StringTag) tag.get("id")).setValue(BlockEntityRewriter.toNewIdentifier(identifier));
}
}
}
});
}
});
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
});
}
});
registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
});
}
});
this.registerClientbound(ClientboundPackets1_9_3.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// effectID
this.map(Type.INT);
// pos
this.map(Type.POSITION);
// effectData
this.map(Type.INT);
// serverwide / global
this.map(Type.BOOLEAN);
handler(packetWrapper -> {
int effectID = packetWrapper.get(Type.INT, 0);
if (effectID == 2002) {
int data = packetWrapper.get(Type.INT, 1);
boolean isInstant = false;
Pair<Integer, Boolean> newData = PotionColorMapping.getNewData(data);
if (newData == null) {
Via.getPlatform().getLogger().warning("Received unknown 1.11 -> 1.10.2 potion data (" + data + ")");
data = 0;
} else {
data = newData.key();
isInstant = newData.value();
}
if (isInstant) {
packetWrapper.set(Type.INT, 0, 2007);
}
packetWrapper.set(Type.INT, 1, data);
}
});
}
});
/*
INCOMING PACKETS
*/
registerServerbound(ServerboundPackets1_9_3.PLAYER_BLOCK_PLACEMENT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Location
map(Type.POSITION);
// 1 - Face
map(Type.VAR_INT);
// 2 - Hand
map(Type.VAR_INT);
map(Type.FLOAT, toOldByte);
map(Type.FLOAT, toOldByte);
map(Type.FLOAT, toOldByte);
}
});
registerServerbound(ServerboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Message
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// 100 character limit on older servers
String msg = wrapper.get(Type.STRING, 0);
if (msg.length() > 100) {
wrapper.set(Type.STRING, 0, msg.substring(0, 100));
}
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld in project ViaVersion by ViaVersion.
the class Protocol1_12To1_11_1 method registerPackets.
@Override
protected void registerPackets() {
metadataRewriter.register();
itemRewriter.register();
registerClientbound(ClientboundPackets1_9_3.SPAWN_ENTITY, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Type
map(Type.BYTE);
// Track Entity
handler(metadataRewriter.objectTrackerHandler());
}
});
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Entity UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.VAR_INT);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// 12 - Metadata
map(Types1_12.METADATA_LIST);
// Track mob and rewrite metadata
handler(metadataRewriter.trackerAndRewriterHandler(Types1_12.METADATA_LIST));
}
});
registerClientbound(ClientboundPackets1_9_3.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
if (!Via.getConfig().is1_12NBTArrayFix())
return;
try {
JsonElement obj = Protocol1_9To1_8.FIX_JSON.transform(null, wrapper.passthrough(Type.COMPONENT).toString());
TranslateRewriter.toClient(obj, wrapper.user());
ChatItemRewriter.toClient(obj, wrapper.user());
wrapper.set(Type.COMPONENT, 0, obj);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
Chunk chunk = wrapper.passthrough(type);
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = section.getBlockWithoutData(x, y, z);
// Is this a bed?
if (block == 26) {
// NBT -> { color:14, x:132, y:64, z:222, id:"minecraft:bed" } (Debug output)
CompoundTag tag = new CompoundTag();
// Set color to red (Default in previous versions)
tag.put("color", new IntTag(14));
tag.put("x", new IntTag(x + (chunk.getX() << 4)));
tag.put("y", new IntTag(y + (i << 4)));
tag.put("z", new IntTag(z + (chunk.getZ() << 4)));
tag.put("id", new StringTag("minecraft:bed"));
// Add a fake block entity
chunk.getBlockEntities().add(tag);
}
}
}
}
}
}
});
}
});
metadataRewriter.registerRemoveEntities(ClientboundPackets1_9_3.DESTROY_ENTITIES);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_9_3.ENTITY_METADATA, Types1_12.METADATA_LIST);
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
map(Type.UNSIGNED_BYTE);
map(Type.INT);
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
});
}
});
registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
});
}
});
new SoundRewriter(this, this::getNewSoundId).registerSound(ClientboundPackets1_9_3.SOUND);
// New packet at 0x01
cancelServerbound(ServerboundPackets1_12.PREPARE_CRAFTING_GRID);
// Client Settings (max length changed)
registerServerbound(ServerboundPackets1_12.CLIENT_SETTINGS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Locale
map(Type.STRING);
// 1 - view distance
map(Type.BYTE);
// 2 - chat mode
map(Type.VAR_INT);
// 3 - chat colors
map(Type.BOOLEAN);
// 4 - chat flags
map(Type.UNSIGNED_BYTE);
// 5 - main hand
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// As part of the fix for MC-111054, the max length of
// the locale was raised to 16 (from 7), and the client
// now makes sure that resource packs have names in that
// length. However, for older servers, it is still 7,
// and thus the server will reject it (and the client
// won't know that the pack's invalid).
// The fix is to just silently lower the length. The
// server doesn't actually use the locale anywhere, so
// this is fine.
String locale = wrapper.get(Type.STRING, 0);
if (locale.length() > 7) {
wrapper.set(Type.STRING, 0, locale.substring(0, 7));
}
}
});
}
});
// New packet at 0x17
cancelServerbound(ServerboundPackets1_12.RECIPE_BOOK_DATA);
// New packet 0x19
cancelServerbound(ServerboundPackets1_12.ADVANCEMENT_TAB);
}
use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION);
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
for (ChunkSection section : chunk.getSections()) {
if (section == null)
continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
section.setPaletteEntry(i, protocol.getMappingData().getNewBlockStateId(section.getPaletteEntry(i)));
}
}
}
});
}
});
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_13.EFFECT, new PacketRemapper() {
@Override
public void registerMap() {
// Effect Id
map(Type.INT);
// Location
map(Type.POSITION);
// Data
map(Type.INT);
handler(wrapper -> {
int id = wrapper.get(Type.INT, 0);
if (id == 2000) {
// Smoke
int data = wrapper.get(Type.INT, 1);
switch(data) {
case // North
1:
// North
wrapper.set(Type.INT, 1, 2);
break;
// North-West
case 0:
// West
case 3:
case // South-West
6:
// West
wrapper.set(Type.INT, 1, 4);
break;
// North-East
case 2:
// East
case 5:
case // South-East
8:
// East
wrapper.set(Type.INT, 1, 5);
break;
case // South
7:
// South
wrapper.set(Type.INT, 1, 3);
break;
default:
// Self and other directions
// Down
wrapper.set(Type.INT, 1, 0);
break;
}
} else if (id == 1010) {
// Play record
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewItemId(wrapper.get(Type.INT, 1)));
} else if (id == 2001) {
// Block break + block break sound
wrapper.set(Type.INT, 1, protocol.getMappingData().getNewBlockStateId(wrapper.get(Type.INT, 1)));
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
// Store the player
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientChunks.setEnvironment(dimensionId);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_13.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension ID
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld in project ViaVersion by ViaVersion.
the class Protocol1_10To1_9_3_4 method registerPackets.
@Override
protected void registerPackets() {
itemRewriter.register();
// Named sound effect
registerClientbound(ClientboundPackets1_9_3.NAMED_SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound name
map(Type.STRING);
// 1 - Sound Category
map(Type.VAR_INT);
// 2 - x
map(Type.INT);
// 3 - y
map(Type.INT);
// 4 - z
map(Type.INT);
// 5 - Volume
map(Type.FLOAT);
// 6 - Pitch
map(Type.UNSIGNED_BYTE, TO_NEW_PITCH);
}
});
// Sound effect
registerClientbound(ClientboundPackets1_9_3.SOUND, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Sound name
map(Type.VAR_INT);
// 1 - Sound Category
map(Type.VAR_INT);
// 2 - x
map(Type.INT);
// 3 - y
map(Type.INT);
// 4 - z
map(Type.INT);
// 5 - Volume
map(Type.FLOAT);
// 6 - Pitch
map(Type.UNSIGNED_BYTE, TO_NEW_PITCH);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int id = wrapper.get(Type.VAR_INT, 0);
wrapper.set(Type.VAR_INT, 0, getNewSoundId(id));
}
});
}
});
// Metadata packet
registerClientbound(ClientboundPackets1_9_3.ENTITY_METADATA, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Metadata list
map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
}
});
// Spawn Mob
registerClientbound(ClientboundPackets1_9_3.SPAWN_MOB, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity id
map(Type.VAR_INT);
// 1 - UUID
map(Type.UUID);
// 2 - Entity Type
map(Type.UNSIGNED_BYTE);
// 3 - X
map(Type.DOUBLE);
// 4 - Y
map(Type.DOUBLE);
// 5 - Z
map(Type.DOUBLE);
// 6 - Yaw
map(Type.BYTE);
// 7 - Pitch
map(Type.BYTE);
// 8 - Head Pitch
map(Type.BYTE);
// 9 - Velocity X
map(Type.SHORT);
// 10 - Velocity Y
map(Type.SHORT);
// 11 - Velocity Z
map(Type.SHORT);
// 12 - Metadata
map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
}
});
// Spawn Player
registerClientbound(ClientboundPackets1_9_3.SPAWN_PLAYER, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.VAR_INT);
// 1 - Player UUID
map(Type.UUID);
// 2 - X
map(Type.DOUBLE);
// 3 - Y
map(Type.DOUBLE);
// 4 - Z
map(Type.DOUBLE);
// 5 - Yaw
map(Type.BYTE);
// 6 - Pitch
map(Type.BYTE);
// 7 - Metadata list
map(Types1_9.METADATA_LIST, TRANSFORM_METADATA);
}
});
// Join Game
registerClientbound(ClientboundPackets1_9_3.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Entity ID
map(Type.INT);
// 1 - Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Dimension
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 1);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
// Respawn
registerClientbound(ClientboundPackets1_9_3.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension ID
map(Type.INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
}
});
// Chunk Data
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_9_3_4Type(clientWorld));
if (Via.getConfig().isReplacePistons()) {
int replacementId = Via.getConfig().getPistonReplacementId();
for (ChunkSection section : chunk.getSections()) {
if (section == null)
continue;
section.replacePaletteEntry(36, replacementId);
}
}
}
});
}
});
// Packet Send ResourcePack
registerClientbound(ClientboundPackets1_9_3.RESOURCE_PACK, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - URL
map(Type.STRING);
// 1 - Hash
map(Type.STRING);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ResourcePackTracker tracker = wrapper.user().get(ResourcePackTracker.class);
// Store the hash for resourcepack status
tracker.setLastHash(wrapper.get(Type.STRING, 1));
}
});
}
});
// Packet ResourcePack status
registerServerbound(ServerboundPackets1_9_3.RESOURCE_PACK_STATUS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ResourcePackTracker tracker = wrapper.user().get(ResourcePackTracker.class);
wrapper.write(Type.STRING, tracker.getLastHash());
wrapper.write(Type.VAR_INT, wrapper.read(Type.VAR_INT));
}
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld in project ViaVersion by ViaVersion.
the class PlayerPackets method register.
public static void register(Protocol1_9To1_8 protocol) {
protocol.registerClientbound(ClientboundPackets1_8.CHAT_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Chat Message (json)
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 1 - Chat Positon
map(Type.BYTE);
handler(wrapper -> {
try {
JsonObject obj = (JsonObject) wrapper.get(Type.COMPONENT, 0);
ChatRewriter.toClient(obj, wrapper.user());
} catch (Exception e) {
e.printStackTrace();
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.TAB_LIST, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Header
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
// 1 - Footer
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
}
});
protocol.registerClientbound(ClientboundPackets1_8.DISCONNECT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Reason
map(Type.STRING, Protocol1_9To1_8.FIX_JSON);
}
});
protocol.registerClientbound(ClientboundPackets1_8.TITLE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Action
map(Type.VAR_INT);
// We only handle if the title or subtitle is set then just write through.
handler(wrapper -> {
int action = wrapper.get(Type.VAR_INT, 0);
if (action == 0 || action == 1) {
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
}
});
// Everything else is handled.
}
});
protocol.registerClientbound(ClientboundPackets1_8.PLAYER_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Player X
map(Type.DOUBLE);
// 1 - Player Y
map(Type.DOUBLE);
// 2 - Player Z
map(Type.DOUBLE);
// 3 - Player Yaw
map(Type.FLOAT);
// 4 - Player Pitch
map(Type.FLOAT);
// 5 - Player Flags
map(Type.BYTE);
handler(wrapper -> {
// 6 - Teleport ID was added
wrapper.write(Type.VAR_INT, 0);
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.TEAMS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Team Name
map(Type.STRING);
// 1 - Mode
map(Type.BYTE);
handler(wrapper -> {
// Mode
byte mode = wrapper.get(Type.BYTE, 0);
if (mode == 0 || mode == 2) {
// Display Name
wrapper.passthrough(Type.STRING);
// Prefix
wrapper.passthrough(Type.STRING);
// Suffix
wrapper.passthrough(Type.STRING);
// Friendly Fire
wrapper.passthrough(Type.BYTE);
// Name tag visibility
wrapper.passthrough(Type.STRING);
wrapper.write(Type.STRING, Via.getConfig().isPreventCollision() ? "never" : "");
// Colour
wrapper.passthrough(Type.BYTE);
}
if (mode == 0 || mode == 3 || mode == 4) {
// Players
String[] players = wrapper.passthrough(Type.STRING_ARRAY);
final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
String myName = wrapper.user().getProtocolInfo().getUsername();
String teamName = wrapper.get(Type.STRING, 0);
for (String player : players) {
if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) {
if (mode == 4) {
// since removing add to auto team
// Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
} else {
// since adding remove from auto team
entityTracker.sendTeamPacket(false, true);
entityTracker.setCurrentTeam(teamName);
}
}
}
}
if (mode == 1) {
// Remove team
final EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
String teamName = wrapper.get(Type.STRING, 0);
if (entityTracker.isAutoTeam() && teamName.equals(entityTracker.getCurrentTeam())) {
// team was removed
// Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Player ID
map(Type.INT);
// Parse this info
handler(wrapper -> {
int entityId = wrapper.get(Type.INT, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.addEntity(entityId, Entity1_10Types.EntityType.PLAYER);
tracker.setClientEntityId(entityId);
});
// 1 - Player Gamemode
map(Type.UNSIGNED_BYTE);
// 2 - Player Dimension
map(Type.BYTE);
// 3 - World Difficulty
map(Type.UNSIGNED_BYTE);
// 4 - Max Players (Tab)
map(Type.UNSIGNED_BYTE);
// 5 - Level Type
map(Type.STRING);
// 6 - Reduced Debug info
map(Type.BOOLEAN);
handler(wrapper -> {
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
// Set player gamemode
tracker.setGameMode(GameMode.getById(wrapper.get(Type.UNSIGNED_BYTE, 0)));
});
// Track player's dimension
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.BYTE, 0);
clientWorld.setEnvironment(dimensionId);
});
// Gotta fake their op
handler(wrapper -> {
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
provider.sendPermission(wrapper.user());
});
// Scoreboard will be cleared when join game is received
handler(wrapper -> {
EntityTracker1_9 entityTracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (Via.getConfig().isAutoTeam()) {
entityTracker.setAutoTeam(true);
// Workaround for packet order issue
wrapper.send(Protocol1_9To1_8.class);
wrapper.cancel();
entityTracker.sendTeamPacket(true, true);
entityTracker.setCurrentTeam("viaversion");
} else {
entityTracker.setAutoTeam(false);
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.PLAYER_INFO, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Action
map(Type.VAR_INT);
// 1 - Player Count
map(Type.VAR_INT);
// Due to this being a complex data structure we just use a handler.
handler(wrapper -> {
int action = wrapper.get(Type.VAR_INT, 0);
int count = wrapper.get(Type.VAR_INT, 1);
for (int i = 0; i < count; i++) {
// Player UUID
wrapper.passthrough(Type.UUID);
if (action == 0) {
// add player
// Player Name
wrapper.passthrough(Type.STRING);
int properties = wrapper.passthrough(Type.VAR_INT);
// loop through properties
for (int j = 0; j < properties; j++) {
// name
wrapper.passthrough(Type.STRING);
// value
wrapper.passthrough(Type.STRING);
boolean isSigned = wrapper.passthrough(Type.BOOLEAN);
if (isSigned) {
// signature
wrapper.passthrough(Type.STRING);
}
}
// gamemode
wrapper.passthrough(Type.VAR_INT);
// ping
wrapper.passthrough(Type.VAR_INT);
boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
if (hasDisplayName) {
// display name
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
}
} else if ((action == 1) || (action == 2)) {
// update gamemode || update latency
wrapper.passthrough(Type.VAR_INT);
} else if (action == 3) {
// update display name
boolean hasDisplayName = wrapper.passthrough(Type.BOOLEAN);
if (hasDisplayName) {
// display name
Protocol1_9To1_8.FIX_JSON.write(wrapper, wrapper.read(Type.STRING));
}
} else if (action == 4) {
// remove player
// no fields
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Channel Name
map(Type.STRING);
handler(wrapper -> {
String name = wrapper.get(Type.STRING, 0);
if (name.equalsIgnoreCase("MC|BOpen")) {
// Not used anymore
wrapper.read(Type.REMAINING_BYTES);
wrapper.write(Type.VAR_INT, 0);
}
if (name.equalsIgnoreCase("MC|TrList")) {
// ID
wrapper.passthrough(Type.INT);
Short size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; ++i) {
Item item1 = wrapper.passthrough(Type.ITEM);
ItemRewriter.toClient(item1);
Item item2 = wrapper.passthrough(Type.ITEM);
ItemRewriter.toClient(item2);
boolean present = wrapper.passthrough(Type.BOOLEAN);
if (present) {
Item item3 = wrapper.passthrough(Type.ITEM);
ItemRewriter.toClient(item3);
}
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Dimension
map(Type.INT);
// 1 - Difficulty
map(Type.UNSIGNED_BYTE);
// 2 - GameMode
map(Type.UNSIGNED_BYTE);
// 3 - Level Type
map(Type.STRING);
// Track player's dimension
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimensionId = wrapper.get(Type.INT, 0);
clientWorld.setEnvironment(dimensionId);
}
});
handler(wrapper -> {
// Client unloads chunks on respawn
wrapper.user().get(ClientChunks.class).getLoadedChunks().clear();
int gamemode = wrapper.get(Type.UNSIGNED_BYTE, 0);
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(gamemode));
});
// Fake permissions to get Commandblocks working
handler(wrapper -> {
CommandBlockProvider provider = Via.getManager().getProviders().get(CommandBlockProvider.class);
provider.sendPermission(wrapper.user());
provider.unloadChunks(wrapper.user());
});
}
});
protocol.registerClientbound(ClientboundPackets1_8.GAME_EVENT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Reason
map(Type.UNSIGNED_BYTE);
// 1 - Value
map(Type.FLOAT);
handler(wrapper -> {
short reason = wrapper.get(Type.UNSIGNED_BYTE, 0);
if (reason == 3) {
// Change gamemode
int gamemode = wrapper.get(Type.FLOAT, 0).intValue();
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
tracker.setGameMode(GameMode.getById(gamemode));
} else if (reason == 4) {
// Open credits screen
wrapper.set(Type.FLOAT, 0, 1F);
}
});
}
});
/* Removed packets */
protocol.registerClientbound(ClientboundPackets1_8.SET_COMPRESSION, null, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
CompressionProvider provider = Via.getManager().getProviders().get(CompressionProvider.class);
provider.handlePlayCompression(wrapper.user(), wrapper.read(Type.VAR_INT));
});
}
});
/* Incoming Packets */
protocol.registerServerbound(ServerboundPackets1_9.TAB_COMPLETE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Requested Command
map(Type.STRING);
// 1 - Is Command Block
map(Type.BOOLEAN, Type.NOTHING);
}
});
protocol.registerServerbound(ServerboundPackets1_9.CLIENT_SETTINGS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - locale
map(Type.STRING);
// 1 - View Distance
map(Type.BYTE);
// 2 - Chat Mode
map(Type.VAR_INT, Type.BYTE);
// 3 - If Chat Colours on
map(Type.BOOLEAN);
// 4 - Skin Parts
map(Type.UNSIGNED_BYTE);
handler(wrapper -> {
int hand = wrapper.read(Type.VAR_INT);
if (Via.getConfig().isLeftHandedHandling()) {
// Add 0x80 if left handed
if (hand == 0)
wrapper.set(Type.UNSIGNED_BYTE, 0, (short) (wrapper.get(Type.UNSIGNED_BYTE, 0).intValue() | 0x80));
}
wrapper.sendToServer(Protocol1_9To1_8.class);
wrapper.cancel();
Via.getManager().getProviders().get(MainHandProvider.class).setMainHand(wrapper.user(), hand);
});
}
});
protocol.registerServerbound(ServerboundPackets1_9.ANIMATION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Hand
map(Type.VAR_INT, Type.NOTHING);
}
});
protocol.cancelServerbound(ServerboundPackets1_9.TELEPORT_CONFIRM);
protocol.cancelServerbound(ServerboundPackets1_9.VEHICLE_MOVE);
protocol.cancelServerbound(ServerboundPackets1_9.STEER_BOAT);
protocol.registerServerbound(ServerboundPackets1_9.PLUGIN_MESSAGE, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Channel Name
map(Type.STRING);
handler(wrapper -> {
String name = wrapper.get(Type.STRING, 0);
if (name.equalsIgnoreCase("MC|BSign")) {
Item item = wrapper.passthrough(Type.ITEM);
if (item != null) {
// Written Book
item.setIdentifier(387);
ItemRewriter.rewriteBookToServer(item);
}
}
if (name.equalsIgnoreCase("MC|AutoCmd")) {
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
wrapper.write(Type.BYTE, (byte) 0);
// X
wrapper.passthrough(Type.INT);
// Y
wrapper.passthrough(Type.INT);
// Z
wrapper.passthrough(Type.INT);
// Command
wrapper.passthrough(Type.STRING);
// Flag
wrapper.passthrough(Type.BOOLEAN);
wrapper.clearInputBuffer();
}
if (name.equalsIgnoreCase("MC|AdvCmd")) {
wrapper.set(Type.STRING, 0, "MC|AdvCdm");
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_9.CLIENT_STATUS, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Action ID
map(Type.VAR_INT);
handler(wrapper -> {
int action = wrapper.get(Type.VAR_INT, 0);
if (action == 2) {
// cancel any blocking >.>
EntityTracker1_9 tracker = wrapper.user().getEntityTracker(Protocol1_9To1_8.class);
if (tracker.isBlocking()) {
if (!Via.getConfig().isShowShieldWhenSwordInHand()) {
tracker.setSecondHand(null);
}
tracker.setBlocking(false);
}
}
});
}
});
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - X
map(Type.DOUBLE);
// 1 - Y
map(Type.DOUBLE);
// 2 - Z
map(Type.DOUBLE);
// 3 - Ground
map(Type.BOOLEAN);
handler(new PlayerMovementMapper());
}
});
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_POSITION_AND_ROTATION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - X
map(Type.DOUBLE);
// 1 - Y
map(Type.DOUBLE);
// 2 - Z
map(Type.DOUBLE);
// 3 - Yaw
map(Type.FLOAT);
// 4 - Pitch
map(Type.FLOAT);
// 5 - Ground
map(Type.BOOLEAN);
handler(new PlayerMovementMapper());
}
});
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_ROTATION, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Yaw
map(Type.FLOAT);
// 1 - Pitch
map(Type.FLOAT);
// 2 - Ground
map(Type.BOOLEAN);
handler(new PlayerMovementMapper());
}
});
protocol.registerServerbound(ServerboundPackets1_9.PLAYER_MOVEMENT, new PacketRemapper() {
@Override
public void registerMap() {
// 0 - Ground
map(Type.BOOLEAN);
handler(new PlayerMovementMapper());
}
});
}
Aggregations