mirror of
https://github.com/ViaVersion/ViaBackwards.git
synced 2024-11-23 12:25:24 +01:00
Very WIP 24w40a
This commit is contained in:
parent
49febd1e63
commit
d3be34adc9
@ -20,13 +20,10 @@ 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.ItemTagStorage;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.minecraft.HolderSet;
|
||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||
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.chunk.ChunkType1_20_2;
|
||||
@ -37,7 +34,6 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPac
|
||||
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.rewriter.RecipeRewriter1_21_2;
|
||||
import com.viaversion.viaversion.rewriter.BlockRewriter;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
|
||||
@ -116,9 +112,7 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem
|
||||
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.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, this::updateContainerId);
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLOSE, this::updateContainerIdServerbound);
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, this::updateContainerIdServerbound);
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.CONTAINER_CLICK, wrapper -> {
|
||||
updateContainerIdServerbound(wrapper);
|
||||
wrapper.passthrough(Types.VAR_INT); // State id
|
||||
@ -183,82 +177,36 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem
|
||||
new SoundRewriter<>(protocol).soundHolderHandler().handle(wrapper);
|
||||
});
|
||||
|
||||
new RecipeRewriter1_21_2<>(protocol) {
|
||||
@Override
|
||||
protected void handleIngredient(final PacketWrapper wrapper) {
|
||||
wrapper.write(mappedItemArrayType(), ingredient(wrapper));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCraftingShaped(final PacketWrapper wrapper) {
|
||||
wrapper.passthrough(Types.STRING); // Group
|
||||
wrapper.passthrough(Types.VAR_INT); // Crafting book category
|
||||
wrapper.passthrough(Types.VAR_INT); // Width
|
||||
wrapper.passthrough(Types.VAR_INT); // Height
|
||||
|
||||
final int ingredients = wrapper.read(Types.VAR_INT);
|
||||
for (int i = 0; i < ingredients; i++) {
|
||||
wrapper.write(mappedItemArrayType(), ingredient(wrapper));
|
||||
}
|
||||
|
||||
wrapper.write(mappedItemType(), rewrite(wrapper.user(), wrapper.read(itemType()))); // Result
|
||||
wrapper.passthrough(Types.BOOLEAN); // Show notification
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleCraftingShapeless(final PacketWrapper wrapper) {
|
||||
wrapper.passthrough(Types.STRING); // Group
|
||||
wrapper.passthrough(Types.VAR_INT); // Crafting book category
|
||||
|
||||
// Move below
|
||||
final Item result = rewrite(wrapper.user(), wrapper.read(itemType()));
|
||||
|
||||
final int ingredients = wrapper.passthrough(Types.VAR_INT);
|
||||
for (int i = 0; i < ingredients; i++) {
|
||||
wrapper.write(mappedItemArrayType(), ingredient(wrapper));
|
||||
}
|
||||
|
||||
wrapper.write(mappedItemType(), result);
|
||||
}
|
||||
|
||||
private Item[] ingredient(final PacketWrapper wrapper) {
|
||||
final HolderSet ingredient = wrapper.read(Types.HOLDER_SET).rewrite(id -> protocol.getMappingData().getNewItemId(id));
|
||||
if (ingredient.hasTagKey()) {
|
||||
final ItemTagStorage tagStorage = wrapper.user().get(ItemTagStorage.class);
|
||||
final int[] tagEntries = tagStorage.itemTag(ingredient.tagKey());
|
||||
if (tagEntries == null || tagEntries.length == 0) {
|
||||
// Most cannot be empty; add a dummy ingredient, though this would only come from bad data
|
||||
return new Item[]{new StructuredItem(1, 1)};
|
||||
}
|
||||
|
||||
final Item[] items = new Item[tagEntries.length];
|
||||
for (int i = 0; i < tagEntries.length; i++) {
|
||||
items[i] = new StructuredItem(tagEntries[i], 1);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
final int[] ids = ingredient.ids();
|
||||
final Item[] items = new Item[ids.length];
|
||||
for (int i = 0; i < ids.length; i++) {
|
||||
items[i] = new StructuredItem(ids[i], 1);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRecipeType(final PacketWrapper wrapper, final String type) {
|
||||
if (type.equals("crafting_transmute")) {
|
||||
wrapper.read(Types.STRING); // Group
|
||||
wrapper.read(Types.VAR_INT); // Crafting book category
|
||||
wrapper.read(Types.HOLDER_SET); // Input
|
||||
wrapper.read(Types.HOLDER_SET); // Material
|
||||
wrapper.read(Types.VAR_INT); // Result item ID
|
||||
} else {
|
||||
super.handleRecipeType(wrapper, type);
|
||||
}
|
||||
}
|
||||
}.register1_20_5(ClientboundPackets1_21_2.UPDATE_RECIPES);
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_ADD, null, wrapper -> {
|
||||
// TODO
|
||||
wrapper.cancel();
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_REMOVE, null, wrapper -> {
|
||||
// TODO
|
||||
wrapper.cancel();
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.RECIPE_BOOK_SETTINGS, null, wrapper -> {
|
||||
// TODO
|
||||
wrapper.cancel();
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.UPDATE_RECIPES, wrapper -> {
|
||||
wrapper.cancel(); // TODO
|
||||
});
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.PLACE_GHOST_RECIPE, wrapper -> {
|
||||
this.updateContainerId(wrapper);
|
||||
final int recipeDisplay = wrapper.read(Types.VAR_INT);
|
||||
wrapper.cancel(); // TODO
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.PLACE_RECIPE, wrapper -> {
|
||||
this.updateContainerIdServerbound(wrapper);
|
||||
final int recipeDisplayId = wrapper.read(Types.VAR_INT);
|
||||
wrapper.cancel(); // TODO
|
||||
});
|
||||
protocol.registerServerbound(ServerboundPackets1_20_5.RECIPE_BOOK_SEEN_RECIPE, wrapper -> {
|
||||
this.updateContainerIdServerbound(wrapper);
|
||||
final int recipeDisplayId = wrapper.read(Types.VAR_INT);
|
||||
wrapper.cancel(); // TODO
|
||||
});
|
||||
}
|
||||
|
||||
private void updateContainerId(final PacketWrapper wrapper) {
|
||||
|
@ -21,7 +21,6 @@ import com.viaversion.nbt.tag.Tag;
|
||||
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.SneakingStorage;
|
||||
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
|
||||
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;
|
||||
@ -36,13 +35,11 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacke
|
||||
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.util.Key;
|
||||
import com.viaversion.viaversion.rewriter.RegistryDataRewriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
|
||||
import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.EntityPacketRewriter1_21_2.updateEnchantmentAttributes;
|
||||
|
||||
public final class EntityPacketRewriter1_21_2 extends EntityRewriter<ClientboundPacket1_21_2, Protocol1_21_2To1_21> {
|
||||
|
||||
public EntityPacketRewriter1_21_2(final Protocol1_21_2To1_21 protocol) {
|
||||
@ -83,15 +80,9 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
|
||||
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
|
||||
final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY);
|
||||
if (registryKey.equals("enchantment")) {
|
||||
updateEnchantmentAttributes(entries, protocol.getMappingData().getAttributeMappings());
|
||||
}
|
||||
|
||||
handleRegistryData1_20_5(wrapper.user(), registryKey, entries);
|
||||
});
|
||||
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
|
||||
@ -135,6 +126,42 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
||||
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
|
||||
|
||||
updateRotation(wrapper);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_ROTATION, ClientboundPackets1_21.PLAYER_POSITION, wrapper -> {
|
||||
// TODO Send PLAYER_LOOK_AT via currently tracked location
|
||||
wrapper.cancel();
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.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
|
||||
|
||||
double movementX = wrapper.read(Types.DOUBLE);
|
||||
double movementY = wrapper.read(Types.DOUBLE);
|
||||
double movementZ = wrapper.read(Types.DOUBLE);
|
||||
|
||||
// Pack y and x rot
|
||||
updateRotation(wrapper);
|
||||
|
||||
final int relativeArguments = wrapper.read(Types.VAR_INT);
|
||||
// TODO Similar to player position
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_21_2.PLAYER_POSITION, wrapper -> {
|
||||
final int teleportId = wrapper.read(Types.VAR_INT);
|
||||
|
||||
@ -302,6 +329,14 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
||||
});
|
||||
}
|
||||
|
||||
private void updateRotation(PacketWrapper wrapper) {
|
||||
// Pack y and x rot
|
||||
final float yaw = wrapper.read(Types.FLOAT);
|
||||
final float pitch = wrapper.read(Types.FLOAT);
|
||||
wrapper.write(Types.BYTE, (byte) Math.floor(yaw * 256F / 360F));
|
||||
wrapper.write(Types.BYTE, (byte) Math.floor(pitch * 256F / 360F));
|
||||
}
|
||||
|
||||
private int boatTypeFromEntityType(final EntityType type) {
|
||||
if (type == EntityTypes1_21_2.OAK_BOAT) {
|
||||
return 0;
|
||||
@ -369,6 +404,15 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
||||
);
|
||||
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.DOLPHIN).removeIndex(16); // Baby
|
||||
@ -384,5 +428,8 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user