More work

This commit is contained in:
Nassim Jahnke 2024-08-16 13:51:52 +02:00
parent 5cd34e6fa8
commit 5269a610d1
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
2 changed files with 91 additions and 0 deletions

View File

@ -20,7 +20,10 @@ package com.viaversion.viabackwards.protocol.v1_21_2to1_21.rewriter;
import com.viaversion.viabackwards.api.rewriters.BackwardsStructuredItemRewriter; 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.Protocol1_21_2To1_21;
import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.connection.UserConnection;
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.Item;
import com.viaversion.viaversion.api.minecraft.item.StructuredItem;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.type.Types; 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.chunk.ChunkType1_20_2;
@ -31,7 +34,9 @@ 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_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.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.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.BlockRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
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.downgradeItemData;
import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.updateItemData; import static com.viaversion.viaversion.protocols.v1_21to1_21_2.rewriter.BlockItemPacketRewriter1_21_2.updateItemData;
@ -107,6 +112,92 @@ public final class BlockItemPacketRewriter1_21_2 extends BackwardsStructuredItem
final int slot = wrapper.read(Types.VAR_INT); final int slot = wrapper.read(Types.VAR_INT);
wrapper.write(Types.SHORT, (short) slot); 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
// TODO
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);
});
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()) {
// TODO
return new Item[]{new StructuredItem(1, 1)};
}
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;
}
}.register1_20_5(ClientboundPackets1_21_2.UPDATE_RECIPES);
} }
private void updateContainerId(final PacketWrapper wrapper) { private void updateContainerId(final PacketWrapper wrapper) {