3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-10-02 00:10:06 +02:00
TODO: Yoink recipe rewriter from ViaBackwards
Dieser Commit ist enthalten in:
KennyTV 2020-07-01 17:20:59 +02:00
Ursprung f16ff65933
Commit 3ddd289b49
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
22 geänderte Dateien mit 20656 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -0,0 +1,239 @@
package us.myles.ViaVersion.api.entities;
import us.myles.ViaVersion.api.Via;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
public class Entity1_16_2Types {
public static EntityType getTypeFromId(int typeID) {
Optional<EntityType> type = EntityType.findById(typeID);
if (!type.isPresent()) {
Via.getPlatform().getLogger().severe("Could not find 1.16.2 type id " + typeID);
return EntityType.ENTITY; // Fall back to the basic ENTITY
}
return type.get();
}
public enum EntityType implements us.myles.ViaVersion.api.entities.EntityType {
ENTITY(-1),
AREA_EFFECT_CLOUD(0, ENTITY),
END_CRYSTAL(18, ENTITY),
EVOKER_FANGS(23, ENTITY),
EXPERIENCE_ORB(24, ENTITY),
EYE_OF_ENDER(25, ENTITY),
FALLING_BLOCK(26, ENTITY),
FIREWORK_ROCKET(27, ENTITY),
ITEM(37, ENTITY),
LLAMA_SPIT(43, ENTITY),
TNT(64, ENTITY),
SHULKER_BULLET(71, ENTITY),
FISHING_BOBBER(107, ENTITY),
LIVINGENTITY(-1, ENTITY),
ARMOR_STAND(1, LIVINGENTITY),
PLAYER(106, LIVINGENTITY),
ABSTRACT_INSENTIENT(-1, LIVINGENTITY),
ENDER_DRAGON(19, ABSTRACT_INSENTIENT),
BEE(4, ABSTRACT_INSENTIENT),
ABSTRACT_CREATURE(-1, ABSTRACT_INSENTIENT),
ABSTRACT_AGEABLE(-1, ABSTRACT_CREATURE),
VILLAGER(93, ABSTRACT_AGEABLE),
WANDERING_TRADER(95, ABSTRACT_AGEABLE),
// Animals
ABSTRACT_ANIMAL(-1, ABSTRACT_AGEABLE),
DOLPHIN(13, ABSTRACT_INSENTIENT),
CHICKEN(9, ABSTRACT_ANIMAL),
COW(11, ABSTRACT_ANIMAL),
MOOSHROOM(53, COW),
PANDA(56, ABSTRACT_INSENTIENT),
PIG(59, ABSTRACT_ANIMAL),
POLAR_BEAR(63, ABSTRACT_ANIMAL),
RABBIT(66, ABSTRACT_ANIMAL),
SHEEP(69, ABSTRACT_ANIMAL),
TURTLE(91, ABSTRACT_ANIMAL),
FOX(28, ABSTRACT_ANIMAL),
ABSTRACT_TAMEABLE_ANIMAL(-1, ABSTRACT_ANIMAL),
CAT(7, ABSTRACT_TAMEABLE_ANIMAL),
OCELOT(54, ABSTRACT_TAMEABLE_ANIMAL),
WOLF(100, ABSTRACT_TAMEABLE_ANIMAL),
ABSTRACT_PARROT(-1, ABSTRACT_TAMEABLE_ANIMAL),
PARROT(57, ABSTRACT_PARROT),
// Horses
ABSTRACT_HORSE(-1, ABSTRACT_ANIMAL),
CHESTED_HORSE(-1, ABSTRACT_HORSE),
DONKEY(14, CHESTED_HORSE),
MULE(52, CHESTED_HORSE),
LLAMA(42, CHESTED_HORSE),
TRADER_LLAMA(89, CHESTED_HORSE),
HORSE(33, ABSTRACT_HORSE),
SKELETON_HORSE(74, ABSTRACT_HORSE),
ZOMBIE_HORSE(103, ABSTRACT_HORSE),
// Golem
ABSTRACT_GOLEM(-1, ABSTRACT_CREATURE),
SNOW_GOLEM(77, ABSTRACT_GOLEM),
IRON_GOLEM(36, ABSTRACT_GOLEM),
SHULKER(70, ABSTRACT_GOLEM),
// Fish
ABSTRACT_FISHES(-1, ABSTRACT_CREATURE),
COD(10, ABSTRACT_FISHES),
PUFFERFISH(65, ABSTRACT_FISHES),
SALMON(68, ABSTRACT_FISHES),
TROPICAL_FISH(90, ABSTRACT_FISHES),
// Monsters
ABSTRACT_MONSTER(-1, ABSTRACT_CREATURE),
BLAZE(5, ABSTRACT_MONSTER),
CREEPER(12, ABSTRACT_MONSTER),
ENDERMITE(21, ABSTRACT_MONSTER),
ENDERMAN(20, ABSTRACT_MONSTER),
GIANT(30, ABSTRACT_MONSTER),
SILVERFISH(72, ABSTRACT_MONSTER),
VEX(92, ABSTRACT_MONSTER),
WITCH(96, ABSTRACT_MONSTER),
WITHER(97, ABSTRACT_MONSTER),
RAVAGER(67, ABSTRACT_MONSTER),
PIGLIN(60, ABSTRACT_MONSTER),
HOGLIN(32, ABSTRACT_ANIMAL),
STRIDER(83, ABSTRACT_ANIMAL),
ZOGLIN(101, ABSTRACT_MONSTER),
// Illagers
ABSTRACT_ILLAGER_BASE(-1, ABSTRACT_MONSTER),
ABSTRACT_EVO_ILLU_ILLAGER(-1, ABSTRACT_ILLAGER_BASE),
EVOKER(22, ABSTRACT_EVO_ILLU_ILLAGER),
ILLUSIONER(35, ABSTRACT_EVO_ILLU_ILLAGER),
VINDICATOR(94, ABSTRACT_ILLAGER_BASE),
PILLAGER(62, ABSTRACT_ILLAGER_BASE),
// Skeletons
ABSTRACT_SKELETON(-1, ABSTRACT_MONSTER),
SKELETON(73, ABSTRACT_SKELETON),
STRAY(82, ABSTRACT_SKELETON),
WITHER_SKELETON(98, ABSTRACT_SKELETON),
// Guardians
GUARDIAN(31, ABSTRACT_MONSTER),
ELDER_GUARDIAN(17, GUARDIAN),
// Spiders
SPIDER(80, ABSTRACT_MONSTER),
CAVE_SPIDER(8, SPIDER),
// Zombies
ZOMBIE(102, ABSTRACT_MONSTER),
DROWNED(16, ZOMBIE),
HUSK(34, ZOMBIE),
ZOMBIFIED_PIGLIN(105, ZOMBIE),
ZOMBIE_VILLAGER(104, ZOMBIE),
// Flying entities
ABSTRACT_FLYING(-1, ABSTRACT_INSENTIENT),
GHAST(29, ABSTRACT_FLYING),
PHANTOM(58, ABSTRACT_FLYING),
ABSTRACT_AMBIENT(-1, ABSTRACT_INSENTIENT),
BAT(3, ABSTRACT_AMBIENT),
ABSTRACT_WATERMOB(-1, ABSTRACT_INSENTIENT),
SQUID(81, ABSTRACT_WATERMOB),
// Slimes
SLIME(75, ABSTRACT_INSENTIENT),
MAGMA_CUBE(44, SLIME),
// Hangable objects
ABSTRACT_HANGING(-1, ENTITY),
LEASH_KNOT(40, ABSTRACT_HANGING),
ITEM_FRAME(38, ABSTRACT_HANGING),
PAINTING(55, ABSTRACT_HANGING),
ABSTRACT_LIGHTNING(-1, ENTITY),
LIGHTNING_BOLT(41, ABSTRACT_LIGHTNING),
// Arrows
ABSTRACT_ARROW(-1, ENTITY),
ARROW(2, ABSTRACT_ARROW),
SPECTRAL_ARROW(79, ABSTRACT_ARROW),
TRIDENT(88, ABSTRACT_ARROW),
// Fireballs
ABSTRACT_FIREBALL(-1, ENTITY),
DRAGON_FIREBALL(15, ABSTRACT_FIREBALL),
FIREBALL(39, ABSTRACT_FIREBALL),
SMALL_FIREBALL(76, ABSTRACT_FIREBALL),
WITHER_SKULL(99, ABSTRACT_FIREBALL),
// Projectiles
PROJECTILE_ABSTRACT(-1, ENTITY),
SNOWBALL(78, PROJECTILE_ABSTRACT),
ENDER_PEARL(85, PROJECTILE_ABSTRACT),
EGG(84, PROJECTILE_ABSTRACT),
POTION(87, PROJECTILE_ABSTRACT),
EXPERIENCE_BOTTLE(86, PROJECTILE_ABSTRACT),
// Vehicles
MINECART_ABSTRACT(-1, ENTITY),
CHESTED_MINECART_ABSTRACT(-1, MINECART_ABSTRACT),
CHEST_MINECART(46, CHESTED_MINECART_ABSTRACT),
HOPPER_MINECART(49, CHESTED_MINECART_ABSTRACT),
MINECART(45, MINECART_ABSTRACT),
FURNACE_MINECART(48, MINECART_ABSTRACT),
COMMAND_BLOCK_MINECART(47, MINECART_ABSTRACT),
TNT_MINECART(51, MINECART_ABSTRACT),
SPAWNER_MINECART(50, MINECART_ABSTRACT),
BOAT(6, ENTITY);
private static final Map<Integer, EntityType> TYPES = new HashMap<>();
private final int id;
private final EntityType parent;
EntityType(int id) {
this.id = id;
this.parent = null;
}
EntityType(int id, EntityType parent) {
this.id = id;
this.parent = parent;
}
@Override
public int getId() {
return id;
}
@Override
public EntityType getParent() {
return parent;
}
static {
for (EntityType type : EntityType.values()) {
TYPES.put(type.id, type);
}
}
public static Optional<EntityType> findById(int id) {
if (id == -1)
return Optional.empty();
return Optional.ofNullable(TYPES.get(id));
}
}
}

Datei anzeigen

@ -29,6 +29,7 @@ import us.myles.ViaVersion.protocols.protocol1_15_1to1_15.Protocol1_15_1To1_15;
import us.myles.ViaVersion.protocols.protocol1_15_2to1_15_1.Protocol1_15_2To1_15_1;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import us.myles.ViaVersion.protocols.protocol1_16_1to1_16.Protocol1_16_1To1_16;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.Protocol1_9_1_2To1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_1to1_9.Protocol1_9_1To1_9;
@ -108,6 +109,7 @@ public class ProtocolRegistry {
registerProtocol(new Protocol1_16To1_15_2(), ProtocolVersion.v1_16, ProtocolVersion.v1_15_2);
registerProtocol(new Protocol1_16_1To1_16(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16);
registerProtocol(new Protocol1_16_2To1_16_1(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_1);
}
public static void init() {

Datei anzeigen

@ -41,6 +41,7 @@ public class ProtocolVersion {
public static final ProtocolVersion v1_15_2;
public static final ProtocolVersion v1_16;
public static final ProtocolVersion v1_16_1;
public static final ProtocolVersion v1_16_2;
public static final ProtocolVersion unknown;
private final int id;
@ -83,6 +84,7 @@ public class ProtocolVersion {
register(v1_15_2 = new ProtocolVersion(578, "1.15.2"));
register(v1_16 = new ProtocolVersion(735, "1.16"));
register(v1_16_1 = new ProtocolVersion(736, "1.16.1"));
register(v1_16_2 = new ProtocolVersion(738, "1.16.2"));
register(unknown = new ProtocolVersion(-1, "UNKNOWN"));
}

Datei anzeigen

@ -0,0 +1,156 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.SoundRewriter;
import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.rewriters.TagType;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets.WorldPackets;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.storage.EntityTracker1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_16_2To1_16_1 extends Protocol<ClientboundPackets1_16, ClientboundPackets1_16, ServerboundPackets1_16, ServerboundPackets1_16_2> {
private TagRewriter tagRewriter;
public Protocol1_16_2To1_16_1() {
super(ClientboundPackets1_16.class, ClientboundPackets1_16.class, ServerboundPackets1_16.class, ServerboundPackets1_16_2.class, true);
}
@Override
protected void registerPackets() {
MetadataRewriter1_16_2To1_16_1 metadataRewriter = new MetadataRewriter1_16_2To1_16_1(this);
EntityPackets.register(this);
WorldPackets.register(this);
InventoryPackets.register(this);
tagRewriter = new TagRewriter(this, Protocol1_16_2To1_16_1::getNewBlockId, InventoryPackets::getNewItemId, metadataRewriter::getNewEntityId);
tagRewriter.register(ClientboundPackets1_16.TAGS);
SoundRewriter soundRewriter = new SoundRewriter(this, id -> MappingData.soundMappings.getNewId(id));
soundRewriter.registerSound(ClientboundPackets1_16.SOUND);
soundRewriter.registerSound(ClientboundPackets1_16.ENTITY_SOUND);
registerOutgoing(ClientboundPackets1_16.ADVANCEMENTS, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT); // Mapping size
for (int i = 0; i < size; i++) {
wrapper.passthrough(Type.STRING); // Identifier
// Parent
if (wrapper.passthrough(Type.BOOLEAN))
wrapper.passthrough(Type.STRING);
// Display data
if (wrapper.passthrough(Type.BOOLEAN)) {
wrapper.passthrough(Type.COMPONENT); // Title
wrapper.passthrough(Type.COMPONENT); // Description
InventoryPackets.toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Icon
wrapper.passthrough(Type.VAR_INT); // Frame type
int flags = wrapper.passthrough(Type.INT); // Flags
if ((flags & 1) != 0)
wrapper.passthrough(Type.STRING); // Background texture
wrapper.passthrough(Type.FLOAT); // X
wrapper.passthrough(Type.FLOAT); // Y
}
wrapper.passthrough(Type.STRING_ARRAY); // Criteria
int arrayLength = wrapper.passthrough(Type.VAR_INT);
for (int array = 0; array < arrayLength; array++) {
wrapper.passthrough(Type.STRING_ARRAY); // String array
}
}
});
}
});
// Recipe book data has been split into 2 separate packets
registerIncoming(ServerboundPackets1_16_2.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int recipeType = wrapper.read(Type.VAR_INT);
boolean open = wrapper.read(Type.BOOLEAN);
boolean filter = wrapper.read(Type.BOOLEAN);
wrapper.write(Type.VAR_INT, 1); // Settings
wrapper.write(Type.BOOLEAN, open);
wrapper.write(Type.BOOLEAN, filter);
wrapper.write(Type.BOOLEAN, recipeType == 1); // Furnace
wrapper.write(Type.BOOLEAN, filter);
wrapper.write(Type.BOOLEAN, recipeType == 2); // Blast Furnace
wrapper.write(Type.BOOLEAN, filter);
wrapper.write(Type.BOOLEAN, recipeType == 3); // Smoker
wrapper.write(Type.BOOLEAN, filter);
});
}
});
registerIncoming(ServerboundPackets1_16_2.SEEN_RECIPE, ServerboundPackets1_16.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
String recipe = wrapper.read(Type.STRING);
wrapper.write(Type.VAR_INT, 0); // Shown
wrapper.write(Type.STRING, recipe);
});
}
});
}
@Override
protected void loadMappingData() {
MappingData.init();
tagRewriter.addEmptyTag(TagType.BLOCK, "minecraft:mushroom_grow_block");
// The client now wants ALL (previous) tags to be sent, sooooo :>
tagRewriter.addEmptyTags(TagType.ITEM, "minecraft:soul_fire_base_blocks", "minecraft:furnace_materials", "minecraft:crimson_stems",
"minecraft:gold_ores", "minecraft:piglin_loved", "minecraft:piglin_repellents", "minecraft:creeper_drop_music_discs",
"minecraft:logs_that_burn", "minecraft:stone_tool_materials", "minecraft:warped_stems");
tagRewriter.addEmptyTags(TagType.BLOCK, "minecraft:infiniburn_nether", "minecraft:crimson_stems",
"minecraft:wither_summon_base_blocks", "minecraft:infiniburn_overworld", "minecraft:piglin_repellents",
"minecraft:hoglin_repellents", "minecraft:prevent_mob_spawning_inside", "minecraft:wart_blocks",
"minecraft:stone_pressure_plates", "minecraft:nylium", "minecraft:gold_ores", "minecraft:pressure_plates",
"minecraft:logs_that_burn", "minecraft:strider_warm_blocks", "minecraft:warped_stems", "minecraft:infiniburn_end");
}
public static int getNewBlockStateId(int id) {
int newId = MappingData.blockStateMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16.2 blockstate for 1.16 blockstate " + id);
return 0;
}
return newId;
}
public static int getNewBlockId(int id) {
int newId = MappingData.blockMappings.getNewId(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16.2 block for 1.16 block " + id);
return 0;
}
return newId;
}
@Override
public void init(UserConnection userConnection) {
userConnection.put(new EntityTracker1_16_2(userConnection));
if (!userConnection.has(ClientWorld.class)) {
userConnection.put(new ClientWorld(userConnection));
}
}
}

Datei anzeigen

@ -0,0 +1,55 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1;
import us.myles.ViaVersion.api.protocol.ServerboundPacketType;
public enum ServerboundPackets1_16_2 implements ServerboundPacketType {
TELEPORT_CONFIRM, // 0x00
QUERY_BLOCK_NBT, // 0x01
SET_DIFFICULTY, // 0x02
CHAT_MESSAGE, // 0x03
CLIENT_STATUS, // 0x04
CLIENT_SETTINGS, // 0x05
TAB_COMPLETE, // 0x06
WINDOW_CONFIRMATION, // 0x07
CLICK_WINDOW_BUTTON, // 0x08
CLICK_WINDOW, // 0x09
CLOSE_WINDOW, // 0x0A
PLUGIN_MESSAGE, // 0x0B
EDIT_BOOK, // 0x0C
ENTITY_NBT_REQUEST, // 0x0D
INTERACT_ENTITY, // 0x0E
GENERATE_JIGSAW, // 0x0F
KEEP_ALIVE, // 0x10
LOCK_DIFFICULTY, // 0x11
PLAYER_POSITION, // 0x12
PLAYER_POSITION_AND_ROTATION, // 0x13
PLAYER_ROTATION, // 0x14
PLAYER_MOVEMENT, // 0x15
VEHICLE_MOVE, // 0x16
STEER_BOAT, // 0x17
PICK_ITEM, // 0x18
CRAFT_RECIPE_REQUEST, // 0x19
PLAYER_ABILITIES, // 0x1A
PLAYER_DIGGING, // 0x1B
ENTITY_ACTION, // 0x1C
STEER_VEHICLE, // 0x1D
RECIPE_BOOK_DATA, // 0x1E
SEEN_RECIPE, // 0x1F
RENAME_ITEM, // 0x20
RESOURCE_PACK_STATUS, // 0x21
ADVANCEMENT_TAB, // 0x22
SELECT_TRADE, // 0x23
SET_BEACON_EFFECT, // 0x24
HELD_ITEM_CHANGE, // 0x25
UPDATE_COMMAND_BLOCK, // 0x26
UPDATE_COMMAND_BLOCK_MINECART, // 0x27
CREATIVE_INVENTORY_ACTION, // 0x28
UPDATE_JIGSAW_BLOCK, // 0x29
UPDATE_STRUCTURE_BLOCK, // 0x2A
UPDATE_SIGN, // 0x2B
ANIMATION, // 0x2C
SPECTATE, // 0x2D
PLAYER_BLOCK_PLACEMENT, // 0x2E
USE_ITEM, // 0x2F
}

Datei anzeigen

@ -0,0 +1,26 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data;
import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.MappingDataLoader;
import us.myles.ViaVersion.api.data.Mappings;
import us.myles.ViaVersion.util.Int2IntBiMap;
public class MappingData {
public static Int2IntBiMap oldToNewItems = new Int2IntBiMap();
public static Mappings blockMappings;
public static Mappings blockStateMappings;
public static Mappings soundMappings;
public static void init() {
Via.getPlatform().getLogger().info("Loading 1.16.1 -> 1.16.2 mappings...");
JsonObject mapping1_16 = MappingDataLoader.loadData("mapping-1.16.json", true);
JsonObject mapping1_16_2 = MappingDataLoader.loadData("mapping-1.16.2.json", true);
oldToNewItems.defaultReturnValue(-1);
blockStateMappings = new Mappings(mapping1_16.getAsJsonObject("blockstates"), mapping1_16_2.getAsJsonObject("blockstates"));
blockMappings = new Mappings(mapping1_16.getAsJsonObject("blocks"), mapping1_16_2.getAsJsonObject("blocks"));
MappingDataLoader.mapIdentifiers(oldToNewItems, mapping1_16.getAsJsonObject("items"), mapping1_16_2.getAsJsonObject("items"));
soundMappings = new Mappings(mapping1_16.getAsJsonArray("sounds"), mapping1_16_2.getAsJsonArray("sounds"));
}
}

Datei anzeigen

@ -0,0 +1,38 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.metadata;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_16Types;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types;
import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.storage.EntityTracker1_16_2;
import java.util.List;
public class MetadataRewriter1_16_2To1_16_1 extends MetadataRewriter {
public MetadataRewriter1_16_2To1_16_1(Protocol1_16_2To1_16_1 protocol) {
super(protocol, EntityTracker1_16_2.class);
mapTypes(Entity1_16Types.EntityType.values(), Entity1_16_2Types.EntityType.class);
}
@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
if (metadata.getMetaType() == MetaType1_14.Slot) {
InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
int data = (int) metadata.getValue();
metadata.setValue(Protocol1_16_2To1_16_1.getNewBlockStateId(data));
}
}
@Override
protected EntityType getTypeFromId(int type) {
return Entity1_16_2Types.getTypeFromId(type);
}
}

Datei anzeigen

@ -0,0 +1,48 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.metadata.MetadataRewriter1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.Protocol1_16To1_15_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.storage.EntityTracker1_16;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class EntityPackets {
public static void register(Protocol1_16_2To1_16_1 protocol) {
MetadataRewriter1_16_2To1_16_1 metadataRewriter = protocol.get(MetadataRewriter1_16_2To1_16_1.class);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_16.SPAWN_ENTITY, Entity1_16_2Types.EntityType.FALLING_BLOCK, Protocol1_16To1_15_2::getNewBlockStateId);
metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_16.SPAWN_PLAYER, Entity1_16_2Types.EntityType.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16.ENTITY_METADATA, Types1_14.METADATA_LIST);
metadataRewriter.registerEntityDestroy(ClientboundPackets1_16.DESTROY_ENTITIES);
protocol.registerOutgoing(ClientboundPackets1_16.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // Entity ID
handler(wrapper -> wrapper.write(Type.BOOLEAN, false)); // Hardcore //TODO save?
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE); // Previous Gamemode
map(Type.STRING_ARRAY); // World List
map(Type.NBT); // Dimension Registry
map(Type.STRING); // Dimension Type
map(Type.STRING); // Dimension
map(Type.LONG); // Seed
map(Type.UNSIGNED_BYTE, Type.VAR_INT); // Max players
// ...
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
String dimension = wrapper.get(Type.STRING, 0);
clientChunks.setEnvironment(dimension);
wrapper.user().get(EntityTracker1_16.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16_2Types.EntityType.PLAYER);
});
}
});
}
}

Datei anzeigen

@ -0,0 +1,177 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
public class InventoryPackets {
public static void register(Protocol1_16_2To1_16_1 protocol) {
ItemRewriter itemRewriter = new ItemRewriter(protocol, InventoryPackets::toClient, InventoryPackets::toServer);
itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, InventoryPackets::getNewItemId);
itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
protocol.registerOutgoing(ClientboundPackets1_16.UNLOCK_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.BOOLEAN); // Open
wrapper.passthrough(Type.BOOLEAN); // Filter
wrapper.passthrough(Type.BOOLEAN); // Furnace
wrapper.passthrough(Type.BOOLEAN); // Filter furnace
// Blast furnace / smoker
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.BOOLEAN, false);
});
}
});
protocol.registerOutgoing(ClientboundPackets1_16.TRADE_LIST, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
int size = wrapper.passthrough(Type.UNSIGNED_BYTE);
for (int i = 0; i < size; i++) {
Item input = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
toClient(input);
Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
toClient(output);
if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Second Item
}
wrapper.passthrough(Type.BOOLEAN); // Trade disabled
wrapper.passthrough(Type.INT); // Number of tools uses
wrapper.passthrough(Type.INT); // Maximum number of trade uses
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.FLOAT);
wrapper.passthrough(Type.INT);
}
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.BOOLEAN);
});
}
});
itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerEntityEquipmentArray(ClientboundPackets1_16.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
protocol.registerOutgoing(ClientboundPackets1_16.DECLARE_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT);
for (int i = 0; i < size; i++) {
String type = wrapper.passthrough(Type.STRING).replace("minecraft:", "");
String id = wrapper.passthrough(Type.STRING);
switch (type) {
case "crafting_shapeless": {
wrapper.passthrough(Type.STRING); // Group
int ingredientsNo = wrapper.passthrough(Type.VAR_INT);
for (int j = 0; j < ingredientsNo; j++) {
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) toClient(item);
}
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
break;
}
case "crafting_shaped": {
int ingredientsNo = wrapper.passthrough(Type.VAR_INT) * wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Group
for (int j = 0; j < ingredientsNo; j++) {
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) toClient(item);
}
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
break;
}
case "blasting":
case "smoking":
case "campfire_cooking":
case "smelting": {
wrapper.passthrough(Type.STRING); // Group
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) toClient(item);
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time
break;
}
case "stonecutting": {
wrapper.passthrough(Type.STRING);
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) toClient(item);
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
break;
}
case "smithing": {
wrapper.passthrough(Type.STRING);
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
for (Item item : items) toClient(item);
items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
for (Item item : items) toClient(item);
toClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM));
break;
}
}
}
});
}
});
itemRewriter.registerClickWindow(ServerboundPackets1_16_2.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerCreativeInvAction(ServerboundPackets1_16_2.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);
protocol.registerIncoming(ServerboundPackets1_16_2.EDIT_BOOK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> InventoryPackets.toServer(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)));
}
});
}
public static void toClient(Item item) {
if (item == null) return;
item.setIdentifier(getNewItemId(item.getIdentifier()));
}
public static void toServer(Item item) {
if (item == null) return;
item.setIdentifier(getOldItemId(item.getIdentifier()));
}
public static int getNewItemId(int id) {
int newId = MappingData.oldToNewItems.get(id);
if (newId == -1) {
Via.getPlatform().getLogger().warning("Missing 1.16.2 item for 1.16 item " + id);
return 1;
}
return newId;
}
public static int getOldItemId(int id) {
int oldId = MappingData.oldToNewItems.inverse().get(id);
return oldId != -1 ? oldId : 1;
}
}

Datei anzeigen

@ -0,0 +1,46 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.protocol.Protocol;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.BlockRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class WorldPackets {
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16_2To1_16_1::getNewBlockStateId, Protocol1_16_2To1_16_1::getNewBlockId);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_16.MULTI_BLOCK_CHANGE);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
protocol.registerOutgoing(ClientboundPackets1_16.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_16Type(clientWorld));
for (int s = 0; s < 16; s++) {
ChunkSection section = chunk.getSections()[s];
if (section == null) continue;
for (int i = 0; i < section.getPaletteSize(); i++) {
int old = section.getPaletteEntry(i);
section.setPaletteEntry(i, Protocol1_16_2To1_16_1.getNewBlockStateId(old));
}
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001, InventoryPackets::getNewItemId);
blockRewriter.registerSpawnParticle(ClientboundPackets1_16.SPAWN_PARTICLE, 3, 23, 34,
null, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE);
}
}

Datei anzeigen

@ -0,0 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.storage;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types.EntityType;
import us.myles.ViaVersion.api.storage.EntityTracker;
public class EntityTracker1_16_2 extends EntityTracker {
public EntityTracker1_16_2(UserConnection user) {
super(user, EntityType.PLAYER);
}
}

Datei-Diff unterdrückt, da er zu groß ist Diff laden

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>viaversion-jar</name>

Datei anzeigen

@ -6,7 +6,7 @@
<groupId>us.myles</groupId>
<artifactId>viaversion-parent</artifactId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
<packaging>pom</packaging>
<name>viaversion-parent</name>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Datei anzeigen

@ -5,7 +5,7 @@
<parent>
<artifactId>viaversion-parent</artifactId>
<groupId>us.myles</groupId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2-20w27a</version>
</parent>
<modelVersion>4.0.0</modelVersion>