From 8bde89d4eecfa5aa7dfe742c974d8f5a43bc8e82 Mon Sep 17 00:00:00 2001 From: booky10 Date: Fri, 18 Oct 2024 03:19:21 +0200 Subject: [PATCH] Implement WrapperPlayServerRecipeBookRemove --- .../protocol/recipe/RecipeDisplayEntry.java | 12 ++-- .../protocol/recipe/RecipeDisplayId.java | 43 +++++++++++++ .../WrapperPlayServerRecipeBookRemove.java | 63 +++++++++++++++++++ 3 files changed, 112 insertions(+), 6 deletions(-) create mode 100644 api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayId.java create mode 100644 api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerRecipeBookRemove.java diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayEntry.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayEntry.java index fd44c238c..798c41c64 100644 --- a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayEntry.java +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayEntry.java @@ -32,14 +32,14 @@ public final class RecipeDisplayEntry { - private int id; + private RecipeDisplayId id; private RecipeDisplay display; private @Nullable Integer group; private RecipeBookCategory category; private @Nullable List> ingredients; public RecipeDisplayEntry( - int id, + RecipeDisplayId id, RecipeDisplay display, @Nullable Integer group, RecipeBookCategory category, @@ -53,7 +53,7 @@ public RecipeDisplayEntry( } public static RecipeDisplayEntry read(PacketWrapper wrapper) { - int id = wrapper.readVarInt(); + RecipeDisplayId id = RecipeDisplayId.read(wrapper); RecipeDisplay display = RecipeDisplay.read(wrapper); Integer group = wrapper.readNullableVarInt(); RecipeBookCategory category = wrapper.readMappedEntity(RecipeBookCategories.getRegistry()); @@ -63,7 +63,7 @@ public static RecipeDisplayEntry read(PacketWrapper wrapper) { } public static void write(PacketWrapper wrapper, RecipeDisplayEntry entry) { - wrapper.writeVarInt(entry.id); + RecipeDisplayId.write(wrapper, entry.id); RecipeDisplay.write(wrapper, entry.display); wrapper.writeNullableVarInt(entry.group); wrapper.writeMappedEntity(entry.category); @@ -71,11 +71,11 @@ public static void write(PacketWrapper wrapper, RecipeDisplayEntry entry) { ew.writeList(list, MappedEntitySet::write)); } - public int getId() { + public RecipeDisplayId getId() { return this.id; } - public void setId(int id) { + public void setId(RecipeDisplayId id) { this.id = id; } diff --git a/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayId.java b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayId.java new file mode 100644 index 000000000..7c69ffb30 --- /dev/null +++ b/api/src/main/java/com/github/retrooper/packetevents/protocol/recipe/RecipeDisplayId.java @@ -0,0 +1,43 @@ +/* + * This file is part of packetevents - https://github.com/retrooper/packetevents + * Copyright (C) 2024 retrooper 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 . + */ + +package com.github.retrooper.packetevents.protocol.recipe; + +import com.github.retrooper.packetevents.wrapper.PacketWrapper; + +public final class RecipeDisplayId { + + private final int id; + + public RecipeDisplayId(int id) { + this.id = id; + } + + public static RecipeDisplayId read(PacketWrapper wrapper) { + int id = wrapper.readVarInt(); + return new RecipeDisplayId(id); + } + + public static void write(PacketWrapper wrapper, RecipeDisplayId id) { + wrapper.writeVarInt(id.id); + } + + public int getId() { + return this.id; + } +} diff --git a/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerRecipeBookRemove.java b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerRecipeBookRemove.java new file mode 100644 index 000000000..e7e571fe0 --- /dev/null +++ b/api/src/main/java/com/github/retrooper/packetevents/wrapper/play/server/WrapperPlayServerRecipeBookRemove.java @@ -0,0 +1,63 @@ +/* + * This file is part of packetevents - https://github.com/retrooper/packetevents + * Copyright (C) 2024 retrooper 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 . + */ + +package com.github.retrooper.packetevents.wrapper.play.server; + +import com.github.retrooper.packetevents.event.PacketSendEvent; +import com.github.retrooper.packetevents.protocol.packettype.PacketType; +import com.github.retrooper.packetevents.protocol.recipe.RecipeDisplayId; +import com.github.retrooper.packetevents.wrapper.PacketWrapper; + +import java.util.List; + +public class WrapperPlayServerRecipeBookRemove extends PacketWrapper { + + private List recipeIds; + + public WrapperPlayServerRecipeBookRemove(PacketSendEvent event) { + super(event); + } + + public WrapperPlayServerRecipeBookRemove(List recipeIds) { + super(PacketType.Play.Server.RECIPE_BOOK_REMOVE); + this.recipeIds = recipeIds; + } + + @Override + public void read() { + this.recipeIds = this.readList(RecipeDisplayId::read); + } + + @Override + public void write() { + this.writeList(this.recipeIds, RecipeDisplayId::write); + } + + @Override + public void copy(WrapperPlayServerRecipeBookRemove wrapper) { + this.recipeIds = wrapper.recipeIds; + } + + public List getRecipeIds() { + return this.recipeIds; + } + + public void setRecipeIds(List recipeIds) { + this.recipeIds = recipeIds; + } +}