Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mappingCompression {
compress("item/item_potion_mappings.json")
compress("item/item_trim_material_mappings.json")
compress("item/item_trim_pattern_mappings.json")
compress("item/recipe_serializer_mappings.json")

compress("particle/particle_type_mappings.json")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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;

public enum CookingCategory {

FOOD,
BLOCKS,
MISC,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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;

public enum CraftingCategory {

BUILDING,
REDSTONE,
EQUIPMENT,
MISC,
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,26 @@
package com.github.retrooper.packetevents.protocol.recipe;

import com.github.retrooper.packetevents.protocol.item.ItemStack;
import org.jetbrains.annotations.NotNull;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

// From MCProtocolLib
public class Ingredient {
private final @NotNull ItemStack[] options;

public Ingredient(@NotNull ItemStack... options) {
private final ItemStack[] options;

public Ingredient(ItemStack... options) {
this.options = options;
}

public @NotNull ItemStack[] getOptions() {
return options;
public static Ingredient read(PacketWrapper<?> wrapper) {
ItemStack[] options = wrapper.readArray(PacketWrapper::readItemStack, ItemStack.class);
return new Ingredient(options);
}

public static void write(PacketWrapper<?> wrapper, Ingredient ingredient) {
wrapper.writeArray(ingredient.options, PacketWrapper::writeItemStack);
}

public ItemStack[] getOptions() {
return this.options;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,89 @@

package com.github.retrooper.packetevents.protocol.recipe;

import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.protocol.recipe.data.RecipeData;
import org.jetbrains.annotations.NotNull;
import com.github.retrooper.packetevents.resources.ResourceLocation;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

// From MCProtocolLib
public class Recipe {
private final @NotNull RecipeType type;
private final @NotNull String identifier;
private final RecipeData data;
public class Recipe<T extends RecipeData> {

public Recipe(@NotNull RecipeType type, @NotNull String identifier, RecipeData data) {
this.type = type;
this.identifier = identifier;
private final ResourceLocation key;
private final RecipeSerializer<T> serializer;
private final T data;

@SuppressWarnings("unchecked") // backwards compat
@Deprecated
public Recipe(RecipeType serializer, String key, RecipeData data) {
this(
new ResourceLocation(key),
(RecipeSerializer<T>) serializer.getSerializer(),
(T) data
);
}

public Recipe(ResourceLocation key, RecipeSerializer<T> serializer, T data) {
this.key = key;
this.serializer = serializer;
this.data = data;
}

public @NotNull RecipeType getType() {
return type;
public static Recipe<?> read(PacketWrapper<?> wrapper) {
ResourceLocation key;
RecipeSerializer<?> serializer;
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_20_5)) {
key = wrapper.readIdentifier();
serializer = wrapper.readMappedEntity(RecipeSerializers::getById);
} else {
serializer = RecipeSerializers.getByName(wrapper.readIdentifier().toString());
key = wrapper.readIdentifier();
}
return read(wrapper, key, serializer);
}

private static <T extends RecipeData> Recipe<T> read(
PacketWrapper<?> wrapper,
ResourceLocation key,
RecipeSerializer<T> serializer
) {
T data = serializer.read(wrapper);
return new Recipe<>(key, serializer, data);
}

public static <T extends RecipeData> void write(PacketWrapper<?> wrapper, Recipe<T> recipe) {
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_20_5)) {
wrapper.writeIdentifier(recipe.key);
wrapper.writeMappedEntity(recipe.serializer);
} else {
wrapper.writeIdentifier(recipe.serializer.getName());
wrapper.writeIdentifier(recipe.key);
}
recipe.serializer.write(wrapper, recipe.data);
}

@Deprecated
public RecipeType getType() {
return this.serializer.getLegacyType();
}

public String getIdentifier() {
return this.key.toString();
}

public ResourceLocation getKey() {
return this.key;
}

public @NotNull String getIdentifier() {
return identifier;
public RecipeSerializer<T> getSerializer() {
return this.serializer;
}

public @NotNull RecipeData getData() {
return data;
public T getData() {
return this.data;
}

@Override
public String toString() {
return "Recipe{" +
"type=" + type +
", identifier='" + identifier + '\'' +
", data=" + data +
'}';
return "Recipe{key=" + this.key + ", serializer=" + this.serializer + ", data=" + this.data + '}';
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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.protocol.mapper.MappedEntity;
import com.github.retrooper.packetevents.protocol.recipe.data.RecipeData;
import com.github.retrooper.packetevents.wrapper.PacketWrapper;

public interface RecipeSerializer<T extends RecipeData> extends MappedEntity {

@Deprecated
RecipeType getLegacyType();

T read(PacketWrapper<?> wrapper);

void write(PacketWrapper<?> wrapper, T data);
}
Loading