Skip to content

Commit

Permalink
Implement WrapperPlayServerRecipeBookRemove
Browse files Browse the repository at this point in the history
  • Loading branch information
booky10 committed Oct 18, 2024
1 parent a5ebc35 commit 8bde89d
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<MappedEntitySet<ItemType>> ingredients;

public RecipeDisplayEntry(
int id,
RecipeDisplayId id,
RecipeDisplay<?> display,
@Nullable Integer group,
RecipeBookCategory category,
Expand All @@ -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());
Expand All @@ -63,19 +63,19 @@ 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);
wrapper.writeOptional(entry.ingredients, (ew, list) ->
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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<WrapperPlayServerRecipeBookRemove> {

private List<RecipeDisplayId> recipeIds;

public WrapperPlayServerRecipeBookRemove(PacketSendEvent event) {
super(event);
}

public WrapperPlayServerRecipeBookRemove(List<RecipeDisplayId> 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<RecipeDisplayId> getRecipeIds() {
return this.recipeIds;
}

public void setRecipeIds(List<RecipeDisplayId> recipeIds) {
this.recipeIds = recipeIds;
}
}

0 comments on commit 8bde89d

Please sign in to comment.