3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-10-07 10:40:05 +02:00

Move RecipeRewriter to VV, cleanup advancements+trade list

Dieser Commit ist enthalten in:
KennyTV 2020-07-02 00:26:44 +02:00
Ursprung f3c30130d2
Commit 7638d678bb
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
12 geänderte Dateien mit 45 neuen und 502 gelöschten Zeilen

Datei anzeigen

@ -1,33 +0,0 @@
package nl.matsv.viabackwards.api.rewriters;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
public abstract class RecipeRewriter {
protected final ItemRewriterBase rewriter;
protected RecipeRewriter(ItemRewriterBase rewriter) {
this.rewriter = rewriter;
}
public abstract void handle(PacketWrapper wrapper, String type) throws Exception;
public void registerDefaultHandler(ClientboundPacketType packetType) {
rewriter.getProtocol().registerOutgoing(packetType, 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); // Recipe Identifier
handle(wrapper, type);
}
});
}
});
}
}

Datei anzeigen

@ -56,47 +56,6 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
cancelOutgoing(ClientboundPackets1_14.UPDATE_VIEW_DISTANCE);
cancelOutgoing(ClientboundPackets1_14.ACKNOWLEDGE_PLAYER_DIGGING);
registerOutgoing(ClientboundPackets1_14.ADVANCEMENTS, new PacketRemapper() { // c
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
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
blockItemPackets.handleItemToClient(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
}
}
}
});
}
});
registerOutgoing(ClientboundPackets1_14.TAGS, new PacketRemapper() {
@Override
public void registerMap() {

Datei anzeigen

@ -1,65 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data;
import nl.matsv.viabackwards.api.rewriters.ItemRewriterBase;
import nl.matsv.viabackwards.api.rewriters.RecipeRewriter;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type;
public class RecipeRewriter1_14 extends RecipeRewriter {
public RecipeRewriter1_14(ItemRewriterBase rewriter) {
super(rewriter);
}
public void handle(PacketWrapper wrapper, String type) throws Exception {
switch (type) {
case "crafting_shapeless":
handleCraftingShapeless(wrapper);
break;
case "crafting_shaped":
handleCraftingShaped(wrapper);
break;
case "smelting":
handleSmelting(wrapper);
break;
}
}
public void handleSmelting(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.STRING); // Group
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) {
rewriter.handleItemToClient(item);
}
rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
wrapper.passthrough(Type.FLOAT); // EXP
wrapper.passthrough(Type.VAR_INT); // Cooking time
}
public void handleCraftingShaped(PacketWrapper wrapper) throws Exception {
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) {
rewriter.handleItemToClient(item);
}
}
rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
}
public void handleCraftingShapeless(PacketWrapper wrapper) throws Exception {
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) {
rewriter.handleItemToClient(item);
}
}
rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
}
}

Datei anzeigen

@ -4,11 +4,9 @@ import com.google.common.collect.ImmutableSet;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.entities.storage.EntityTracker;
import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter;
import nl.matsv.viabackwards.api.rewriters.RecipeRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2To1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.RecipeRewriter1_14;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
@ -24,6 +22,7 @@ import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.BlockRewriter;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
import us.myles.ViaVersion.api.rewriters.RecipeRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_13;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter;
@ -32,6 +31,7 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ServerboundPackets1_13
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.types.Chunk1_13Type;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ClientboundPackets1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.data.RecipeRewriter1_14;
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.gson.JsonElement;
@ -181,6 +181,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
itemRewriter.registerSetCooldown(ClientboundPackets1_14.COOLDOWN, BlockItemPackets1_14::getOldItemId);
itemRewriter.registerWindowItems(ClientboundPackets1_14.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_14.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerAdvancements(ClientboundPackets1_14.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
// Trade List -> Plugin Message
protocol.registerOutgoing(ClientboundPackets1_14.TRADE_LIST, ClientboundPackets1_13.PLUGIN_MESSAGE, new PacketRemapper() {
@ -282,12 +283,12 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
}
});
RecipeRewriter recipeHandler = new RecipeRewriter1_14(protocol, this::handleItemToClient);
protocol.registerOutgoing(ClientboundPackets1_14.DECLARE_RECIPES, new PacketRemapper() { // c
@Override
public void registerMap() {
handler(new PacketHandler() {
private final Set<String> removedTypes = ImmutableSet.of("crafting_special_suspiciousstew", "blasting", "smoking", "campfire_cooking", "stonecutting");
private final RecipeRewriter recipeHandler = new RecipeRewriter1_14(BlockItemPackets1_14.this);
@Override
public void handle(PacketWrapper wrapper) throws Exception {

Datei anzeigen

@ -12,7 +12,6 @@ import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets.BlockItemPack
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.packets.EntityPackets1_15;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.type.Type;
@ -80,45 +79,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
}
});
registerOutgoing(ClientboundPackets1_15.ADVANCEMENTS, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.BOOLEAN); // Reset/clear
int size = wrapper.passthrough(Type.VAR_INT);
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
blockItemPackets.handleItemToClient(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
}
}
}
});
}
});
new TagRewriter(this, id -> BackwardsMappings.blockMappings.getNewId(id),
id -> MappingData.oldToNewItems.inverse().get(id), EntityTypeMapping::getOldEntityId).register(ClientboundPackets1_15.TAGS);
}

Datei anzeigen

@ -1,45 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data;
import nl.matsv.viabackwards.api.rewriters.ItemRewriterBase;
import nl.matsv.viabackwards.protocol.protocol1_13_2to1_14.data.RecipeRewriter1_14;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.type.Type;
public class RecipeRewriter1_15 extends RecipeRewriter1_14 {
public RecipeRewriter1_15(ItemRewriterBase rewriter) {
super(rewriter);
}
@Override
public void handle(PacketWrapper wrapper, String type) throws Exception {
switch (type) {
case "crafting_shapeless":
handleCraftingShapeless(wrapper);
break;
case "crafting_shaped":
handleCraftingShaped(wrapper);
break;
case "blasting": // new
case "smoking": // new
case "campfire_cooking": // new
case "smelting":
handleSmelting(wrapper);
break;
case "stonecutting": // new
handleStonecutting(wrapper);
break;
}
}
public void handleStonecutting(PacketWrapper wrapper) throws Exception {
wrapper.passthrough(Type.STRING);
Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
for (Item item : items) {
rewriter.handleItemToClient(item);
}
rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
}
}

Datei anzeigen

@ -5,7 +5,6 @@ import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.Protocol1_14_4To1_15;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.ParticleMapping;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
@ -19,6 +18,7 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.RecipeRewriter1_15;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
@ -33,7 +33,7 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_14_4To1_15::getNewBlockStateId, Protocol1_14_4To1_15::getNewBlockId);
new RecipeRewriter1_15(this).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
new RecipeRewriter1_15(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_15.DECLARE_RECIPES);
protocol.registerIncoming(ServerboundPackets1_14.EDIT_BOOK, new PacketRemapper() {
@Override
@ -45,47 +45,9 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
itemRewriter.registerSetCooldown(ClientboundPackets1_15.COOLDOWN, BlockItemPackets1_15::getOldItemId);
itemRewriter.registerWindowItems(ClientboundPackets1_15.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_15.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
protocol.registerOutgoing(ClientboundPackets1_15.TRADE_LIST, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
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);
handleItemToClient(input);
Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
handleItemToClient(output);
if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item
// Second Item
Item second = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
handleItemToClient(second);
}
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
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.registerTradeList(ClientboundPackets1_15.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerEntityEquipment(ClientboundPackets1_15.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerAdvancements(ClientboundPackets1_15.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerClickWindow(ServerboundPackets1_14.CLICK_WINDOW, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerCreativeInvAction(ServerboundPackets1_14.CREATIVE_INVENTORY_ACTION, Type.FLAT_VAR_INT_ITEM);

Datei anzeigen

@ -95,42 +95,6 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
}
});
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);
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
blockItemPackets.handleItemToClient(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
}
}
});
}
});
registerOutgoing(ClientboundPackets1_16.STATISTICS, new PacketRemapper() {
@Override
public void registerMap() {

Datei anzeigen

@ -1,84 +0,0 @@
package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data;
import nl.matsv.viabackwards.api.rewriters.ItemRewriterBase;
import nl.matsv.viabackwards.protocol.protocol1_14_4to1_15.data.RecipeRewriter1_15;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type;
public class RecipeRewriter1_16 extends RecipeRewriter1_15 {
public RecipeRewriter1_16(ItemRewriterBase rewriter) {
super(rewriter);
}
public void register(ClientboundPacketType packetType) {
// Remove new smithing type, only in this handler
rewriter.getProtocol().registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT);
int newSize = size;
for (int i = 0; i < size; i++) {
String originalType = wrapper.read(Type.STRING);
String type = originalType.replace("minecraft:", "");
if (type.equals("smithing")) {
newSize--;
wrapper.read(Type.STRING);
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
wrapper.read(Type.FLAT_VAR_INT_ITEM);
continue;
}
wrapper.write(Type.STRING, originalType);
String id = wrapper.passthrough(Type.STRING); // Recipe Identifier
handle(wrapper, type);
}
wrapper.set(Type.VAR_INT, 0, newSize);
});
}
});
}
@Override
public void handle(PacketWrapper wrapper, String type) throws Exception {
switch (type) {
case "crafting_shapeless":
handleCraftingShapeless(wrapper);
break;
case "crafting_shaped":
handleCraftingShaped(wrapper);
break;
case "blasting":
case "smoking":
case "campfire_cooking":
case "smelting":
handleSmelting(wrapper);
break;
case "stonecutting":
handleStonecutting(wrapper);
break;
case "smithing": // new
handleSmithing(wrapper);
break;
}
}
public void handleSmithing(PacketWrapper wrapper) throws Exception {
Item[] baseIngredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
for (Item item : baseIngredients) {
rewriter.handleItemToClient(item);
}
Item[] ingredients = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
for (Item item : ingredients) {
rewriter.handleItemToClient(item);
}
rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result
}
}

Datei anzeigen

@ -6,7 +6,6 @@ import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.MapColorRewriter;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.RecipeRewriter1_16;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -22,6 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_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;
import us.myles.ViaVersion.util.CompactArrayUtil;
@ -49,47 +49,42 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_15_2To1_16::getNewBlockStateId, Protocol1_15_2To1_16::getNewBlockId);
new RecipeRewriter1_16(this).register(ClientboundPackets1_16.DECLARE_RECIPES);
RecipeRewriter1_16 recipeRewriter = new RecipeRewriter1_16(protocol, this::handleItemToClient);
// Remove new smithing type, only in this handler
protocol.registerOutgoing(ClientboundPackets1_16.DECLARE_RECIPES, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
int size = wrapper.passthrough(Type.VAR_INT);
int newSize = size;
for (int i = 0; i < size; i++) {
String originalType = wrapper.read(Type.STRING);
String type = originalType.replace("minecraft:", "");
if (type.equals("smithing")) {
newSize--;
wrapper.read(Type.STRING);
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
wrapper.read(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT);
wrapper.read(Type.FLAT_VAR_INT_ITEM);
continue;
}
wrapper.write(Type.STRING, originalType);
String id = wrapper.passthrough(Type.STRING); // Recipe Identifier
recipeRewriter.handle(wrapper, type);
}
wrapper.set(Type.VAR_INT, 0, newSize);
});
}
});
itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, BlockItemPackets1_16::getOldItemId);
itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
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);
handleItemToClient(input);
Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
handleItemToClient(output);
if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item
// Second Item
Item second = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
handleItemToClient(second);
}
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
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.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);

Datei anzeigen

@ -55,42 +55,6 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
soundRewriter.registerNamedSound(ClientboundPackets1_16.NAMED_SOUND);
soundRewriter.registerStopSound(ClientboundPackets1_16.STOP_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);
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
blockItemPackets.handleItemToClient(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.RECIPE_BOOK_DATA, new PacketRemapper() {
@Override

Datei anzeigen

@ -3,12 +3,10 @@ package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets;
import nl.matsv.viabackwards.ViaBackwards;
import nl.matsv.viabackwards.api.rewriters.EnchantmentRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.RecipeRewriter1_16;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.data.BackwardsMappings;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.rewriters.BlockRewriter;
import us.myles.ViaVersion.api.rewriters.ItemRewriter;
@ -16,6 +14,7 @@ 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_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_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;
@ -33,12 +32,14 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
ItemRewriter itemRewriter = new ItemRewriter(protocol, this::handleItemToClient, this::handleItemToServer);
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16_1To1_16_2::getNewBlockStateId, Protocol1_16_1To1_16_2::getNewBlockId);
new RecipeRewriter1_16(this).register(ClientboundPackets1_16.DECLARE_RECIPES);
new RecipeRewriter1_16(protocol, this::handleItemToClient).registerDefaultHandler(ClientboundPackets1_16.DECLARE_RECIPES);
itemRewriter.registerSetCooldown(ClientboundPackets1_16.COOLDOWN, BlockItemPackets1_16_2::getOldItemId);
itemRewriter.registerWindowItems(ClientboundPackets1_16.WINDOW_ITEMS, Type.FLAT_VAR_INT_ITEM_ARRAY);
itemRewriter.registerSetSlot(ClientboundPackets1_16.SET_SLOT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerEntityEquipmentArray(ClientboundPackets1_16.ENTITY_EQUIPMENT, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerTradeList(ClientboundPackets1_16.TRADE_LIST, Type.FLAT_VAR_INT_ITEM);
itemRewriter.registerAdvancements(ClientboundPackets1_16.ADVANCEMENTS, Type.FLAT_VAR_INT_ITEM);
protocol.registerOutgoing(ClientboundPackets1_16.UNLOCK_RECIPES, new PacketRemapper() {
@Override
@ -58,42 +59,6 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
}
});
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);
handleItemToClient(input);
Item output = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
handleItemToClient(output);
if (wrapper.passthrough(Type.BOOLEAN)) { // Has second item
// Second Item
Item second = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM);
handleItemToClient(second);
}
wrapper.passthrough(Type.BOOLEAN);
wrapper.passthrough(Type.INT);
wrapper.passthrough(Type.INT);
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);
});
}
});
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);