Compare commits

...
39 Commits
Author SHA1 Message Date
Nassim Jahnke 31d5a98f26 5.1.0 Release 2024-10-25 18:15:16 +02:00
Nassim Jahnke b3c1266da7 Update ChunkSectionLightImpl call 2024-10-25 18:09:02 +02:00
Nassim Jahnke 0a6d143d92 Remove baby index via parent type 2024-10-24 16:56:54 +02:00
Nassim Jahnke b1f4a88050 Fix 1.20.5->1.20.3 darkness effect transition 2024-10-23 21:26:12 +02:00
FlorianMichael 4f119d26d7 Update version ranges in gradle.properties 2024-10-23 16:27:14 +02:00
Nassim Jahnke afb8384319 Enable bundle feature 2024-10-22 18:42:43 +02:00
Nassim Jahnke f27c977be2 Back to onenable tasks 2024-10-22 18:10:18 +02:00
RK_01 90878517db Fix CLIENT_INFORMATION skin flags data type (#4) 2024-10-22 10:26:05 +02:00
RK_01 a0f2a8595e Fix PLAYER_INFO_UPDATE display name data type (#5) 2024-10-22 10:25:43 +02:00
Nassim Jahnke 2ce11704ba Register tasks in the right place 2024-10-20 19:48:26 +02:00
Nassim Jahnke 0827b6f6bb Handle player info components in 1.20.5->1.20.3 2024-10-19 13:17:13 +02:00
Nassim Jahnke 1c7017a056 Pass position/rotation values directly, fix relative position and rotation handling 2024-10-19 13:10:54 +02:00
FlorianMichael 4d4f66a1a2 Emulate PLAYER_INPUT packet as well 2024-10-19 02:28:26 +02:00
FlorianMichael f274d643a5 Emulate CLIENT_TICK_END packet 2024-10-19 01:47:38 +02:00
FlorianMichael c7324b1b35 Use SET_ENTITY_MOTION and EXPLODE for delta movement translation 2024-10-19 01:19:22 +02:00
FlorianMichael c8ec145880 Always use correct PROFILE_ACTIONS_ENUM from VV types 2024-10-18 23:20:36 +02:00
FlorianMichael 30d3b0d02e Handle new relative arguments in PLAYER_POSITION and TELEPORT_ENTITY 2024-10-18 23:05:41 +02:00
FlorianMichael 545365786f Handle PLAYER_ROTATION packet using PLAYER_LOOK_AT 2024-10-18 21:57:06 +02:00
Nassim Jahnke 1b9d53af2a Create tag if needed 2024-10-17 19:44:37 +02:00
Nassim Jahnke fd85b67a92 Sort recipes 2024-10-17 17:06:56 +02:00
Nassim Jahnke 16eca5f6aa 1.21.2-pre3 2024-10-14 17:55:19 +02:00
Nassim Jahnke c57b238b86 Recipes mostly work now 2024-10-14 17:55:19 +02:00
Nassim Jahnke 5646d04ba9 1.21.2-pre1 2024-10-14 17:55:19 +02:00
Nassim Jahnke 4937ec4800 Start working on recipes 2024-10-14 17:55:19 +02:00
Nassim Jahnke d3be34adc9 Very WIP 24w40a 2024-10-14 17:55:19 +02:00
Nassim Jahnke 49febd1e63 Fix vehicle exiting 2024-10-14 17:55:18 +02:00
Nassim Jahnke 8737b2b51a 24w39a 2024-10-14 17:55:18 +02:00
Nassim Jahnke 1876b9bb95 Convert attributes in item hover event 2024-10-14 17:55:18 +02:00
Nassim Jahnke f2fcc9d02f 24w38a 2024-10-14 17:55:18 +02:00
Nassim Jahnke d0eeae92d3 24w37a 2024-10-14 17:55:18 +02:00
Nassim Jahnke be28d0c3e8 24w36a, mostly 2024-10-14 17:55:18 +02:00
Nassim Jahnke b0276eaa7d Handle item hover events 2024-10-14 17:55:17 +02:00
Nassim Jahnke 6b690a0218 Remove baby entity data from changed water animals 2024-10-14 17:55:17 +02:00
Nassim Jahnke 4bcc213f1b Handle item tags in recipe ingredients 2024-10-14 17:55:17 +02:00
Nassim Jahnke ff94019b08 Actually track inventory state id 2024-10-14 17:55:17 +02:00
Nassim Jahnke 681e8a2f07 Working 24w34a 2024-10-14 17:55:17 +02:00
Nassim Jahnke 5269a610d1 More work 2024-10-14 17:55:17 +02:00
Nassim Jahnke 5cd34e6fa8 WIP 24w33a 2024-10-14 17:55:16 +02:00
Nassim Jahnke 752c5fc48b Bump version to 5.1.0-SNAPSHOT 2024-10-14 17:55:14 +02:00
36 changed files with 2159 additions and 127 deletions

No files matched your search

@@ -48,7 +48,10 @@ public class BukkitPlugin extends JavaPlugin implements ViaBackwardsPlatform {
}
}
private void enable() {
@Override
public void enable() {
ViaBackwardsPlatform.super.enable();
final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion();
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_17)) {
new PlayerItemDropListener(this).register();
@@ -54,6 +54,8 @@ import com.viaversion.viabackwards.protocol.v1_19_1to1_19.Protocol1_19_1To1_19;
import com.viaversion.viabackwards.protocol.v1_20_3to1_20_2.Protocol1_20_3To1_20_2;
import com.viaversion.viabackwards.protocol.v1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viabackwards.protocol.v1_20_2to1_20.Protocol1_20_2To1_20;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.task.PlayerPacketsTickTask;
import com.viaversion.viabackwards.protocol.v1_21to1_20_5.Protocol1_21To1_20_5;
import com.viaversion.viabackwards.protocol.v1_9_3to1_9_1.Protocol1_9_3To1_9_1;
import com.viaversion.viabackwards.protocol.v1_10to1_9_3.Protocol1_10To1_9_3;
@@ -69,7 +71,7 @@ import java.util.logging.Logger;
public interface ViaBackwardsPlatform {
String MINIMUM_VV_VERSION = "5.0.4";
String MINIMUM_VV_VERSION = "5.1.0";
/**
* Initialize ViaBackwards.
@@ -141,6 +143,14 @@ public interface ViaBackwardsPlatform {
protocolManager.registerProtocol(new Protocol1_20_5To1_20_3(), ProtocolVersion.v1_20_3, ProtocolVersion.v1_20_5);
protocolManager.registerProtocol(new Protocol1_21To1_20_5(), ProtocolVersion.v1_20_5, ProtocolVersion.v1_21);
protocolManager.registerProtocol(new Protocol1_21_2To1_21(), ProtocolVersion.v1_21, ProtocolVersion.v1_21_2);
}
default void enable() {
final ProtocolVersion protocolVersion = Via.getAPI().getServerVersion().highestSupportedProtocolVersion();
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_21_2)) {
Via.getPlatform().runRepeatingSync(new PlayerPacketsTickTask(), 1L);
}
}
/**
@@ -75,7 +75,11 @@ public class EntityPositionHandler {
}
}
positionStorage.setCoordinates(x, y, z, relative);
if (relative) {
positionStorage.addRelativePosition(x, y, z);
} else {
positionStorage.setPosition(x, y, z);
}
}
public EntityPositionStorage getStorage(UserConnection user, int entityId) {
@@ -34,15 +34,15 @@ public abstract class EntityPositionStorage {
return z;
}
public void setCoordinates(double x, double y, double z, boolean relative) {
if (relative) {
this.x += x;
this.y += y;
this.z += z;
} else {
this.x = x;
this.y = y;
this.z = z;
}
public void setPosition(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public void addRelativePosition(double relX, double relY, double relZ) {
this.x += relX;
this.y += relY;
this.z += relZ;
}
}
@@ -18,8 +18,6 @@
package com.viaversion.viabackwards.api.entities.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
public abstract class PlayerPositionStorage implements StorableObject {
private double x;
@@ -53,19 +51,15 @@ public abstract class PlayerPositionStorage implements StorableObject {
this.z = z;
}
public void setCoordinates(PacketWrapper wrapper, boolean relative) {
setCoordinates(wrapper.get(Types.DOUBLE, 0), wrapper.get(Types.DOUBLE, 1), wrapper.get(Types.DOUBLE, 2), relative);
public void setPosition(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
}
public void setCoordinates(double x, double y, double z, boolean relative) {
if (relative) {
this.x += x;
this.y += y;
this.z += z;
} else {
this.x = x;
this.y = y;
this.z = z;
}
public void addRelativePosition(double relX, double relY, double relZ) {
this.x += relX;
this.y += relY;
this.z += relZ;
}
}
@@ -35,6 +35,7 @@ import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.rewriter.StructuredItemRewriter;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable;
public class BackwardsStructuredItemRewriter<C extends ClientboundPacketType, S extends ServerboundPacketType,
@@ -19,6 +19,7 @@ package com.viaversion.viabackwards.api.rewriters;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappingDataLoader;
import com.viaversion.viaversion.api.connection.UserConnection;
@@ -60,7 +61,7 @@ public class TranslatableRewriter<C extends ClientboundPacketType> extends Compo
super(protocol, type);
final Map<String, String> translatableMappings = getTranslatableMappings(version);
if (translatableMappings == null) {
protocol.getLogger().warning("Missing " + version + " translatables!");
ViaBackwards.getPlatform().getLogger().warning("Missing " + version + " translatables!");
this.translatables = new HashMap<>();
} else {
this.translatables = translatableMappings;
@@ -19,22 +19,22 @@ package com.viaversion.viabackwards.protocol.template;
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.api.type.types.version.Types1_21;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.api.type.types.version.Types1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.RecipeDisplayRewriter;
// To replace if needed:
// ChunkType1_20_2
// RecipeRewriter1_20_3
// Types1_21
final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter<ClientboundPacket1_21, ServerboundPacket1_20_5, Protocol1_98To1_99> {
final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter<ClientboundPacket1_21_2, ServerboundPacket1_21_2, Protocol1_98To1_99> {
public BlockItemPacketRewriter1_99(final Protocol1_98To1_99 protocol) {
super(protocol, Types1_21.ITEM, Types1_21.ITEM_ARRAY);
super(protocol, Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY);
/*super(protocol,
Types1_21.ITEM, Types1_21.ITEM_ARRAY, Types1_OLD.ITEM, Types1_OLD.ITEM_ARRAY,
Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST, Types1_OLD.ITEM_COST, Types1_OLD.OPTIONAL_ITEM_COST,
@@ -44,27 +44,31 @@ final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRewriter<
@Override
public void registerPackets() {
final BlockRewriter<ClientboundPacket1_21> blockRewriter = BlockRewriter.for1_20_2(protocol);
blockRewriter.registerBlockEvent(ClientboundPackets1_21.BLOCK_EVENT);
blockRewriter.registerBlockUpdate(ClientboundPackets1_21.BLOCK_UPDATE);
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21.SECTION_BLOCKS_UPDATE);
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21.LEVEL_EVENT, 2001);
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_21.BLOCK_ENTITY_DATA);
final BlockRewriter<ClientboundPacket1_21_2> blockRewriter = BlockRewriter.for1_20_2(protocol);
blockRewriter.registerBlockEvent(ClientboundPackets1_21_2.BLOCK_EVENT);
blockRewriter.registerBlockUpdate(ClientboundPackets1_21_2.BLOCK_UPDATE);
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_2.SECTION_BLOCKS_UPDATE);
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_2.LEVEL_EVENT, 2001);
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA);
// registerOpenWindow(ClientboundPackets1_21.OPEN_WINDOW);
registerCooldown(ClientboundPackets1_21.COOLDOWN);
registerSetContent1_17_1(ClientboundPackets1_21.CONTAINER_SET_CONTENT);
registerSetSlot1_17_1(ClientboundPackets1_21.CONTAINER_SET_SLOT);
registerAdvancements1_20_3(ClientboundPackets1_21.UPDATE_ADVANCEMENTS);
registerSetEquipment(ClientboundPackets1_21.SET_EQUIPMENT);
registerContainerClick1_17_1(ServerboundPackets1_20_5.CONTAINER_CLICK);
registerMerchantOffers1_20_5(ClientboundPackets1_21.MERCHANT_OFFERS);
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
registerContainerSetData(ClientboundPackets1_21.CONTAINER_SET_DATA);
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES);
registerExplosion(ClientboundPackets1_21.EXPLODE);
// registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN);
protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, this::passthroughClientboundItem);
registerCooldown1_21_2(ClientboundPackets1_21_2.COOLDOWN);
registerSetContent1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT);
registerSetSlot1_21_2(ClientboundPackets1_21_2.CONTAINER_SET_SLOT);
registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS);
registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT);
registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS);
registerContainerSetData(ClientboundPackets1_21_2.CONTAINER_SET_DATA);
registerLevelParticles1_20_5(ClientboundPackets1_21_2.LEVEL_PARTICLES);
registerExplosion1_21_2(ClientboundPackets1_21_2.EXPLODE);
registerContainerClick1_21_2(ServerboundPackets1_21_2.CONTAINER_CLICK);
registerSetCreativeModeSlot(ServerboundPackets1_21_2.SET_CREATIVE_MODE_SLOT);
new RecipeRewriter1_20_3<>(protocol).register1_20_5(ClientboundPackets1_21.UPDATE_RECIPES);
final RecipeDisplayRewriter<ClientboundPacket1_21_2> recipeRewriter = new RecipeDisplayRewriter<>(protocol);
recipeRewriter.registerUpdateRecipes(ClientboundPackets1_21_2.UPDATE_RECIPES);
recipeRewriter.registerRecipeBookAdd(ClientboundPackets1_21_2.RECIPE_BOOK_ADD);
recipeRewriter.registerPlaceGhostRecipe(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE);
}
}
@@ -25,14 +25,14 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.util.Key;
// Replace if needed
// Types1_OLD
// Types1_21
final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_21, Protocol1_98To1_99> {
final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_21_2, Protocol1_98To1_99> {
public EntityPacketRewriter1_99(final Protocol1_98To1_99 protocol) {
super(protocol, Types1_20_5.ENTITY_DATA_TYPES.optionalComponentType, Types1_20_5.ENTITY_DATA_TYPES.booleanType);
@@ -40,9 +40,9 @@ final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_2
@Override
public void registerPackets() {
registerTrackerWithData1_19(ClientboundPackets1_21.ADD_ENTITY, EntityTypes1_20_5.FALLING_BLOCK);
registerSetEntityData(ClientboundPackets1_21.SET_ENTITY_DATA, /*Types1_OLD.ENTITY_DATA_LIST, */Types1_20_5.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
registerRemoveEntities(ClientboundPackets1_21.REMOVE_ENTITIES);
registerTrackerWithData1_19(ClientboundPackets1_21_2.ADD_ENTITY, EntityTypes1_20_5.FALLING_BLOCK);
registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA, /*Types1_OLD.ENTITY_DATA_LIST, */Types1_20_5.ENTITY_DATA_LIST); // Specify old and new entity data list if changed
registerRemoveEntities(ClientboundPackets1_21_2.REMOVE_ENTITIES);
// TODO Item and sound id changes in registries, probably others as well
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
@@ -51,7 +51,7 @@ final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_2
handleRegistryData1_20_5(wrapper.user(), registryKey, entries); // Caches dimensions to access data like height later and tracks the amount of biomes sent for chunk data
});
protocol.registerClientbound(ClientboundPackets1_21.LOGIN, new PacketHandlers() {
protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, new PacketHandlers() {
@Override
public void register() {
map(Types.INT); // Entity id
@@ -66,10 +66,11 @@ final class EntityPacketRewriter1_99 extends EntityRewriter<ClientboundPacket1_2
map(Types.VAR_INT); // Dimension key
map(Types.STRING); // World
handler(worldDataTrackerHandlerByKey1_20_5(3)); // Tracks world height and name for chunk data and entity (un)tracking
handler(playerTrackerHandler());
}
});
protocol.registerClientbound(ClientboundPackets1_21.RESPAWN, wrapper -> {
protocol.registerClientbound(ClientboundPackets1_21_2.RESPAWN, wrapper -> {
final int dimensionId = wrapper.passthrough(Types.VAR_INT);
final String world = wrapper.passthrough(Types.STRING);
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world); // Tracks world height and name for chunk data and entity (un)tracking
@@ -27,12 +27,12 @@ import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvide
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
import com.viaversion.viaversion.rewriter.ComponentRewriter.ReadType;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
@@ -42,51 +42,52 @@ import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
// Placeholders to replace (in the entire package):
// Protocol1_98To1_99, EntityPacketRewriter1_99, BlockItemPacketRewriter1_99
// Protocol1_20_5To1_21 (the ViaVersion protocol class the mappings depend on)
// ClientboundPacket1_21
// ServerboundPacket1_20_5
// ClientboundPacket1_21_2
// ServerboundPacket1_21_2
// ClientboundConfigurationPackets1_21
// ServerboundConfigurationPackets1_20_5
// EntityTypes1_20_5 (UNMAPPED type)
// 1.99, 1.98
final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacket1_21, ClientboundPacket1_21, ServerboundPacket1_20_5, ServerboundPacket1_20_5> {
final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacket1_21_2, ClientboundPacket1_21_2, ServerboundPacket1_21_2, ServerboundPacket1_21_2> {
// ViaBackwards uses its own mappings and also needs a translatablerewriter for translation mappings
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.99", "1.98", Protocol1_20_5To1_21.class);
private final EntityPacketRewriter1_99 entityRewriter = new EntityPacketRewriter1_99(this);
private final BlockItemPacketRewriter1_99 itemRewriter = new BlockItemPacketRewriter1_99(this);
private final TranslatableRewriter<ClientboundPacket1_21> translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT);
private final TagRewriter<ClientboundPacket1_21> tagRewriter = new TagRewriter<>(this);
private final TranslatableRewriter<ClientboundPacket1_21_2> translatableRewriter = new TranslatableRewriter<>(this, ReadType.NBT);
private final TagRewriter<ClientboundPacket1_21_2> tagRewriter = new TagRewriter<>(this);
public Protocol1_98To1_99() {
super(ClientboundPacket1_21.class, ClientboundPacket1_21.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class);
super(ClientboundPacket1_21_2.class, ClientboundPacket1_21_2.class, ServerboundPacket1_21_2.class, ServerboundPacket1_21_2.class);
}
@Override
protected void registerPackets() {
super.registerPackets();
tagRewriter.registerGeneric(ClientboundPackets1_21.UPDATE_TAGS);
tagRewriter.registerGeneric(ClientboundPackets1_21_2.UPDATE_TAGS);
tagRewriter.registerGeneric(ClientboundConfigurationPackets1_21.UPDATE_TAGS);
final SoundRewriter<ClientboundPacket1_21> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND);
soundRewriter.registerSound1_19_3(ClientboundPackets1_21.SOUND_ENTITY);
soundRewriter.registerStopSound(ClientboundPackets1_21.STOP_SOUND);
final SoundRewriter<ClientboundPacket1_21_2> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND);
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND_ENTITY);
soundRewriter.registerStopSound(ClientboundPackets1_21_2.STOP_SOUND);
new StatisticsRewriter<>(this).register(ClientboundPackets1_21.AWARD_STATS);
//new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21.ENTITY_PROPERTIES);
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS);
//new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES);
// Registers translatable mappings (missing a whole bunch still)
//translatableRewriter.registerOpenWindow(ClientboundPackets1_21.OPEN_WINDOW); // Handled by registerOpenWindow in item rewriters
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_ACTION_BAR_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SET_SUBTITLE_TEXT);
translatableRewriter.registerBossEvent(ClientboundPackets1_21.BOSS_EVENT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_21.TAB_LIST);
translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21.PLAYER_COMBAT_KILL);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.SYSTEM_CHAT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21.DISGUISED_CHAT);
//translatableRewriter.registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN); // Handled by registerOpenScreen in item rewriters
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT);
translatableRewriter.registerBossEvent(ClientboundPackets1_21_2.BOSS_EVENT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_21_2.TAB_LIST);
translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_2.PLAYER_COMBAT_KILL);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SYSTEM_CHAT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISGUISED_CHAT);
translatableRewriter.registerPlayerInfoUpdate1_21_2(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE);
translatableRewriter.registerPing();
}
@@ -111,22 +112,22 @@ final class Protocol1_98To1_99 extends BackwardsProtocol<ClientboundPacket1_21,
}
@Override
public TranslatableRewriter<ClientboundPacket1_21> getComponentRewriter() {
public TranslatableRewriter<ClientboundPacket1_21_2> getComponentRewriter() {
return translatableRewriter;
}
@Override
public TagRewriter<ClientboundPacket1_21> getTagRewriter() {
public TagRewriter<ClientboundPacket1_21_2> getTagRewriter() {
return tagRewriter;
}
@Override
protected PacketTypesProvider<ClientboundPacket1_21, ClientboundPacket1_21, ServerboundPacket1_20_5, ServerboundPacket1_20_5> createPacketTypesProvider() {
protected PacketTypesProvider<ClientboundPacket1_21_2, ClientboundPacket1_21_2, ServerboundPacket1_21_2, ServerboundPacket1_21_2> createPacketTypesProvider() {
return new SimplePacketTypesProvider<>(
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class),
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class),
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class),
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class),
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class),
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class),
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class)
);
}
}
@@ -31,10 +31,11 @@ import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes1_12;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_12;
@@ -237,14 +238,11 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
});
if (ViaBackwards.getConfig().isFix1_13FacePlayer()) {
PacketHandlers movementRemapper = new PacketHandlers() {
@Override
public void register() {
map(Types.DOUBLE);
map(Types.DOUBLE);
map(Types.DOUBLE);
handler(wrapper -> wrapper.user().get(PlayerPositionStorage1_13.class).setCoordinates(wrapper, false));
}
PacketHandler movementRemapper = wrapper -> {
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
wrapper.user().get(PlayerPositionStorage1_13.class).setPosition(x, y, z);
};
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS, movementRemapper); // Player Position
protocol.registerServerbound(ServerboundPackets1_12_1.MOVE_PLAYER_POS_ROT, movementRemapper); // Player Position And Look (serverbound)
@@ -369,7 +369,7 @@ public class BlockItemPacketRewriter1_14 extends BackwardsItemRewriter<Clientbou
ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
ChunkSectionLight sectionLight = new ChunkSectionLightImpl();
ChunkSectionLight sectionLight = ChunkSectionLightImpl.createWithBlockLight();
section.setLight(sectionLight);
if (chunkLight == null) {
sectionLight.setBlockLight(ChunkLightStorage.FULL_LIGHT);
@@ -116,7 +116,7 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol<ClientboundPackets1_
soundRewriter.registerStopSound(ClientboundPackets1_16.STOP_SOUND);
// Login success
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> {
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
// Transform uuid to plain string
UUID uuid = wrapper.read(Types.UUID);
wrapper.write(Types.STRING, uuid.toString());
@@ -28,7 +28,6 @@ import com.viaversion.viaversion.api.minecraft.signature.storage.ChatSession1_19
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.BitSetType;
import com.viaversion.viaversion.api.type.types.version.Types1_19;
import com.viaversion.viaversion.api.type.types.version.Types1_19_3;
import com.viaversion.viaversion.libs.gson.JsonElement;
@@ -45,7 +44,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public final class EntityPacketRewriter1_19_3 extends EntityRewriter<ClientboundPackets1_19_3, Protocol1_19_3To1_19_1> {
private static final BitSetType PROFILE_ACTIONS_ENUM_TYPE = new BitSetType(6);
private static final int[] PROFILE_ACTIONS = {2, 3, 4, 5}; // Ignore initialize chat; add player already handled before
private static final int ADD_PLAYER = 0;
private static final int INITIALIZE_CHAT = 1;
@@ -123,7 +121,7 @@ public final class EntityPacketRewriter1_19_3 extends EntityRewriter<Clientbound
protocol.registerClientbound(ClientboundPackets1_19_3.PLAYER_INFO_UPDATE, ClientboundPackets1_19_1.PLAYER_INFO, wrapper -> {
wrapper.cancel();
final BitSet actions = wrapper.read(PROFILE_ACTIONS_ENUM_TYPE);
final BitSet actions = wrapper.read(Types.PROFILE_ACTIONS_ENUM1_19_3);
final int entries = wrapper.read(Types.VAR_INT);
if (actions.get(ADD_PLAYER)) {
// Special case, as we need to write everything into one action
@@ -291,7 +291,7 @@ public final class Protocol1_19To1_18_2 extends BackwardsProtocol<ClientboundPac
});
// Login changes
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, new PacketHandlers() {
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, new PacketHandlers() {
@Override
public void register() {
map(Types.UUID); // UUID
@@ -76,7 +76,7 @@ public final class Protocol1_20_2To1_20 extends BackwardsProtocol<ClientboundPac
wrapper.write(Types.BYTE, (byte) slot);
});
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> {
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
// We can't set the internal state to configuration here as protocols down the line will expect the state to be play
// Add this *before* sending the ack since the server might immediately answer
wrapper.user().put(new ConfigurationPacketStorage());
@@ -283,7 +283,7 @@ public final class Protocol1_20_3To1_20_2 extends BackwardsProtocol<ClientboundP
}
});
registerClientbound(ClientboundPackets1_20_3.PLAYER_INFO_UPDATE, wrapper -> {
final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM);
final BitSet actions = wrapper.passthrough(Types.PROFILE_ACTIONS_ENUM1_19_3);
final int entries = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < entries; i++) {
wrapper.passthrough(Types.UUID);
@@ -416,4 +416,4 @@ public final class Protocol1_20_3To1_20_2 extends BackwardsProtocol<ClientboundP
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_2.class, ServerboundConfigurationPackets1_20_2.class)
);
}
}
}
@@ -109,6 +109,7 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol<ClientboundP
translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_20_5.PLAYER_COMBAT_KILL);
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.SYSTEM_CHAT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_20_5.DISGUISED_CHAT);
translatableRewriter.registerPlayerInfoUpdate1_20_3(ClientboundPackets1_20_5.PLAYER_INFO_UPDATE);
translatableRewriter.registerPing();
registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO, wrapper -> {
@@ -157,7 +158,7 @@ public final class Protocol1_20_5To1_20_3 extends BackwardsProtocol<ClientboundP
}
}.registerDeclareCommands1_19(ClientboundPackets1_20_5.COMMANDS);
registerClientbound(State.LOGIN, ClientboundLoginPackets.GAME_PROFILE, wrapper -> {
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
wrapper.passthrough(Types.UUID); // UUID
wrapper.passthrough(Types.STRING); // Name
@@ -50,6 +50,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPac
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.StructuredDataConverter;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.util.Key;
import java.util.function.Function;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItemRewriter<ClientboundPacket1_20_5, ServerboundPacket1_20_3, Protocol1_20_5To1_20_3> {
@@ -380,10 +381,11 @@ public final class BlockItemPacketRewriter1_20_5 extends BackwardsStructuredItem
if (customData != null) {
// We later don't know which tags are custom data and which are not because the VV conversion
// keeps converted data, so we backup the original custom data and restore it later
if (oldItem.tag() == null) {
oldItem.setTag(new CompoundTag());
}
oldItem.tag().put(nbtTagName(), customData.copy());
}
if (oldItem.tag() != null && oldItem.tag().isEmpty()) {
} else if (oldItem.tag() != null && oldItem.tag().isEmpty()) {
// Improve item equality checks by removing empty tags
oldItem.setTag(null);
}
@@ -243,14 +243,26 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter<Clientbound
protocol.registerClientbound(ClientboundPackets1_20_5.UPDATE_MOB_EFFECT, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Entity ID
wrapper.passthrough(Types.VAR_INT); // Effect ID
final int effectId = wrapper.passthrough(Types.VAR_INT);
final int amplifier = wrapper.read(Types.VAR_INT);
wrapper.write(Types.BYTE, (byte) MathUtil.clamp(amplifier, Byte.MIN_VALUE, Byte.MAX_VALUE));
wrapper.passthrough(Types.VAR_INT); // Duration
wrapper.passthrough(Types.BYTE); // Flags
wrapper.write(Types.OPTIONAL_COMPOUND_TAG, null); // Add empty factor data
if (effectId == 32) { // Darkness, keep a stable effect
final CompoundTag factorData = new CompoundTag();
factorData.putInt("padding_duration", 22);
factorData.putBoolean("had_effect_last_tick", true);
factorData.putFloat("factor_previous_frame", 0);
factorData.putFloat("factor_start", 1);
factorData.putFloat("factor_target", 1);
factorData.putFloat("factor_current", 1);
wrapper.write(Types.OPTIONAL_COMPOUND_TAG, factorData);
} else {
wrapper.write(Types.OPTIONAL_COMPOUND_TAG, null);
}
});
protocol.registerClientbound(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES, wrapper -> {
@@ -0,0 +1,198 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21;
import com.viaversion.viabackwards.api.BackwardsProtocol;
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.BlockItemPacketRewriter1_21_2;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.ComponentRewriter1_21_2;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter.EntityPacketRewriter1_21_2;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.ItemTagStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.data.entity.EntityTrackerBase;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.Protocol1_21To1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
import com.viaversion.viaversion.rewriter.AttributeRewriter;
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
import com.viaversion.viaversion.rewriter.TagRewriter;
import com.viaversion.viaversion.util.ArrayUtil;
import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap;
public final class Protocol1_21_2To1_21 extends BackwardsProtocol<ClientboundPacket1_21_2, ClientboundPacket1_21, ServerboundPacket1_21_2, ServerboundPacket1_20_5> {
public static final BackwardsMappingData MAPPINGS = new BackwardsMappingData("1.21.2", "1.21", Protocol1_21To1_21_2.class);
private final EntityPacketRewriter1_21_2 entityRewriter = new EntityPacketRewriter1_21_2(this);
private final BlockItemPacketRewriter1_21_2 itemRewriter = new BlockItemPacketRewriter1_21_2(this);
private final TranslatableRewriter<ClientboundPacket1_21_2> translatableRewriter = new ComponentRewriter1_21_2(this);
private final TagRewriter<ClientboundPacket1_21_2> tagRewriter = new TagRewriter<>(this);
public Protocol1_21_2To1_21() {
super(ClientboundPacket1_21_2.class, ClientboundPacket1_21.class, ServerboundPacket1_21_2.class, ServerboundPacket1_20_5.class);
}
@Override
protected void registerPackets() {
super.registerPackets();
registerClientbound(ClientboundPackets1_21_2.UPDATE_TAGS, this::storeTags);
registerClientbound(ClientboundConfigurationPackets1_21.UPDATE_TAGS, this::storeTags);
final SoundRewriter<ClientboundPacket1_21_2> soundRewriter = new SoundRewriter<>(this);
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND);
soundRewriter.registerSound1_19_3(ClientboundPackets1_21_2.SOUND_ENTITY);
soundRewriter.registerStopSound(ClientboundPackets1_21_2.STOP_SOUND);
new StatisticsRewriter<>(this).register(ClientboundPackets1_21_2.AWARD_STATS);
new AttributeRewriter<>(this).register1_21(ClientboundPackets1_21_2.UPDATE_ATTRIBUTES);
translatableRewriter.registerOpenScreen(ClientboundPackets1_21_2.OPEN_SCREEN);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_ACTION_BAR_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_TITLE_TEXT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SET_SUBTITLE_TEXT);
translatableRewriter.registerBossEvent(ClientboundPackets1_21_2.BOSS_EVENT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISCONNECT);
translatableRewriter.registerTabList(ClientboundPackets1_21_2.TAB_LIST);
translatableRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_21_2.PLAYER_COMBAT_KILL);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.SYSTEM_CHAT);
translatableRewriter.registerComponentPacket(ClientboundPackets1_21_2.DISGUISED_CHAT);
translatableRewriter.registerPing();
registerServerbound(ServerboundPackets1_20_5.CLIENT_INFORMATION, this::clientInformation);
registerServerbound(ServerboundConfigurationPackets1_20_5.CLIENT_INFORMATION, this::clientInformation);
registerClientbound(ClientboundConfigurationPackets1_21.UPDATE_ENABLED_FEATURES, wrapper -> {
final String[] enabledFeatures = wrapper.read(Types.STRING_ARRAY);
wrapper.write(Types.STRING_ARRAY, ArrayUtil.add(enabledFeatures, "bundle"));
});
cancelClientbound(ClientboundPackets1_21_2.MOVE_MINECART_ALONG_TRACK); // TODO
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_FINISHED, wrapper -> {
wrapper.passthrough(Types.UUID); // UUID
wrapper.passthrough(Types.STRING); // Name
final int properties = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < properties; i++) {
wrapper.passthrough(Types.STRING); // Name
wrapper.passthrough(Types.STRING); // Value
wrapper.passthrough(Types.OPTIONAL_STRING); // Signature
}
wrapper.write(Types.BOOLEAN, true); // Strict error handling. Always enabled for newer clients, so mimic that behavior
});
registerClientbound(ClientboundPackets1_21_2.SET_TIME, wrapper -> {
wrapper.passthrough(Types.LONG); // Game time
long dayTime = wrapper.read(Types.LONG);
final boolean daylightCycle = wrapper.read(Types.BOOLEAN);
if (!daylightCycle) {
if (dayTime == 0) {
dayTime = -1;
} else {
dayTime = -dayTime;
}
}
wrapper.write(Types.LONG, dayTime);
});
}
private void storeTags(final PacketWrapper wrapper) {
tagRewriter.handleGeneric(wrapper);
wrapper.resetReader();
wrapper.user().get(ItemTagStorage.class).readItemTags(wrapper);
}
private void clientInformation(final PacketWrapper wrapper) {
wrapper.passthrough(Types.STRING); // Locale
wrapper.passthrough(Types.BYTE); // View distance
wrapper.passthrough(Types.VAR_INT); // Chat visibility
wrapper.passthrough(Types.BOOLEAN); // Chat colors
wrapper.passthrough(Types.UNSIGNED_BYTE); // Skin parts
wrapper.passthrough(Types.VAR_INT); // Main hand
wrapper.passthrough(Types.BOOLEAN); // Text filtering enabled
wrapper.passthrough(Types.BOOLEAN); // Allow listing
wrapper.write(Types.VAR_INT, 0); // Particle status, assume 'all'
}
@Override
public void init(final UserConnection user) {
addEntityTracker(user, new EntityTrackerBase(user, EntityTypes1_20_5.PLAYER));
user.put(new InventoryStateIdStorage());
user.put(new ItemTagStorage());
user.put(new RecipeStorage(this));
user.put(new PlayerStorage());
}
@Override
public BackwardsMappingData getMappingData() {
return MAPPINGS;
}
@Override
public EntityPacketRewriter1_21_2 getEntityRewriter() {
return entityRewriter;
}
@Override
public BlockItemPacketRewriter1_21_2 getItemRewriter() {
return itemRewriter;
}
@Override
public TranslatableRewriter<ClientboundPacket1_21_2> getComponentRewriter() {
return translatableRewriter;
}
@Override
public TagRewriter<ClientboundPacket1_21_2> getTagRewriter() {
return tagRewriter;
}
@Override
protected PacketTypesProvider<ClientboundPacket1_21_2, ClientboundPacket1_21, ServerboundPacket1_21_2, ServerboundPacket1_20_5> createPacketTypesProvider() {
return new SimplePacketTypesProvider<>(
packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_21_2.class, ClientboundConfigurationPackets1_21.class),
packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class),
packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_21_2.class, ServerboundConfigurationPackets1_20_5.class),
packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class)
);
}
}
@@ -0,0 +1,289 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter;
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.InventoryStateIdStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.RecipeStorage;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.data.MappingData;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2;
import com.viaversion.viaversion.api.type.types.version.Types1_21;
import com.viaversion.viaversion.api.type.types.version.Types1_21_2;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
import com.viaversion.viaversion.util.Key;
import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.downgradeItemData;
import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.updateItemData;
public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItemRewriter<ClientboundPacket1_21_2, ServerboundPacket1_20_5, Protocol1_21_2To1_21> {
public BlockItemPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) {
super(protocol,
Types1_21_2.ITEM, Types1_21_2.ITEM_ARRAY, Types1_21.ITEM, Types1_21.ITEM_ARRAY,
Types1_21_2.ITEM_COST, Types1_21_2.OPTIONAL_ITEM_COST, Types1_21.ITEM_COST, Types1_21.OPTIONAL_ITEM_COST,
Types1_21_2.PARTICLE, Types1_21.PARTICLE
);
}
@Override
public void registerPackets() {
final BlockRewriter<ClientboundPacket1_21_2> blockRewriter = BlockRewriter.for1_20_2(protocol);
blockRewriter.registerBlockEvent(ClientboundPackets1_21_2.BLOCK_EVENT);
blockRewriter.registerBlockUpdate(ClientboundPackets1_21_2.BLOCK_UPDATE);
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21_2.SECTION_BLOCKS_UPDATE);
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_21_2.LEVEL_EVENT, 2001);
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21_2.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_21_2.BLOCK_ENTITY_DATA);
registerAdvancements1_20_3(ClientboundPackets1_21_2.UPDATE_ADVANCEMENTS);
registerSetEquipment(ClientboundPackets1_21_2.SET_EQUIPMENT);
registerMerchantOffers1_20_5(ClientboundPackets1_21_2.MERCHANT_OFFERS);
registerSetCreativeModeSlot(ServerboundPackets1_20_5.SET_CREATIVE_MODE_SLOT);
registerLevelParticles1_20_5(ClientboundPackets1_21_2.LEVEL_PARTICLES);
protocol.registerClientbound(ClientboundPackets1_21_2.COOLDOWN, wrapper -> {
final MappingData mappingData = protocol.getMappingData();
final String itemIdentifier = wrapper.read(Types.STRING);
final int id = mappingData.getFullItemMappings().id(itemIdentifier);
if (id != -1) {
final int mappedId = mappingData.getFullItemMappings().getNewId(id);
wrapper.write(Types.VAR_INT, mappedId);
} else {
wrapper.cancel();
}
});
protocol.registerClientbound(ClientboundPackets1_21_2.SET_CURSOR_ITEM, ClientboundPackets1_21.CONTAINER_SET_SLOT, wrapper -> {
wrapper.write(Types.BYTE, (byte) -1); // Player inventory
wrapper.write(Types.VAR_INT, wrapper.user().get(InventoryStateIdStorage.class).stateId()); // State id; re-use the last known one
wrapper.write(Types.SHORT, (short) -1); // Cursor
final Item item = wrapper.passthrough(Types1_21_2.ITEM);
handleItemToClient(wrapper.user(), item);
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_CONTENT, wrapper -> {
updateContainerId(wrapper);
final int stateId = wrapper.passthrough(Types.VAR_INT);
wrapper.user().get(InventoryStateIdStorage.class).setStateId(stateId);
final Item[] items = wrapper.read(itemArrayType());
wrapper.write(mappedItemArrayType(), items);
for (int i = 0; i < items.length; i++) {
items[i] = handleItemToClient(wrapper.user(), items[i]);
}
passthroughClientboundItem(wrapper);
});
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_SLOT, wrapper -> {
updateContainerId(wrapper);
final int stateId = wrapper.passthrough(Types.VAR_INT);
wrapper.user().get(InventoryStateIdStorage.class).setStateId(stateId);
wrapper.passthrough(Types.SHORT); // Slot id
passthroughClientboundItem(wrapper);
});
protocol.registerClientbound(ClientboundPackets1_21_2.SET_HELD_SLOT, ClientboundPackets1_21.SET_CARRIED_ITEM);
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_CLOSE, this::updateContainerId);
protocol.registerClientbound(ClientboundPackets1_21_2.CONTAINER_SET_DATA, this::updateContainerId);
protocol.registerClientbound(ClientboundPackets1_21_2.HORSE_SCREEN_OPEN, this::updateContainerId);
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, this::updateContainerIdServerbound);
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLICK, wrapper -> {
updateContainerIdServerbound(wrapper);
wrapper.passthrough(Types.VAR_INT); // State id
wrapper.passthrough(Types.SHORT); // Slot
wrapper.passthrough(Types.BYTE); // Button
wrapper.passthrough(Types.VAR_INT); // Mode
final int length = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < length; i++) {
wrapper.passthrough(Types.SHORT); // Slot
passthroughServerboundItem(wrapper);
}
passthroughServerboundItem(wrapper);
});
protocol.registerServerbound(ServerboundPackets1_20_5.USE_ITEM_ON, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Hand
wrapper.passthrough(Types.BLOCK_POSITION1_14); // Block position
wrapper.passthrough(Types.VAR_INT); // Direction
wrapper.passthrough(Types.FLOAT); // X
wrapper.passthrough(Types.FLOAT); // Y
wrapper.passthrough(Types.FLOAT); // Z
wrapper.passthrough(Types.BOOLEAN); // Inside
wrapper.write(Types.BOOLEAN, false); // World border hit
});
protocol.registerClientbound(ClientboundPackets1_21_2.SET_PLAYER_INVENTORY, ClientboundPackets1_21.CONTAINER_SET_SLOT, wrapper -> {
wrapper.write(Types.BYTE, (byte) -2); // Player inventory
wrapper.write(Types.VAR_INT, 0); // 0 state id
final int slot = wrapper.read(Types.VAR_INT);
wrapper.write(Types.SHORT, (short) slot);
});
protocol.registerClientbound(ClientboundPackets1_21_2.EXPLODE, wrapper -> {
wrapper.passthrough(Types.DOUBLE); // Center X
wrapper.passthrough(Types.DOUBLE); // Center Y
wrapper.passthrough(Types.DOUBLE); // Center Z
// The server will already send block changes separately
wrapper.write(Types.FLOAT, 0F); // Power
wrapper.write(Types.VAR_INT, 0); // No blocks affected
double knockbackX = 0;
double knockbackY = 0;
double knockbackZ = 0;
if (wrapper.read(Types.BOOLEAN)) {
knockbackX = wrapper.read(Types.DOUBLE);
knockbackY = wrapper.read(Types.DOUBLE);
knockbackZ = wrapper.read(Types.DOUBLE);
}
wrapper.write(Types.FLOAT, (float) knockbackX);
wrapper.write(Types.FLOAT, (float) knockbackY);
wrapper.write(Types.FLOAT, (float) knockbackZ);
wrapper.write(Types.VAR_INT, 0); // Block interaction type
final Particle explosionParticle = wrapper.read(Types1_21.PARTICLE);
rewriteParticle(wrapper.user(), explosionParticle);
// As small and large explosion particle
wrapper.write(Types1_21_2.PARTICLE, explosionParticle);
wrapper.write(Types1_21_2.PARTICLE, explosionParticle);
new SoundRewriter<>(protocol).soundHolderHandler().handle(wrapper);
});
protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_ADD, null, wrapper -> {
final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class);
final int size = wrapper.read(Types.VAR_INT);
for (int i = 0; i < size; i++) {
recipeStorage.readRecipe(wrapper);
}
final boolean replace = wrapper.read(Types.BOOLEAN);
if (replace) {
recipeStorage.clearRecipes();
}
recipeStorage.sendRecipes(wrapper.user());
wrapper.cancel();
});
protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_REMOVE, ClientboundPackets1_21.RECIPE, wrapper -> {
final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class);
final int[] ids = wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE);
recipeStorage.lockRecipes(wrapper, ids);
});
protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_SETTINGS, null, wrapper -> {
final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class);
final boolean[] settings = new boolean[RecipeStorage.RECIPE_BOOK_SETTINGS];
for (int i = 0; i < RecipeStorage.RECIPE_BOOK_SETTINGS; i++) {
settings[i] = wrapper.read(Types.BOOLEAN);
}
recipeStorage.setRecipeBookSettings(settings);
wrapper.cancel();
});
protocol.registerClientbound(ClientboundPackets1_21_2.UPDATE_RECIPES, wrapper -> {
// Inputs for furnaces etc. Old clients get these from the full recipes
final int size = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < size; i++) {
wrapper.read(Types.STRING); // Recipe group
wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE); // Items
}
final RecipeStorage recipeStorage = wrapper.user().get(RecipeStorage.class);
recipeStorage.readStoneCutterRecipes(wrapper);
// Send later with the recipe book init
wrapper.cancel();
});
protocol.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, wrapper -> {
this.updateContainerId(wrapper);
wrapper.cancel(); // Full recipe display, this doesn't look mappable
});
protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, wrapper -> {
this.updateContainerIdServerbound(wrapper);
final String recipe = Key.stripMinecraftNamespace(wrapper.read(Types.STRING));
wrapper.write(Types.VAR_INT, Integer.parseInt(recipe));
});
protocol.registerServerbound(ServerboundPackets1_20_5.RECIPE_BOOK_SEEN_RECIPE, wrapper -> {
final String recipe = Key.stripMinecraftNamespace(wrapper.read(Types.STRING));
wrapper.write(Types.VAR_INT, Integer.parseInt(recipe));
});
}
private void updateContainerId(final PacketWrapper wrapper) {
final int containerId = wrapper.read(Types.VAR_INT);
wrapper.write(Types.UNSIGNED_BYTE, (short) containerId);
}
private void updateContainerIdServerbound(final PacketWrapper wrapper) {
final short containerId = wrapper.read(Types.UNSIGNED_BYTE);
final int intId = (byte) containerId;
wrapper.write(Types.VAR_INT, intId);
}
@Override
public void rewriteParticle(final UserConnection connection, final Particle particle) {
super.rewriteParticle(connection, particle);
final String identifier = protocol.getMappingData().getParticleMappings().mappedIdentifier(particle.id());
if (identifier.equals("minecraft:dust_color_transition")) {
argbToVector(particle, 0);
argbToVector(particle, 3);
} else if (identifier.equals("minecraft:dust")) {
argbToVector(particle, 0);
}
}
private void argbToVector(final Particle particle, final int index) {
final int argb = particle.<Integer>removeArgument(index).getValue();
final float r = ((argb >> 16) & 0xFF) / 255F;
final float g = ((argb >> 8) & 0xFF) / 255F;
final float b = (argb & 0xFF) / 255F;
particle.add(index, Types.FLOAT, r);
particle.add(index + 1, Types.FLOAT, g);
particle.add(index + 2, Types.FLOAT, b);
}
@Override
public Item handleItemToClient(final UserConnection connection, final Item item) {
super.handleItemToClient(connection, item);
downgradeItemData(item);
return item;
}
@Override
public Item handleItemToServer(final UserConnection connection, final Item item) {
super.handleItemToServer(connection, item);
updateItemData(item);
return item;
}
}
@@ -0,0 +1,74 @@
/*
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
import com.viaversion.viaversion.util.SerializerVersion;
import com.viaversion.viaversion.util.TagUtil;
public final class ComponentRewriter1_21_2 extends TranslatableRewriter<ClientboundPacket1_21_2> {
public ComponentRewriter1_21_2(final Protocol1_21_2To1_21 protocol) {
super(protocol, ReadType.NBT);
}
@Override
protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) {
super.handleShowItem(connection, itemTag, componentsTag);
if (componentsTag == null) {
return;
}
com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.ComponentRewriter1_21_2.convertAttributes(componentsTag, protocol.getMappingData().getAttributeMappings());
final CompoundTag instrument = TagUtil.getNamespacedCompoundTag(componentsTag, "instrument");
if (instrument != null) {
instrument.remove("description");
}
final CompoundTag useRemainder = TagUtil.getNamespacedCompoundTag(componentsTag, "use_remainder");
final CompoundTag food = TagUtil.getNamespacedCompoundTag(componentsTag, "food");
if (food != null) {
if (useRemainder != null) {
food.put("using_converts_to", useRemainder);
}
food.putFloat("eat_seconds", 1.6F);
}
TagUtil.removeNamespaced(componentsTag, "repairable");
TagUtil.removeNamespaced(componentsTag, "enchantable");
TagUtil.removeNamespaced(componentsTag, "consumable");
TagUtil.removeNamespaced(componentsTag, "use_remainder");
TagUtil.removeNamespaced(componentsTag, "use_cooldown");
TagUtil.removeNamespaced(componentsTag, "item_model");
TagUtil.removeNamespaced(componentsTag, "equippable");
TagUtil.removeNamespaced(componentsTag, "glider");
TagUtil.removeNamespaced(componentsTag, "tooltip_style");
TagUtil.removeNamespaced(componentsTag, "death_protection");
TagUtil.removeNamespaced(componentsTag, "damage_resistant");
}
@Override
protected SerializerVersion inputSerializerVersion() {
return SerializerVersion.V1_20_5;
}
}
@@ -0,0 +1,595 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.api.rewriters.EntityRewriter;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage;
import com.viaversion.viaversion.api.minecraft.Holder;
import com.viaversion.viaversion.api.minecraft.Particle;
import com.viaversion.viaversion.api.minecraft.SoundEvent;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_21_2;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_21;
import com.viaversion.viaversion.api.type.types.version.Types1_21_2;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPacket1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ClientboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ClientVehicleStorage;
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.List;
public final class EntityPacketRewriter1_21_2 extends EntityRewriter<ClientboundPacket1_21_2, Protocol1_21_2To1_21> {
private static final int REL_X = 0;
private static final int REL_Y = 1;
private static final int REL_Z = 2;
private static final int REL_Y_ROT = 3;
private static final int REL_X_ROT = 4;
private static final int REL_DELTA_X = 5;
private static final int REL_DELTA_Y = 6;
private static final int REL_DELTA_Z = 7;
private static final int REL_ROTATE_DELTA = 8;
private boolean warned = ViaBackwards.getConfig().suppressEmulationWarnings();
public EntityPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) {
super(protocol, Types1_21.ENTITY_DATA_TYPES.optionalComponentType, Types1_21.ENTITY_DATA_TYPES.booleanType);
}
@Override
public void registerPackets() {
registerSetEntityData(ClientboundPackets1_21_2.SET_ENTITY_DATA, Types1_21_2.ENTITY_DATA_LIST, Types1_21.ENTITY_DATA_LIST);
registerRemoveEntities(ClientboundPackets1_21_2.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundPackets1_21_2.ADD_ENTITY, wrapper -> {
final int entityId = wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Types.UUID); // Entity UUID
final int entityTypeId = wrapper.passthrough(Types.VAR_INT);
wrapper.passthrough(Types.DOUBLE); // X
wrapper.passthrough(Types.DOUBLE); // Y
wrapper.passthrough(Types.DOUBLE); // Z
wrapper.passthrough(Types.BYTE); // Pitch
wrapper.passthrough(Types.BYTE); // Yaw
wrapper.passthrough(Types.BYTE); // Head yaw
wrapper.passthrough(Types.VAR_INT); // Data
getSpawnTrackerWithDataHandler1_19(EntityTypes1_21_2.FALLING_BLOCK).handle(wrapper);
final EntityType type = EntityTypes1_21_2.getTypeFromId(entityTypeId);
if (type.isOrHasParent(EntityTypes1_21_2.ABSTRACT_BOAT)) {
wrapper.send(Protocol1_21_2To1_21.class);
wrapper.cancel();
// Add boat type to entity data
final List<EntityData> data = new ArrayList<>();
final int boatType = type.isOrHasParent(EntityTypes1_21_2.ABSTRACT_CHEST_BOAT) ? chestBoatTypeFromEntityType(type) : boatTypeFromEntityType(type);
data.add(new EntityData(11, Types1_21.ENTITY_DATA_TYPES.varIntType, boatType));
final PacketWrapper entityDataPacket = wrapper.create(ClientboundPackets1_21.SET_ENTITY_DATA);
entityDataPacket.write(Types.VAR_INT, entityId);
entityDataPacket.write(Types1_21.ENTITY_DATA_LIST, data);
entityDataPacket.send(Protocol1_21_2To1_21.class);
}
});
final RegistryDataRewriter registryDataRewriter = new RegistryDataRewriter(protocol);
registryDataRewriter.addEnchantmentEffectRewriter("change_item_damage", tag -> tag.putString("type", "damage_item"));
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, registryDataRewriter::handle);
protocol.registerClientbound(ClientboundPackets1_21_2.LOGIN, new PacketHandlers() {
@Override
public void register() {
map(Types.INT); // Entity id
map(Types.BOOLEAN); // Hardcore
map(Types.STRING_ARRAY); // World List
map(Types.VAR_INT); // Max players
map(Types.VAR_INT); // View distance
map(Types.VAR_INT); // Simulation distance
map(Types.BOOLEAN); // Reduced debug info
map(Types.BOOLEAN); // Show death screen
map(Types.BOOLEAN); // Limited crafting
map(Types.VAR_INT); // Dimension key
map(Types.STRING); // World
map(Types.LONG); // Seed
map(Types.BYTE); // Gamemode
map(Types.BYTE); // Previous gamemode
map(Types.BOOLEAN); // Debug
map(Types.BOOLEAN); // Flat
map(Types.OPTIONAL_GLOBAL_POSITION); // Last death location
map(Types.VAR_INT); // Portal cooldown
handler(worldDataTrackerHandlerByKey1_20_5(3));
handler(playerTrackerHandler());
read(Types.VAR_INT); // Sea level
}
});
protocol.registerClientbound(ClientboundPackets1_21_2.RESPAWN, wrapper -> {
final int dimensionId = wrapper.passthrough(Types.VAR_INT);
final String world = wrapper.passthrough(Types.STRING);
wrapper.passthrough(Types.LONG); // Seed
wrapper.passthrough(Types.BYTE); // Gamemode
wrapper.passthrough(Types.BYTE); // Previous gamemode
wrapper.passthrough(Types.BOOLEAN); // Debug
wrapper.passthrough(Types.BOOLEAN); // Flat
wrapper.passthrough(Types.OPTIONAL_GLOBAL_POSITION); // Last death location
wrapper.passthrough(Types.VAR_INT); // Portal cooldown
wrapper.read(Types.VAR_INT); // Sea level
trackWorldDataByKey1_20_5(wrapper.user(), dimensionId, world);
});
protocol.registerClientbound(ClientboundPackets1_21_2.ENTITY_POSITION_SYNC, ClientboundPackets1_21.TELEPORT_ENTITY, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Entity ID
wrapper.passthrough(Types.DOUBLE); // X
wrapper.passthrough(Types.DOUBLE); // Y
wrapper.passthrough(Types.DOUBLE); // Z
// Unused
wrapper.read(Types.DOUBLE); // Delta movement X
wrapper.read(Types.DOUBLE); // Delta movement Y
wrapper.read(Types.DOUBLE); // Delta movement Z
final float yaw = wrapper.read(Types.FLOAT);
final float pitch = wrapper.read(Types.FLOAT);
writePackedRotation(wrapper, yaw, pitch);
});
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_ROTATION, ClientboundPackets1_21.PLAYER_LOOK_AT, wrapper -> {
final float yaw = wrapper.passthrough(Types.FLOAT);
final float pitch = wrapper.passthrough(Types.FLOAT);
final double yRadians = Math.toRadians(yaw);
final double xRadians = Math.toRadians(pitch);
final double factor = -Math.cos(-xRadians);
final double deltaX = Math.sin(-yRadians - (float) Math.PI) * factor;
final double deltaY = Math.sin(-xRadians);
final double deltaZ = Math.cos(-yRadians - (float) Math.PI) * factor;
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
wrapper.write(Types.VAR_INT, 0); // From anchor
wrapper.write(Types.DOUBLE, storage.x() + deltaX); // X
wrapper.write(Types.DOUBLE, storage.y() + deltaY); // Y
wrapper.write(Types.DOUBLE, storage.z() + deltaZ); // Z
wrapper.write(Types.BOOLEAN, false); // At entity
final PacketWrapper entityMotionPacket = PacketWrapper.create(ServerboundPackets1_21_2.MOVE_PLAYER_ROT, wrapper.user());
entityMotionPacket.write(Types.FLOAT, yaw);
entityMotionPacket.write(Types.FLOAT, pitch);
entityMotionPacket.write(Types.UNSIGNED_BYTE, (short) 0); // On ground and horizontal collision
entityMotionPacket.sendToServer(Protocol1_21_2To1_21.class);
});
protocol.registerClientbound(ClientboundPackets1_21_2.TELEPORT_ENTITY, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Entity ID
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
final double movementX = wrapper.read(Types.DOUBLE);
final double movementY = wrapper.read(Types.DOUBLE);
final double movementZ = wrapper.read(Types.DOUBLE);
final float yaw = wrapper.read(Types.FLOAT);
final float pitch = wrapper.read(Types.FLOAT);
writePackedRotation(wrapper, yaw, pitch);
final int relativeArguments = wrapper.read(Types.INT);
// Send alongside separate entity motion
wrapper.send(Protocol1_21_2To1_21.class);
wrapper.cancel();
handleRelativeArguments(wrapper, x, y, z, yaw, pitch, relativeArguments, movementX, movementY, movementZ);
});
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_POSITION, wrapper -> {
final int teleportId = wrapper.read(Types.VAR_INT);
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
final double movementX = wrapper.read(Types.DOUBLE);
final double movementY = wrapper.read(Types.DOUBLE);
final double movementZ = wrapper.read(Types.DOUBLE);
final float yaw = wrapper.passthrough(Types.FLOAT);
final float pitch = wrapper.passthrough(Types.FLOAT);
// Just keep the new values in there
final int relativeArguments = wrapper.read(Types.INT);
wrapper.write(Types.BYTE, (byte) relativeArguments);
wrapper.write(Types.VAR_INT, teleportId);
// Send alongside separate entity motion
wrapper.send(Protocol1_21_2To1_21.class);
wrapper.cancel();
handleRelativeArguments(wrapper, x, y, z, yaw, pitch, relativeArguments, movementX, movementY, movementZ);
});
protocol.registerServerbound(ServerboundPackets1_20_5.PLAYER_COMMAND, wrapper -> {
wrapper.passthrough(Types.VAR_INT);
final int action = wrapper.passthrough(Types.VAR_INT);
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
if (action == 0) {
storage.setPlayerCommandTrackedSneaking(true);
} else if (action == 1) {
storage.setPlayerCommandTrackedSneaking(false);
} else if (action == 3) {
storage.setPlayerCommandTrackedSprinting(true);
} else if (action == 4) {
storage.setPlayerCommandTrackedSprinting(false);
}
});
// Now also sent by the player if not in a vehicle, but we can't emulate that here, and otherwise only used in predicates
protocol.registerServerbound(ServerboundPackets1_20_5.PLAYER_INPUT, wrapper -> {
final float sideways = wrapper.read(Types.FLOAT);
final float forward = wrapper.read(Types.FLOAT);
final byte flags = wrapper.read(Types.BYTE);
byte updatedFlags = 0;
if (forward > 0) {
updatedFlags |= 1;
} else if (forward < 0) {
updatedFlags |= 1 << 1;
}
if (sideways < 0) {
updatedFlags |= 1 << 2;
} else if (sideways > 0) {
updatedFlags |= 1 << 3;
}
if ((flags & 1) != 0) { // Jumping
updatedFlags |= 1 << 4;
}
final boolean sneaking = (flags & 2) != 0;
if (sneaking) {
updatedFlags |= 1 << 5;
}
// Sprinting we don't know...
wrapper.write(Types.BYTE, updatedFlags);
// Player input no longer sets the sneaking state on the server
// Send the change separately if needed (= when in a vehicle and player commands aren't sent by the old client)
final PlayerStorage sneakingStorage = wrapper.user().get(PlayerStorage.class);
if (sneakingStorage.setSneaking(sneaking)) {
final PacketWrapper playerCommandPacket = wrapper.create(ServerboundPackets1_21_2.PLAYER_COMMAND);
playerCommandPacket.write(Types.VAR_INT, tracker(wrapper.user()).clientEntityId());
playerCommandPacket.write(Types.VAR_INT, sneaking ? 0 : 1); // Start/stop sneaking
playerCommandPacket.write(Types.VAR_INT, 0); // Data
playerCommandPacket.sendToServer(Protocol1_21_2To1_21.class);
}
});
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS, wrapper -> {
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
fixOnGround(wrapper);
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
storage.setPosition(x, y, z);
});
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_POS_ROT, wrapper -> {
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
final float yaw = wrapper.passthrough(Types.FLOAT);
final float pitch = wrapper.passthrough(Types.FLOAT);
fixOnGround(wrapper);
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
storage.setPosition(x, y, z);
storage.setRotation(yaw, pitch);
});
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_ROT, wrapper -> {
final float yaw = wrapper.passthrough(Types.FLOAT);
final float pitch = wrapper.passthrough(Types.FLOAT);
fixOnGround(wrapper);
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
storage.setRotation(yaw, pitch);
});
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_PLAYER_STATUS_ONLY, this::fixOnGround);
protocol.registerServerbound(ServerboundPackets1_20_5.MOVE_VEHICLE, wrapper -> {
final double x = wrapper.passthrough(Types.DOUBLE);
final double y = wrapper.passthrough(Types.DOUBLE);
final double z = wrapper.passthrough(Types.DOUBLE);
final float yaw = wrapper.passthrough(Types.FLOAT);
final float pitch = wrapper.passthrough(Types.FLOAT);
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
storage.setPosition(x, y, z);
storage.setRotation(yaw, pitch);
});
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_INFO_UPDATE, wrapper -> {
final BitSet actions = wrapper.passthroughAndMap(Types.PROFILE_ACTIONS_ENUM1_21_2, Types.PROFILE_ACTIONS_ENUM1_19_3);
final int entries = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < entries; i++) {
wrapper.passthrough(Types.UUID);
if (actions.get(0)) {
wrapper.passthrough(Types.STRING); // Player Name
final int properties = wrapper.passthrough(Types.VAR_INT);
for (int j = 0; j < properties; j++) {
wrapper.passthrough(Types.STRING); // Name
wrapper.passthrough(Types.STRING); // Value
wrapper.passthrough(Types.OPTIONAL_STRING); // Signature
}
}
if (actions.get(1) && wrapper.passthrough(Types.BOOLEAN)) {
wrapper.passthrough(Types.UUID); // Session UUID
wrapper.passthrough(Types.PROFILE_KEY);
}
if (actions.get(2)) {
wrapper.passthrough(Types.VAR_INT); // Gamemode
}
if (actions.get(3)) {
wrapper.passthrough(Types.BOOLEAN); // Listed
}
if (actions.get(4)) {
wrapper.passthrough(Types.VAR_INT); // Latency
}
if (actions.get(5)) {
final Tag displayName = wrapper.passthrough(Types.OPTIONAL_TAG);
protocol.getComponentRewriter().processTag(wrapper.user(), displayName);
}
// New one
if (actions.get(6)) {
actions.clear(6);
wrapper.read(Types.VAR_INT); // List order
}
}
});
protocol.registerClientbound(ClientboundPackets1_21_2.SET_PASSENGERS, wrapper -> {
final int vehicleId = wrapper.passthrough(Types.VAR_INT);
final int[] passengerIds = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
final ClientVehicleStorage storage = wrapper.user().get(ClientVehicleStorage.class);
if (storage != null && vehicleId == storage.vehicleId()) {
wrapper.user().remove(ClientVehicleStorage.class);
}
final int clientEntityId = tracker(wrapper.user()).clientEntityId();
for (final int passenger : passengerIds) {
if (passenger == clientEntityId) {
wrapper.user().put(new ClientVehicleStorage(vehicleId));
break;
}
}
});
protocol.appendClientbound(ClientboundPackets1_21_2.REMOVE_ENTITIES, wrapper -> {
final ClientVehicleStorage vehicleStorage = wrapper.user().get(ClientVehicleStorage.class);
if (vehicleStorage == null) {
return;
}
final int[] entityIds = wrapper.get(Types.VAR_INT_ARRAY_PRIMITIVE, 0);
for (final int entityId : entityIds) {
if (entityId == vehicleStorage.vehicleId()) {
wrapper.user().remove(ClientVehicleStorage.class);
break;
}
}
});
}
private void writePackedRotation(final PacketWrapper wrapper, final float yaw, final float pitch) {
// Pack y and x rot
wrapper.write(Types.BYTE, (byte) Math.floor(yaw * 256F / 360F));
wrapper.write(Types.BYTE, (byte) Math.floor(pitch * 256F / 360F));
}
private void handleRelativeArguments(
final PacketWrapper wrapper,
double x, double y, double z,
float yaw, float pitch,
final int relativeArguments,
double movementX, double movementY, double movementZ
) {
// Position and rotation
final PlayerStorage storage = wrapper.user().get(PlayerStorage.class);
if ((relativeArguments & 1 << REL_X) != 0) {
x += storage.x();
}
if ((relativeArguments & 1 << REL_Y) != 0) {
y += storage.y();
}
if ((relativeArguments & 1 << REL_Z) != 0) {
z += storage.z();
}
if ((relativeArguments & 1 << REL_Y_ROT) != 0) {
yaw += storage.yaw();
}
if ((relativeArguments & 1 << REL_X_ROT) != 0) {
pitch += storage.pitch();
}
// Movement rotation
if ((relativeArguments & 1 << REL_ROTATE_DELTA) != 0) {
final double deltaYaw = Math.toRadians(storage.yaw() - yaw);
final double deltaYawCos = Math.cos(deltaYaw);
final double deltaYawSin = Math.sin(deltaYaw);
movementX = movementX * deltaYawCos + movementZ * deltaYawSin;
movementZ = movementZ * deltaYawCos - movementX * deltaYawSin;
final double deltaPitch = Math.toRadians(storage.pitch() - pitch);
final double deltaPitchCos = Math.cos(deltaPitch);
final double deltaPitchSin = Math.sin(deltaPitch);
movementY = movementY * deltaPitchCos + movementZ * deltaPitchSin;
movementZ = movementZ * deltaPitchCos - movementY * deltaPitchSin;
}
final boolean relativeDeltaX = (relativeArguments & 1 << REL_DELTA_X) != 0;
final boolean relativeDeltaY = (relativeArguments & 1 << REL_DELTA_Y) != 0;
final boolean relativeDeltaZ = (relativeArguments & 1 << REL_DELTA_Z) != 0;
// Movement
if (relativeDeltaX && relativeDeltaY && relativeDeltaZ) {
final PacketWrapper explosionPacket = wrapper.create(ClientboundPackets1_21.EXPLODE);
explosionPacket.write(Types.DOUBLE, 0.0); // Center X
explosionPacket.write(Types.DOUBLE, 0.0); // Center Y
explosionPacket.write(Types.DOUBLE, 0.0); // Center Z
explosionPacket.write(Types.FLOAT, 0F); // Power
explosionPacket.write(Types.VAR_INT, 0); // Blocks affected
explosionPacket.write(Types.FLOAT, (float) movementX);
explosionPacket.write(Types.FLOAT, (float) movementY);
explosionPacket.write(Types.FLOAT, (float) movementZ);
explosionPacket.write(Types.VAR_INT, 0); // Block interaction
explosionPacket.write(Types1_21.PARTICLE, new Particle(0)); // Small explosion
explosionPacket.write(Types1_21.PARTICLE, new Particle(0)); // Large explosion
explosionPacket.write(Types.SOUND_EVENT, Holder.of(new SoundEvent("", null))); // Explosion sound
explosionPacket.send(Protocol1_21_2To1_21.class);
} else if (!relativeDeltaX && !relativeDeltaY && !relativeDeltaZ) {
final PacketWrapper entityMotionPacket = wrapper.create(ClientboundPackets1_21.SET_ENTITY_MOTION);
entityMotionPacket.write(Types.VAR_INT, tracker(wrapper.user()).clientEntityId());
entityMotionPacket.write(Types.SHORT, (short) (movementX * 8000));
entityMotionPacket.write(Types.SHORT, (short) (movementY * 8000));
entityMotionPacket.write(Types.SHORT, (short) (movementZ * 8000));
entityMotionPacket.send(Protocol1_21_2To1_21.class);
} else if (!warned) {
// Mixed combinations of relative and absolute would require tracking the previous delta movement
// which is quite impossible without doing massive player simulation on protocol level.
// This is bad but so is life.
protocol.getLogger().warning("Mixed combinations of relative and absolute delta movements are not supported for 1.21.1 players. " +
"This will result in incorrect movement for the player. ");
warned = true;
}
// Update at the end
storage.setPosition(x, y, z);
storage.setRotation(yaw, pitch);
}
private int boatTypeFromEntityType(final EntityType type) {
if (type == EntityTypes1_21_2.OAK_BOAT) {
return 0;
} else if (type == EntityTypes1_21_2.SPRUCE_BOAT) {
return 1;
} else if (type == EntityTypes1_21_2.BIRCH_BOAT) {
return 2;
} else if (type == EntityTypes1_21_2.JUNGLE_BOAT) {
return 3;
} else if (type == EntityTypes1_21_2.ACACIA_BOAT) {
return 4;
} else if (type == EntityTypes1_21_2.CHERRY_BOAT) {
return 5;
} else if (type == EntityTypes1_21_2.DARK_OAK_BOAT) {
return 6;
} else if (type == EntityTypes1_21_2.MANGROVE_BOAT) {
return 7;
} else if (type == EntityTypes1_21_2.BAMBOO_RAFT) {
return 8;
} else {
return 0;
}
}
private int chestBoatTypeFromEntityType(final EntityType type) {
if (type == EntityTypes1_21_2.OAK_CHEST_BOAT) {
return 0;
} else if (type == EntityTypes1_21_2.SPRUCE_CHEST_BOAT) {
return 1;
} else if (type == EntityTypes1_21_2.BIRCH_CHEST_BOAT) {
return 2;
} else if (type == EntityTypes1_21_2.JUNGLE_CHEST_BOAT) {
return 3;
} else if (type == EntityTypes1_21_2.ACACIA_CHEST_BOAT) {
return 4;
} else if (type == EntityTypes1_21_2.CHERRY_CHEST_BOAT) {
return 5;
} else if (type == EntityTypes1_21_2.DARK_OAK_CHEST_BOAT) {
return 6;
} else if (type == EntityTypes1_21_2.MANGROVE_CHEST_BOAT) {
return 7;
} else if (type == EntityTypes1_21_2.BAMBOO_CHEST_RAFT) {
return 8;
} else {
return 0;
}
}
private void fixOnGround(final PacketWrapper wrapper) {
final boolean data = wrapper.read(Types.BOOLEAN);
wrapper.write(Types.UNSIGNED_BYTE, data ? (short) 1 : 0); // Carries more data now
}
@Override
protected void registerRewrites() {
filter().mapDataType(Types1_21.ENTITY_DATA_TYPES::byId);
registerEntityDataTypeHandler1_20_3(
Types1_21.ENTITY_DATA_TYPES.itemType,
Types1_21.ENTITY_DATA_TYPES.blockStateType,
Types1_21.ENTITY_DATA_TYPES.optionalBlockStateType,
Types1_21.ENTITY_DATA_TYPES.particleType,
Types1_21.ENTITY_DATA_TYPES.particlesType,
Types1_21.ENTITY_DATA_TYPES.componentType,
Types1_21.ENTITY_DATA_TYPES.optionalComponentType
);
registerBlockStateHandler(EntityTypes1_21_2.ABSTRACT_MINECART, 11);
filter().type(EntityTypes1_21_2.CREAKING).cancel(17); // Active
filter().type(EntityTypes1_21_2.CREAKING).cancel(16); // Can move
filter().type(EntityTypes1_21_2.CREAKING_TRANSIENT).handler((event, data) -> {
if (event.index() > 7) {
event.cancel();
}
});
filter().type(EntityTypes1_21_2.ABSTRACT_BOAT).addIndex(11); // Boat type
filter().type(EntityTypes1_21_2.SALMON).removeIndex(17); // Data type
filter().type(EntityTypes1_21_2.AGEABLE_WATER_CREATURE).removeIndex(16); // Baby
filter().type(EntityTypes1_21_2.ABSTRACT_ARROW).removeIndex(10); // In ground
}
@Override
public EntityType typeFromId(final int type) {
return EntityTypes1_21_2.getTypeFromId(type);
}
@Override
public void onMappingDataLoaded() {
mapTypes();
mapEntityTypeWithData(EntityTypes1_21_2.CREAKING, EntityTypes1_21_2.WARDEN).jsonName();
mapEntityTypeWithData(EntityTypes1_21_2.CREAKING_TRANSIENT, EntityTypes1_21_2.TEXT_DISPLAY);
}
}
@@ -0,0 +1,33 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
public final class InventoryStateIdStorage implements StorableObject {
private int stateId = -1;
public int stateId() {
return stateId;
}
public void setStateId(final int stateId) {
this.stateId = stateId;
}
}
@@ -0,0 +1,56 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.util.Key;
import java.util.HashMap;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.Nullable;
public final class ItemTagStorage implements StorableObject {
private Map<String, int[]> itemTags = new HashMap<>();
public int @Nullable [] itemTag(final String key) {
return itemTags.get(Key.stripMinecraftNamespace(key));
}
public void readItemTags(final PacketWrapper wrapper) {
final int length = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < length; i++) {
final String registryKey = wrapper.passthrough(Types.STRING);
final int tagsSize = wrapper.passthrough(Types.VAR_INT);
final boolean itemRegistry = Key.stripMinecraftNamespace(registryKey).equals("item");
if (itemRegistry) {
this.itemTags = new HashMap<>(tagsSize);
}
for (int j = 0; j < tagsSize; j++) {
final String key = wrapper.passthrough(Types.STRING);
final int[] ids = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
if (itemRegistry) {
this.itemTags.put(Key.stripMinecraftNamespace(key), ids);
}
}
}
}
}
@@ -0,0 +1,117 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage;
import com.viaversion.viabackwards.api.entities.storage.PlayerPositionStorage;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
public final class PlayerStorage extends PlayerPositionStorage {
private static final PlayerInput EMPTY = new PlayerInput(false, false, false, false, false, false, false);
private static final float PLAYER_JUMP_HEIGHT = 0.42F;
private float yaw;
private float pitch;
private boolean playerCommandTrackedSneaking;
private boolean playerCommandTrackedSprinting;
private PlayerInput lastInput = EMPTY;
private double prevX;
private double prevY;
private double prevZ;
public void tick(final UserConnection user) {
final double deltaX = x() - prevX;
final double deltaY = y() - prevY;
final double deltaZ = z() - prevZ;
final double magnitude = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
double directionX = magnitude > 0 ? deltaX / magnitude : 0;
double directionZ = magnitude > 0 ? deltaZ / magnitude : 0;
directionX = Math.max(-1, Math.min(1, directionX));
directionZ = Math.max(-1, Math.min(1, directionZ));
final double angle = Math.toRadians(-yaw);
final double newDirectionX = directionX * Math.cos(angle) - directionZ * Math.sin(angle);
final double newDirectionZ = directionX * Math.sin(angle) + directionZ * Math.cos(angle);
final boolean forward = newDirectionZ >= 0.65F;
final boolean backwards = newDirectionZ <= -0.65F;
final boolean left = newDirectionX >= 0.65F;
final boolean right = newDirectionX <= -0.65F;
final boolean jump = Math.abs(deltaY - PLAYER_JUMP_HEIGHT) <= 1E-4F;
final PlayerInput input = new PlayerInput(forward, backwards, left, right, jump, playerCommandTrackedSneaking, playerCommandTrackedSprinting);
if (!lastInput.equals(input)) {
final PacketWrapper playerInputPacket = PacketWrapper.create(ServerboundPackets1_21_2.PLAYER_INPUT, user);
byte flags = 0;
flags = (byte) (flags | (input.forward() ? 1 : 0));
flags = (byte) (flags | (input.backward() ? 2 : 0));
flags = (byte) (flags | (input.left() ? 4 : 0));
flags = (byte) (flags | (input.right() ? 8 : 0));
flags = (byte) (flags | (input.jump() ? 16 : 0));
flags = (byte) (flags | (input.sneak() ? 32 : 0));
flags = (byte) (flags | (input.sprint() ? 64 : 0));
playerInputPacket.write(Types.BYTE, flags);
playerInputPacket.sendToServer(Protocol1_21_2To1_21.class);
lastInput = input;
}
this.prevX = x();
this.prevY = y();
this.prevZ = z();
}
public float yaw() {
return yaw;
}
public float pitch() {
return pitch;
}
public void setRotation(final float yaw, final float pitch) {
this.yaw = yaw;
this.pitch = pitch;
}
public void setPlayerCommandTrackedSneaking(final boolean playerCommandTrackedSneaking) {
this.playerCommandTrackedSneaking = playerCommandTrackedSneaking;
}
public void setPlayerCommandTrackedSprinting(final boolean playerCommandTrackedSprinting) {
this.playerCommandTrackedSprinting = playerCommandTrackedSprinting;
}
public boolean setSneaking(final boolean sneaking) {
final boolean changed = this.playerCommandTrackedSneaking != sneaking;
this.playerCommandTrackedSneaking = sneaking;
return changed;
}
public record PlayerInput(boolean forward, boolean backward, boolean left, boolean right, boolean jump,
boolean sneak, boolean sprint) {
}
}
@@ -0,0 +1,464 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage;
import com.google.common.base.Preconditions;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.HolderSet;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.api.type.types.version.Types1_21_2;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
// Mostly a lost cause as the server will not send all the necessary data.
// Recipe displays can also be different from the actual recipe - at the end of the same,
// the server will still properly handle inputs, but we can't fully reconstruct the recipe book.
public final class RecipeStorage implements StorableObject {
// Pairs of open + filtering for: Crafting, furnace, blast furnace, smoker
public static final int RECIPE_BOOK_SETTINGS = 4 * 2;
private static final String[] EMPTY_STRINGS = new String[0];
private final List<Recipe> recipes = new ArrayList<>();
private final List<Recipe> tempRecipes = new ArrayList<>();
private final List<StoneCutterRecipe> stoneCutterRecipes = new ArrayList<>();
private boolean[] recipeBookSettings = new boolean[RECIPE_BOOK_SETTINGS];
private final Protocol1_21_2To1_21 protocol;
public RecipeStorage(final Protocol1_21_2To1_21 protocol) {
this.protocol = protocol;
}
abstract static class Recipe {
private static final int FOOD_CRAFTING_BOOK_CATEGORY = 0;
private static final int BLOCKS_CRAFTING_BOOK_CATEGORY = 1;
private static final int MISC_CRAFTING_BOOK_CATEGORY = 2;
protected int index;
private Integer group;
private int category;
private boolean highlight;
private boolean locked;
abstract void write(PacketWrapper wrapper);
void writeGroup(final PacketWrapper wrapper) {
wrapper.write(Types.STRING, group != null ? Integer.toString(group) : "");
}
void writeIngredients(final PacketWrapper wrapper, final Item[][] ingredients) {
wrapper.write(Types.VAR_INT, ingredients.length);
for (final Item[] ingredient : ingredients) {
writeIngredient(wrapper, ingredient);
}
}
void writeIngredient(final PacketWrapper wrapper, final Item[] ingredient) {
final Item[] copy = new Item[ingredient.length];
for (int i = 0; i < ingredient.length; i++) {
copy[i] = ingredient[i].copy();
}
wrapper.write(Types1_21_2.ITEM_ARRAY, copy);
}
void writeResult(final PacketWrapper wrapper, final Item result) {
wrapper.write(Types1_21_2.ITEM, result.copy());
}
void writeCategory(final PacketWrapper wrapper) {
// TODO Doesn't translate exactly
final int craftingBookCategory = switch (category) {
case 4, 9, 12 -> FOOD_CRAFTING_BOOK_CATEGORY;
case 0, 5, 7, 10 -> BLOCKS_CRAFTING_BOOK_CATEGORY;
case 1, 2, 3, 6, 8, 11 -> MISC_CRAFTING_BOOK_CATEGORY;
default -> MISC_CRAFTING_BOOK_CATEGORY;
};
wrapper.write(Types.VAR_INT, craftingBookCategory);
}
int category() {
return category;
}
}
public void sendRecipes(final UserConnection connection) {
// Fill from temp recipes so we can clear before if needed
if (!tempRecipes.isEmpty()) {
this.recipes.addAll(tempRecipes);
tempRecipes.clear();
}
int highestIndex = -1;
for (final Recipe recipe : recipes) {
highestIndex = Math.max(highestIndex, recipe.index);
}
// Add stonecutter recipes from update_recipes
final List<Recipe> recipes = new ArrayList<>(this.recipes);
for (final StoneCutterRecipe recipe : stoneCutterRecipes) {
recipe.index = ++highestIndex;
recipes.add(recipe);
}
// Sort by id
recipes.sort(Comparator.comparingInt(a -> a.index));
// Since the server only sends unlocked recipes, we need to re-send all recipes in UPDATE_RECIPES
final PacketWrapper updateRecipesPacket = PacketWrapper.create(ClientboundPackets1_21.UPDATE_RECIPES, connection);
updateRecipesPacket.write(Types.VAR_INT, recipes.size());
for (final Recipe recipe : recipes) {
updateRecipesPacket.write(Types.STRING, identifier(recipe.index));
recipe.write(updateRecipesPacket);
}
updateRecipesPacket.send(Protocol1_21_2To1_21.class);
sendUnlockedRecipes(connection, recipes);
}
private static String identifier(final int recipeIndex) {
// Use index as the recipe identifier, add leading zeros to keept it sorted
return String.format("%06d", recipeIndex);
}
public void lockRecipes(final PacketWrapper wrapper, final int[] ids) {
for (final int id : ids) {
recipes.get(id).locked = true;
}
wrapper.write(Types.VAR_INT, 2); // Remove recipes
for (final boolean recipeBookSetting : recipeBookSettings) {
wrapper.write(Types.BOOLEAN, recipeBookSetting);
}
final String[] recipeKeys = new String[ids.length];
for (int i = 0; i < ids.length; i++) {
recipeKeys[i] = identifier(ids[i]);
}
wrapper.write(Types.STRING_ARRAY, recipeKeys);
}
private void sendUnlockedRecipes(final UserConnection connection, final List<Recipe> recipes) {
final PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_21.RECIPE, connection);
wrapper.write(Types.VAR_INT, 0); // Init recipes
for (final boolean recipeBookSetting : recipeBookSettings) {
wrapper.write(Types.BOOLEAN, recipeBookSetting);
}
// Use index as the recipe identifier. We only know the unlocked ones, so send all
final String[] recipeKeys = new String[recipes.size()];
final List<String> highlightRecipes = new ArrayList<>();
for (int i = 0; i < recipes.size(); i++) {
recipeKeys[i] = identifier(i);
if (recipes.get(i).highlight) {
highlightRecipes.add(recipeKeys[i]);
}
}
wrapper.write(Types.STRING_ARRAY, recipeKeys);
wrapper.write(Types.STRING_ARRAY, highlightRecipes.toArray(EMPTY_STRINGS));
wrapper.send(Protocol1_21_2To1_21.class);
}
public void readRecipe(final PacketWrapper wrapper) {
final int id = wrapper.read(Types.VAR_INT);
final int type = wrapper.passthrough(Types.VAR_INT);
final Recipe recipe = switch (type) {
case 0 -> readShapeless(wrapper);
case 1 -> readShaped(wrapper);
case 2 -> readFurnace(wrapper);
case 3 -> readStoneCutter(wrapper);
case 4 -> readSmithing(wrapper);
default -> null;
};
final Integer group = wrapper.read(Types.OPTIONAL_VAR_INT);
final int category = wrapper.read(Types.VAR_INT);
if (wrapper.read(Types.BOOLEAN)) {
final int ingredientsSize = wrapper.read(Types.VAR_INT);
for (int j = 0; j < ingredientsSize; j++) {
//handleIngredient(wrapper); // Items //TODO ?
wrapper.read(Types.HOLDER_SET);
}
}
final byte flags = wrapper.read(Types.BYTE);
if (recipe != null) {
recipe.index = id;
recipe.group = group;
recipe.category = category;
recipe.highlight = (flags & 2) != 0;
}
}
private Recipe readShapeless(final PacketWrapper wrapper) {
final Item[][] ingredients = readSlotDisplayList(wrapper);
final Item result = readSingleSlotDisplay(wrapper);
readSlotDisplay(wrapper); // Crafting station
return add(new ShapelessRecipe(ingredients, result));
}
private Recipe readShaped(final PacketWrapper wrapper) {
final int width = wrapper.passthrough(Types.VAR_INT);
final int height = wrapper.passthrough(Types.VAR_INT);
final Item[][] ingredients = readSlotDisplayList(wrapper);
final Item result = readSingleSlotDisplay(wrapper);
readSlotDisplay(wrapper); // Crafting station
return add(new ShapedRecipe(width, height, ingredients, result));
}
private Recipe readFurnace(final PacketWrapper wrapper) {
final Item[] ingredient = readSlotDisplay(wrapper);
readSlotDisplay(wrapper); // Fuel
final Item result = readSingleSlotDisplay(wrapper);
readSlotDisplay(wrapper); // Crafting station
final int duration = wrapper.read(Types.VAR_INT);
final float experience = wrapper.read(Types.FLOAT);
return add(new FurnaceRecipe(ingredient, result, duration, experience));
}
private Recipe readStoneCutter(final PacketWrapper wrapper) {
// Use values from UPDATE_RECIPES instead
readSlotDisplay(wrapper); // Input
readSlotDisplay(wrapper); // Result
readSlotDisplay(wrapper); // Crafting station
return null;
}
private Recipe readSmithing(final PacketWrapper wrapper) {
// TODO Combine with update_recipes?
readSlotDisplay(wrapper); // Template
readSlotDisplay(wrapper); // Base
readSlotDisplay(wrapper); // Addition
readSlotDisplay(wrapper); // Result
readSlotDisplay(wrapper); // Crafting station
return null;
}
private Recipe add(final Recipe recipe) {
tempRecipes.add(recipe);
return recipe;
}
private Item[][] readSlotDisplayList(final PacketWrapper wrapper) {
final int size = wrapper.passthrough(Types.VAR_INT);
final Item[][] ingredients = new Item[size][];
for (int i = 0; i < size; i++) {
ingredients[i] = readSlotDisplay(wrapper);
}
return ingredients;
}
private Item readSingleSlotDisplay(final PacketWrapper wrapper) {
final Item[] items = readSlotDisplay(wrapper);
return items.length == 0 ? new StructuredItem(1, 1) : items[0];
}
private Item[] readSlotDisplay(final PacketWrapper wrapper) {
// empty, any_fuel, smithing_trim are empty
final int type = wrapper.read(Types.VAR_INT);
return switch (type) {
case 2 -> {
final int id = wrapper.read(Types.VAR_INT);
if (id == 0) {
protocol.getLogger().warning("Empty item id in recipe");
yield new Item[0];
}
yield new Item[]{new StructuredItem(rewriteItemId(id), 1)};
}
case 3 -> {
final Item item = wrapper.read(Types1_21_2.ITEM);
protocol.getItemRewriter().handleItemToClient(wrapper.user(), item);
if (item.isEmpty()) {
protocol.getLogger().warning("Empty item in recipe");
yield new Item[0];
}
yield new Item[]{item};
}
case 4 -> {
wrapper.read(Types.STRING); // Tag key // TODO Probably not even worth the effort
yield new Item[0];
}
case 5 -> {
readSlotDisplay(wrapper); // Base
readSlotDisplay(wrapper); // Material
readSlotDisplay(wrapper); // Pattern
yield new Item[0];
}
case 6 -> {
readSlotDisplay(wrapper); // Input
readSlotDisplay(wrapper); // Remainder
yield new Item[0];
}
case 7 -> readSlotDisplayList(wrapper)[0]; // Composite
default -> new Item[0];
};
}
private int rewriteItemId(final int id) {
return protocol.getMappingData().getNewItemId(id);
}
public void readStoneCutterRecipes(final PacketWrapper wrapper) {
stoneCutterRecipes.clear();
final int stonecutterRecipesSize = wrapper.read(Types.VAR_INT);
for (int i = 0; i < stonecutterRecipesSize; i++) {
// The ingredients are what's actually used in client prediction, they're the important part
final Item[] ingredient = readHolderSet(wrapper);
// TODO Probably not actually the result, might have to combine with update_recipes
final Item result = readSingleSlotDisplay(wrapper);
stoneCutterRecipes.add(new StoneCutterRecipe(ingredient, result));
}
}
private Item[] readHolderSet(final PacketWrapper wrapper) {
final HolderSet holderSet = wrapper.read(Types.HOLDER_SET);
if (holderSet.hasTagKey()) {
return new Item[]{new StructuredItem(1, 1)}; // TODO Probably not even worth the effort
}
final int[] ids = holderSet.ids();
for (int i = 0; i < ids.length; i++) {
ids[i] = rewriteItemId(ids[i]);
}
final Item[] ingredient = new Item[ids.length];
for (int i = 0; i < ingredient.length; i++) {
ingredient[i] = new StructuredItem(ids[i], 1);
}
return ingredient;
}
private static final class ShapelessRecipe extends Recipe {
private static final int SERIALIZER_ID = 1;
private final Item[][] ingredients;
private final Item result;
private ShapelessRecipe(final Item[][] ingredients, final Item result) {
this.ingredients = ingredients;
this.result = result;
}
@Override
public void write(final PacketWrapper wrapper) {
wrapper.write(Types.VAR_INT, SERIALIZER_ID);
writeGroup(wrapper);
writeCategory(wrapper);
writeIngredients(wrapper, ingredients);
writeResult(wrapper, result);
}
}
private static final class ShapedRecipe extends Recipe {
private static final int SERIALIZER_ID = 0;
private final int width;
private final int height;
private final Item[][] ingredients;
private final Item result;
private ShapedRecipe(final int width, final int height, final Item[][] ingredients, final Item result) {
this.width = width;
this.height = height;
this.ingredients = ingredients;
this.result = result;
}
@Override
public void write(final PacketWrapper wrapper) {
wrapper.write(Types.VAR_INT, SERIALIZER_ID);
writeGroup(wrapper);
writeCategory(wrapper);
wrapper.write(Types.VAR_INT, width);
wrapper.write(Types.VAR_INT, height);
Preconditions.checkArgument(width * height == ingredients.length, "Invalid shaped recipe");
// No length prefix
for (final Item[] ingredient : ingredients) {
writeIngredient(wrapper, ingredient);
}
writeResult(wrapper, result);
wrapper.write(Types.BOOLEAN, false); // Doesn't matter for the init
}
}
private static final class FurnaceRecipe extends Recipe {
private final Item[] ingredient;
private final Item result;
private final float experience;
private final int cookingTime;
private FurnaceRecipe(final Item[] ingredient, final Item result, final int cookingTime, final float experience) {
this.ingredient = ingredient;
this.result = result;
this.experience = experience;
this.cookingTime = cookingTime;
}
@Override
public void write(final PacketWrapper wrapper) {
wrapper.write(Types.VAR_INT, serializerId());
writeGroup(wrapper);
writeCategory(wrapper);
writeIngredient(wrapper, ingredient);
writeResult(wrapper, result);
wrapper.write(Types.FLOAT, experience);
wrapper.write(Types.VAR_INT, cookingTime);
}
private int serializerId() {
return switch (category()) {
case 4, 5, 6 -> 15; // Furnace food, bocks, misc
case 7, 8 -> 16; // Blast furnace blocks, misc
case 9 -> 17; // Smoker
case 12 -> 18; // Campfire
default -> 15;
};
}
}
private static final class StoneCutterRecipe extends Recipe {
private static final int SERIALIZER_ID = 19;
private final Item[] ingredient;
private final Item result;
private StoneCutterRecipe(final Item[] ingredient, final Item result) {
this.ingredient = ingredient;
this.result = result;
}
@Override
public void write(final PacketWrapper wrapper) {
wrapper.write(Types.VAR_INT, SERIALIZER_ID);
writeGroup(wrapper);
writeIngredient(wrapper, ingredient);
writeResult(wrapper, result);
}
}
public void setRecipeBookSettings(final boolean[] recipeBookSettings) {
this.recipeBookSettings = recipeBookSettings;
}
public void clearRecipes() {
recipes.clear();
}
}
@@ -0,0 +1,63 @@
/*
* This file is part of ViaBackwards - https://github.com/ViaVersion/ViaBackwards
* Copyright (C) 2016-2024 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.viaversion.viabackwards.protocol.v1_21_2to1_21.task;
import com.viaversion.viabackwards.ViaBackwards;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.Protocol1_21_2To1_21;
import com.viaversion.viabackwards.protocol.v1_21_2to1_21.storage.PlayerStorage;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.packet.ServerboundPackets1_21_2;
import com.viaversion.viaversion.protocols.v1_21to1_21_2.storage.ClientVehicleStorage;
import io.netty.channel.Channel;
import java.util.logging.Level;
public final class PlayerPacketsTickTask implements Runnable {
@Override
public void run() {
for (final UserConnection user : Via.getManager().getConnectionManager().getConnections()) {
if (user.getProtocolInfo().getClientState() != State.PLAY || !user.getProtocolInfo().getPipeline().contains(Protocol1_21_2To1_21.class)) {
continue;
}
final Channel channel = user.getChannel();
channel.eventLoop().submit(() -> {
if (!channel.isActive()) {
return;
}
try {
if (!user.has(ClientVehicleStorage.class)) {
final PlayerStorage playerStorage = user.get(PlayerStorage.class);
playerStorage.tick(user);
}
} catch (Throwable t) {
ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending player input packet.", t);
}
try {
final PacketWrapper clientTickEndPacket = PacketWrapper.create(ServerboundPackets1_21_2.CLIENT_TICK_END, user);
clientTickEndPacket.sendToServer(Protocol1_21_2To1_21.class);
} catch (Throwable t) {
ViaBackwards.getPlatform().getLogger().log(Level.SEVERE, "Error while sending client tick end packet.", t);
}
});
}
}
}
@@ -1,4 +1,114 @@
{
"1.21.2": {
"attribute.name.tempt_range": "Mob Tempt Range",
"block.minecraft.creaking_heart": "Creaking Heart",
"block.minecraft.pale_hanging_moss": "Pale Hanging Moss",
"block.minecraft.pale_moss_block": "Pale Moss Block",
"block.minecraft.pale_moss_carpet": "Pale Moss Carpet",
"block.minecraft.pale_oak_button": "Pale Oak Button",
"block.minecraft.pale_oak_door": "Pale Oak Door",
"block.minecraft.pale_oak_fence": "Pale Oak Fence",
"block.minecraft.pale_oak_fence_gate": "Pale Oak Fence Gate",
"block.minecraft.pale_oak_hanging_sign": "Pale Oak Hanging Sign",
"block.minecraft.pale_oak_leaves": "Pale Oak Leaves",
"block.minecraft.pale_oak_log": "Pale Oak Log",
"block.minecraft.pale_oak_planks": "Pale Oak Planks",
"block.minecraft.pale_oak_pressure_plate": "Pale Oak Pressure Plate",
"block.minecraft.pale_oak_sapling": "Pale Oak Sapling",
"block.minecraft.pale_oak_sign": "Pale Oak Sign",
"block.minecraft.pale_oak_slab": "Pale Oak Slab",
"block.minecraft.pale_oak_stairs": "Pale Oak Stairs",
"block.minecraft.pale_oak_trapdoor": "Pale Oak Trapdoor",
"block.minecraft.pale_oak_wood": "Pale Oak Wood",
"block.minecraft.potted_pale_oak_sapling": "Potted Pale Oak Sapling",
"block.minecraft.stripped_pale_oak_log": "Stripped Pale Oak Log",
"block.minecraft.stripped_pale_oak_wood": "Stripped Pale Oak Wood",
"commands.drop.no_loot_table.block": "Block %s has no loot table",
"commands.rotate.success": "Rotated %s",
"commands.schedule.macro": "Can't schedule a macro",
"commands.setidletimeout.success.disabled": "The player idle timeout is now disabled",
"container.beehive.bees": "Bees: %s / %s",
"container.beehive.honey": "Honey: %s / %s",
"dataPack.minecart_improvements.description": "Improved movement for Minecarts",
"dataPack.minecart_improvements.name": "Minecart Improvements",
"dataPack.redstone_experiments.description": "Experimental Redstone changes",
"dataPack.redstone_experiments.name": "Redstone Experiments",
"dataPack.winter_drop.description": "New features and content for the Winter Drop",
"dataPack.winter_drop.name": "Winter Drop",
"death.attack.mace_smash": "%1$s was smashed by %2$s",
"death.attack.mace_smash.item": "%1$s was smashed by %2$s with %3$s",
"entity.minecraft.creaking": "Creaking",
"entity.minecraft.creaking_transient": "Creaking",
"entity.minecraft.pale_oak_boat": "Pale Oak Boat",
"entity.minecraft.pale_oak_chest_boat": "Pale Oak Boat with Chest",
"gamerule.disablePlayerMovementCheck": "Disable player movement check",
"gamerule.minecartMaxSpeed": "Minecart max speed",
"gamerule.minecartMaxSpeed.description": "Maximum default speed of a moving Minecart on land.",
"gui.abuseReport.name.comment_box_label": "Please describe why you want to report this name:",
"gui.abuseReport.reason.sexually_inappropriate": "Sexually inappropriate",
"gui.abuseReport.reason.sexually_inappropriate.description": "Skins that are graphic in nature relating to sexual acts, sexual organs, and sexual violence.",
"item.minecraft.black_bundle": "Black Bundle",
"item.minecraft.blue_bundle": "Blue Bundle",
"item.minecraft.bordure_indented_banner_pattern": "Bordure Indented Banner Pattern",
"item.minecraft.brown_bundle": "Brown Bundle",
"item.minecraft.bundle.empty.description": "Can hold a mixed stack of items",
"item.minecraft.bundle.full": "Full",
"item.minecraft.creaking_spawn_egg": "Creaking Spawn Egg",
"item.minecraft.creeper_banner_pattern.new": "Creeper Charge Banner Pattern",
"item.minecraft.cyan_bundle": "Cyan Bundle",
"item.minecraft.field_masoned_banner_pattern": "Field Masoned Banner Pattern",
"item.minecraft.flow_banner_pattern.new": "Flow Banner Pattern",
"item.minecraft.flower_banner_pattern.new": "Flower Charge Banner Pattern",
"item.minecraft.globe_banner_pattern.new": "Globe Banner Pattern",
"item.minecraft.gray_bundle": "Gray Bundle",
"item.minecraft.green_bundle": "Green Bundle",
"item.minecraft.guster_banner_pattern.new": "Guster Banner Pattern",
"item.minecraft.light_blue_bundle": "Light Blue Bundle",
"item.minecraft.light_gray_bundle": "Light Gray Bundle",
"item.minecraft.lime_bundle": "Lime Bundle",
"item.minecraft.magenta_bundle": "Magenta Bundle",
"item.minecraft.mojang_banner_pattern.new": "Thing Banner Pattern",
"item.minecraft.orange_bundle": "Orange Bundle",
"item.minecraft.pale_oak_boat": "Pale Oak Boat",
"item.minecraft.pale_oak_chest_boat": "Pale Oak Boat with Chest",
"item.minecraft.piglin_banner_pattern.new": "Snout Banner Pattern",
"item.minecraft.pink_bundle": "Pink Bundle",
"item.minecraft.purple_bundle": "Purple Bundle",
"item.minecraft.red_bundle": "Red Bundle",
"item.minecraft.skull_banner_pattern.new": "Skull Charge Banner Pattern",
"item.minecraft.white_bundle": "White Bundle",
"item.minecraft.yellow_bundle": "Yellow Bundle",
"mco.create.world.failed": "Failed to create world!",
"mco.errorMessage.initialize.failed": "Failed to initialize Realm",
"mco.upload.failed.too_big.description": "The selected world is too big. The maximum allowed size is %s.",
"mco.upload.failed.too_big.title": "World too big",
"optimizeWorld.confirm.proceed": "Create Backup and Optimize",
"options.accessibility.high_contrast_block_outline": "High Contrast Block Outlines",
"options.accessibility.high_contrast_block_outline.tooltip": "Enhances the block outline contrast of targeted block.",
"options.inactivityFpsLimit": "Reduce FPS when",
"options.inactivityFpsLimit.afk": "AFK",
"options.inactivityFpsLimit.afk.tooltip": "Limits framerate to 30 when the game is not getting any player input for more than a minute. Further limits it to 10 after 9 more minutes.",
"options.inactivityFpsLimit.minimized": "Minimized",
"options.inactivityFpsLimit.minimized.tooltip": "Limits framerate only when the game window is minimized.",
"options.rotateWithMinecart": "Rotate with Minecarts",
"options.rotateWithMinecart.tooltip": "Whether the player's view should rotate with a turning Minecart. Only available in worlds with the 'Minecart Improvements' experimental setting turned on.",
"resourcePack.runtime_failure": "Resource pack error detected",
"subtitles.block.creaking_heart.hurt": "Creaking Heart screams",
"subtitles.block.creaking_heart.spawn": "Creaking Heart awakens",
"subtitles.entity.creaking.activate": "Creaking activates",
"subtitles.entity.creaking.ambient": "Creaking creaks",
"subtitles.entity.creaking.angry": "Creaking sees player",
"subtitles.entity.creaking.attack": "Creaking attacks",
"subtitles.entity.creaking.deactivate": "Creaking deactivates",
"subtitles.entity.creaking.death": "Creaking dies",
"subtitles.entity.creaking.freeze": "Creaking stops",
"subtitles.entity.creaking.spawn": "Creaking lives",
"subtitles.entity.creaking.sway": "Creaking is shielded",
"subtitles.entity.creaking.unfreeze": "Creaking moves",
"subtitles.entity.parrot.imitate.creaking": "Parrot creaks",
"subtitles.item.bundle.insert_fail": "Bundle full",
"subtitles.ui.hud.bubble_pop": "Breath meter dropping"
},
"1.21": {
"argument.entity.selector.nearestEntity": "Nearest entity",
"attribute.name.generic.burning_time": "Burning Time",
@@ -4691,4 +4801,4 @@
"entity.MinecartChest.name": "Minecart with Chest",
"attribute.name.generic.armorToughness": "Armor Toughness"
}
}
}
@@ -35,6 +35,7 @@ public class ViaFabricAddon implements ViaBackwardsPlatform, Runnable {
Path configDirPath = FabricLoader.getInstance().getConfigDir().resolve("ViaBackwards");
configDir = configDirPath.toFile();
this.init(new File(getDataFolder(), "config.yml"));
this.enable();
}
@Override
+3 -3
View File
@@ -1,6 +1,6 @@
projectVersion=5.0.4
projectVersion=5.1.0
# Smile emoji
mcVersions=1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
mcVersionRange=1.10-1.21.1
mcVersions=1.21.3,1.21.2,1.21.1,1.21,1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10
mcVersionRange=1.10-1.21.3
velocityVersion=3.3
+1 -1
View File
@@ -3,7 +3,7 @@ metadata.format.version = "1.1"
[versions]
# ViaVersion
viaver = "5.0.4-SNAPSHOT"
viaver = "5.1.0"
# Common provided
netty = "4.0.20.Final"
+1
View File
@@ -4,6 +4,7 @@ rootProject.name = "viabackwards-parent"
dependencyResolutionManagement {
repositories {
mavenLocal()
maven("https://repo.viaversion.com")
maven("https://repo.papermc.io/repository/maven-public/")
mavenCentral()
@@ -52,6 +52,7 @@ public class VelocityPlugin implements ViaBackwardsPlatform {
public void onProxyStart(ProxyInitializeEvent event) {
this.logger = new LoggerWrapper(loggerSlf4j);
Via.getManager().addEnableListener(() -> this.init(new File(getDataFolder(), "config.yml")));
Via.getManager().addPostEnableListener(this::enable);
}
@Override