mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Update Recipe code, add abstraction for different recipe packet types.
This commit is contained in:
parent
29c6d92bdc
commit
64ee739e1f
@ -5,17 +5,18 @@ import net.minestom.server.network.packet.server.ServerPacket;
|
||||
import net.minestom.server.network.packet.server.ServerPacketIdentifier;
|
||||
import net.minestom.server.utils.binary.BinaryWriter;
|
||||
import net.minestom.server.utils.validate.Check;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class DeclareRecipesPacket implements ServerPacket {
|
||||
|
||||
public Recipe[] recipes;
|
||||
public DeclaredRecipe[] recipes;
|
||||
|
||||
@Override
|
||||
public void write(BinaryWriter writer) {
|
||||
Check.notNull(recipes, "Recipes cannot be null!");
|
||||
|
||||
writer.writeVarInt(recipes.length);
|
||||
for (Recipe recipe : recipes) {
|
||||
for (DeclaredRecipe recipe : recipes) {
|
||||
recipe.write(writer);
|
||||
}
|
||||
}
|
||||
@ -25,91 +26,287 @@ public class DeclareRecipesPacket implements ServerPacket {
|
||||
return ServerPacketIdentifier.DECLARE_RECIPES;
|
||||
}
|
||||
|
||||
public static class Recipe {
|
||||
public abstract static class DeclaredRecipe {
|
||||
protected final String recipeId;
|
||||
protected final String recipeType;
|
||||
|
||||
public String recipeId;
|
||||
public String recipeType;
|
||||
protected DeclaredRecipe(@NotNull String recipeId, @NotNull String recipeType) {
|
||||
this.recipeId = recipeId;
|
||||
this.recipeType = recipeType;
|
||||
}
|
||||
|
||||
public String group;
|
||||
|
||||
// crafting_shapeless
|
||||
// ++ group
|
||||
// ++ ingredients
|
||||
// ++ result
|
||||
|
||||
// crafting_shaped
|
||||
public int width;
|
||||
public int height;
|
||||
// ++ group
|
||||
// ++ ingredients
|
||||
// ++ result
|
||||
|
||||
// smelting, blasting, smoking and campfire
|
||||
// ++ group
|
||||
// ++ ingredient
|
||||
// ++ result
|
||||
public float experience;
|
||||
public int cookingTime;
|
||||
|
||||
// smithing
|
||||
// ++ ingredient (base)
|
||||
public Ingredient additionIngredient;
|
||||
// ++ result
|
||||
|
||||
|
||||
public Ingredient ingredient;
|
||||
public Ingredient[] ingredients;
|
||||
public ItemStack result;
|
||||
|
||||
|
||||
private void write(BinaryWriter writer) {
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
writer.writeSizedString(recipeType);
|
||||
writer.writeSizedString(recipeId);
|
||||
}
|
||||
}
|
||||
|
||||
switch (recipeType) {
|
||||
case "crafting_shapeless": {
|
||||
writer.writeSizedString(group);
|
||||
writer.writeVarInt(ingredients.length);
|
||||
for (Ingredient ingredient : ingredients) {
|
||||
ingredient.write(writer);
|
||||
}
|
||||
writer.writeItemStack(result);
|
||||
break;
|
||||
}
|
||||
case "crafting_shaped": {
|
||||
writer.writeVarInt(width);
|
||||
writer.writeVarInt(height);
|
||||
writer.writeSizedString(group);
|
||||
for (Ingredient ingredient : ingredients) {
|
||||
ingredient.write(writer);
|
||||
}
|
||||
writer.writeItemStack(result);
|
||||
break;
|
||||
}
|
||||
case "smelting":
|
||||
case "blasting":
|
||||
case "smoking":
|
||||
case "campfire_cooking": {
|
||||
writer.writeSizedString(group);
|
||||
ingredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
writer.writeFloat(experience);
|
||||
writer.writeVarInt(cookingTime);
|
||||
break;
|
||||
}
|
||||
case "stonecutting": {
|
||||
writer.writeSizedString(group);
|
||||
ingredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
break;
|
||||
}
|
||||
case "smithing": {
|
||||
ingredient.write(writer);
|
||||
additionIngredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
break;
|
||||
}
|
||||
public final static class DeclaredShapelessCraftingRecipe extends DeclaredRecipe {
|
||||
private final String group;
|
||||
private final Ingredient[] ingredients;
|
||||
private final ItemStack result;
|
||||
|
||||
public DeclaredShapelessCraftingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull Ingredient[] ingredients,
|
||||
@NotNull ItemStack result
|
||||
) {
|
||||
super(recipeId, "crafting_shapeless");
|
||||
this.group = group;
|
||||
this.ingredients = ingredients;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
writer.writeSizedString(group);
|
||||
writer.writeVarInt(ingredients.length);
|
||||
for (Ingredient ingredient : ingredients) {
|
||||
ingredient.write(writer);
|
||||
}
|
||||
writer.writeItemStack(result);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class DeclaredShapedCraftingRecipe extends DeclaredRecipe {
|
||||
public final int width;
|
||||
public final int height;
|
||||
private final String group;
|
||||
private final Ingredient[] ingredients;
|
||||
private final ItemStack result;
|
||||
|
||||
public DeclaredShapedCraftingRecipe(
|
||||
@NotNull String recipeId,
|
||||
int width,
|
||||
int height,
|
||||
@NotNull String group,
|
||||
@NotNull Ingredient[] ingredients,
|
||||
@NotNull ItemStack result
|
||||
) {
|
||||
super(recipeId, "crafting_shaped");
|
||||
this.group = group;
|
||||
this.ingredients = ingredients;
|
||||
this.result = result;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
writer.writeVarInt(width);
|
||||
writer.writeVarInt(height);
|
||||
writer.writeSizedString(group);
|
||||
for (Ingredient ingredient : ingredients) {
|
||||
ingredient.write(writer);
|
||||
}
|
||||
writer.writeItemStack(result);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class DeclaredSmeltingRecipe extends DeclaredRecipe {
|
||||
private final String group;
|
||||
private final Ingredient ingredient;
|
||||
private final ItemStack result;
|
||||
private final float experience;
|
||||
private final int cookingTime;
|
||||
|
||||
public DeclaredSmeltingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull Ingredient ingredient,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(recipeId, "smelting");
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
writer.writeSizedString(group);
|
||||
ingredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
writer.writeFloat(experience);
|
||||
writer.writeVarInt(cookingTime);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class DeclaredBlastingRecipe extends DeclaredRecipe {
|
||||
private final String group;
|
||||
private final Ingredient ingredient;
|
||||
private final ItemStack result;
|
||||
private final float experience;
|
||||
private final int cookingTime;
|
||||
|
||||
public DeclaredBlastingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull Ingredient ingredient,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(recipeId, "blasting");
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
writer.writeSizedString(group);
|
||||
ingredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
writer.writeFloat(experience);
|
||||
writer.writeVarInt(cookingTime);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class DeclaredSmokingRecipe extends DeclaredRecipe {
|
||||
private final String group;
|
||||
private final Ingredient ingredient;
|
||||
private final ItemStack result;
|
||||
private final float experience;
|
||||
private final int cookingTime;
|
||||
|
||||
public DeclaredSmokingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull Ingredient ingredient,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(recipeId, "smoking");
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
writer.writeSizedString(group);
|
||||
ingredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
writer.writeFloat(experience);
|
||||
writer.writeVarInt(cookingTime);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class DeclaredCampfireCookingRecipe extends DeclaredRecipe {
|
||||
private final String group;
|
||||
private final Ingredient ingredient;
|
||||
private final ItemStack result;
|
||||
private final float experience;
|
||||
private final int cookingTime;
|
||||
|
||||
public DeclaredCampfireCookingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull Ingredient ingredient,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(recipeId, "campfire_cooking");
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
writer.writeSizedString(group);
|
||||
ingredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
writer.writeFloat(experience);
|
||||
writer.writeVarInt(cookingTime);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class DeclaredStonecutterRecipe extends DeclaredRecipe {
|
||||
private final String group;
|
||||
private final Ingredient ingredient;
|
||||
private final ItemStack result;
|
||||
|
||||
public DeclaredStonecutterRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull Ingredient ingredient,
|
||||
@NotNull ItemStack result
|
||||
) {
|
||||
super(recipeId, "stonecutter");
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
writer.writeSizedString(group);
|
||||
ingredient.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
}
|
||||
}
|
||||
|
||||
public final static class DeclaredSmithingRecipe extends DeclaredRecipe {
|
||||
private final Ingredient base;
|
||||
private final Ingredient addition;
|
||||
private final ItemStack result;
|
||||
|
||||
public DeclaredSmithingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull Ingredient base,
|
||||
@NotNull Ingredient addition,
|
||||
@NotNull ItemStack result
|
||||
) {
|
||||
super(recipeId, "smithing");
|
||||
this.base = base;
|
||||
this.addition = addition;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
// Write type & id
|
||||
super.write(writer);
|
||||
// Write recipe specific stuff.
|
||||
base.write(writer);
|
||||
addition.write(writer);
|
||||
writer.writeItemStack(result);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,35 +2,53 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BlastingRecipe extends Recipe {
|
||||
|
||||
private String group;
|
||||
private DeclareRecipesPacket.Ingredient ingredient;
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
private ItemStack result;
|
||||
private float experience;
|
||||
|
||||
private int cookingTime;
|
||||
|
||||
public BlastingRecipe(String recipeId, String group) {
|
||||
super(RecipeType.SMELTING, recipeId);
|
||||
setGroup(group);
|
||||
protected BlastingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(RecipeType.BLASTING, recipeId);
|
||||
this.group = group;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(@NotNull String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket.Ingredient getIngredient() {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
public void setIngredient(DeclareRecipesPacket.Ingredient ingredient) {
|
||||
public void setIngredient(@NotNull DeclareRecipesPacket.Ingredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
@ -2,35 +2,53 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class CampfireCookingRecipe extends Recipe {
|
||||
|
||||
private String group;
|
||||
private DeclareRecipesPacket.Ingredient ingredient;
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
private ItemStack result;
|
||||
private float experience;
|
||||
|
||||
private int cookingTime;
|
||||
|
||||
public CampfireCookingRecipe(String recipeId, String group) {
|
||||
super(RecipeType.SMELTING, recipeId);
|
||||
setGroup(group);
|
||||
protected CampfireCookingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(RecipeType.CAMPFIRE_COOKING, recipeId);
|
||||
this.group = group;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(@NotNull String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket.Ingredient getIngredient() {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
public void setIngredient(DeclareRecipesPacket.Ingredient ingredient) {
|
||||
public void setIngredient(@NotNull DeclareRecipesPacket.Ingredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
@ -1,32 +1,25 @@
|
||||
package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class Recipe {
|
||||
protected final RecipeType recipeType;
|
||||
protected final String recipeId;
|
||||
|
||||
protected RecipeType recipeType;
|
||||
protected String recipeId;
|
||||
protected String group;
|
||||
|
||||
protected Recipe(RecipeType recipeType, String recipeId) {
|
||||
protected Recipe(@NotNull RecipeType recipeType, @NotNull String recipeId) {
|
||||
this.recipeType = recipeType;
|
||||
this.recipeId = recipeId;
|
||||
}
|
||||
|
||||
public abstract boolean shouldShow(Player player);
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
public abstract boolean shouldShow(@NotNull Player player);
|
||||
|
||||
@NotNull
|
||||
public RecipeType getRecipeType() {
|
||||
return recipeType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getRecipeId() {
|
||||
return recipeId;
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -8,12 +9,10 @@ import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
public class RecipeManager {
|
||||
private final DeclareRecipesPacket declareRecipesPacket = new DeclareRecipesPacket();
|
||||
private final Set<Recipe> recipes = new CopyOnWriteArraySet<>();
|
||||
|
||||
private Set<Recipe> recipes = new CopyOnWriteArraySet<>();
|
||||
|
||||
private DeclareRecipesPacket declareRecipesPacket = new DeclareRecipesPacket();
|
||||
|
||||
public void addRecipe(Recipe recipe) {
|
||||
public void addRecipe(@NotNull Recipe recipe) {
|
||||
if (this.recipes.add(recipe)) {
|
||||
// TODO add to all players
|
||||
|
||||
@ -21,7 +20,7 @@ public class RecipeManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeRecipe(Recipe recipe) {
|
||||
public void removeRecipe(@NotNull Recipe recipe) {
|
||||
if (this.recipes.remove(recipe)) {
|
||||
// TODO remove to all players
|
||||
|
||||
@ -29,118 +28,130 @@ public class RecipeManager {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Set<Recipe> getRecipes() {
|
||||
return recipes;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket getDeclareRecipesPacket() {
|
||||
return declareRecipesPacket;
|
||||
}
|
||||
|
||||
private void refreshRecipesPacket() {
|
||||
List<DeclareRecipesPacket.Recipe> recipesCache = new ArrayList<>();
|
||||
List<DeclareRecipesPacket.DeclaredRecipe> recipesCache = new ArrayList<>();
|
||||
for (Recipe recipe : recipes) {
|
||||
DeclareRecipesPacket.Recipe packetRecipe = new DeclareRecipesPacket.Recipe();
|
||||
|
||||
switch (recipe.recipeType) {
|
||||
case SHAPELESS: {
|
||||
packetRecipe.recipeType = "crafting_shapeless";
|
||||
packetRecipe.group = recipe.getGroup();
|
||||
|
||||
ShapelessRecipe shapelessRecipe = (ShapelessRecipe) recipe;
|
||||
|
||||
List<DeclareRecipesPacket.Ingredient> ingredients = shapelessRecipe.getIngredients();
|
||||
packetRecipe.ingredients = ingredients.toArray(new DeclareRecipesPacket.Ingredient[0]);
|
||||
packetRecipe.result = shapelessRecipe.getResult();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredShapelessCraftingRecipe(
|
||||
shapelessRecipe.getRecipeId(),
|
||||
shapelessRecipe.getGroup(),
|
||||
shapelessRecipe.getIngredients().toArray(new DeclareRecipesPacket.Ingredient[0]),
|
||||
shapelessRecipe.getResult()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case SHAPED: {
|
||||
packetRecipe.recipeType = "crafting_shaped";
|
||||
packetRecipe.group = recipe.getGroup();
|
||||
|
||||
ShapedRecipe shapedRecipe = (ShapedRecipe) recipe;
|
||||
|
||||
List<DeclareRecipesPacket.Ingredient> ingredients2 = shapedRecipe.getIngredients();
|
||||
packetRecipe.ingredients = ingredients2.toArray(new DeclareRecipesPacket.Ingredient[0]);
|
||||
packetRecipe.result = shapedRecipe.getResult();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredShapedCraftingRecipe(
|
||||
shapedRecipe.getRecipeId(),
|
||||
shapedRecipe.getWidth(),
|
||||
shapedRecipe.getHeight(),
|
||||
shapedRecipe.getGroup(),
|
||||
shapedRecipe.getIngredients().toArray(new DeclareRecipesPacket.Ingredient[0]),
|
||||
shapedRecipe.getResult()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case SMELTING: {
|
||||
packetRecipe.recipeType = "smelting";
|
||||
packetRecipe.group = recipe.getGroup();
|
||||
|
||||
SmeltingRecipe smeltingRecipe = (SmeltingRecipe) recipe;
|
||||
|
||||
packetRecipe.ingredient = smeltingRecipe.getIngredient();
|
||||
packetRecipe.result = smeltingRecipe.getResult();
|
||||
packetRecipe.experience = smeltingRecipe.getExperience();
|
||||
packetRecipe.cookingTime = smeltingRecipe.getCookingTime();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredSmeltingRecipe(
|
||||
smeltingRecipe.getRecipeId(),
|
||||
smeltingRecipe.getGroup(),
|
||||
smeltingRecipe.getIngredient(),
|
||||
smeltingRecipe.getResult(),
|
||||
smeltingRecipe.getExperience(),
|
||||
smeltingRecipe.getCookingTime()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case BLASTING: {
|
||||
packetRecipe.recipeType = "blasting";
|
||||
packetRecipe.group = recipe.getGroup();
|
||||
|
||||
BlastingRecipe blastingRecipe = (BlastingRecipe) recipe;
|
||||
|
||||
packetRecipe.ingredient = blastingRecipe.getIngredient();
|
||||
packetRecipe.result = blastingRecipe.getResult();
|
||||
packetRecipe.experience = blastingRecipe.getExperience();
|
||||
packetRecipe.cookingTime = blastingRecipe.getCookingTime();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredBlastingRecipe(
|
||||
blastingRecipe.getRecipeId(),
|
||||
blastingRecipe.getGroup(),
|
||||
blastingRecipe.getIngredient(),
|
||||
blastingRecipe.getResult(),
|
||||
blastingRecipe.getExperience(),
|
||||
blastingRecipe.getCookingTime()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case SMOKING: {
|
||||
packetRecipe.recipeType = "smoking";
|
||||
packetRecipe.group = recipe.getGroup();
|
||||
|
||||
SmokingRecipe smokingRecipe = (SmokingRecipe) recipe;
|
||||
|
||||
packetRecipe.ingredient = smokingRecipe.getIngredient();
|
||||
packetRecipe.result = smokingRecipe.getResult();
|
||||
packetRecipe.experience = smokingRecipe.getExperience();
|
||||
packetRecipe.cookingTime = smokingRecipe.getCookingTime();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredSmokingRecipe(
|
||||
smokingRecipe.getRecipeId(),
|
||||
smokingRecipe.getGroup(),
|
||||
smokingRecipe.getIngredient(),
|
||||
smokingRecipe.getResult(),
|
||||
smokingRecipe.getExperience(),
|
||||
smokingRecipe.getCookingTime()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case CAMPFIRE_COOKING: {
|
||||
packetRecipe.recipeType = "campfire_cooking";
|
||||
packetRecipe.group = recipe.getGroup();
|
||||
|
||||
CampfireCookingRecipe campfireCookingRecipe = (CampfireCookingRecipe) recipe;
|
||||
|
||||
packetRecipe.ingredient = campfireCookingRecipe.getIngredient();
|
||||
packetRecipe.result = campfireCookingRecipe.getResult();
|
||||
packetRecipe.experience = campfireCookingRecipe.getExperience();
|
||||
packetRecipe.cookingTime = campfireCookingRecipe.getCookingTime();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredCampfireCookingRecipe(
|
||||
campfireCookingRecipe.getRecipeId(),
|
||||
campfireCookingRecipe.getGroup(),
|
||||
campfireCookingRecipe.getIngredient(),
|
||||
campfireCookingRecipe.getResult(),
|
||||
campfireCookingRecipe.getExperience(),
|
||||
campfireCookingRecipe.getCookingTime()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case STONECUTTING: {
|
||||
packetRecipe.recipeType = "stonecutting";
|
||||
packetRecipe.group = recipe.getGroup();
|
||||
|
||||
StonecutterRecipe stonecuttingRecipe = (StonecutterRecipe) recipe;
|
||||
|
||||
packetRecipe.ingredient = stonecuttingRecipe.getIngredient();
|
||||
packetRecipe.result = stonecuttingRecipe.getResult();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredStonecutterRecipe(
|
||||
stonecuttingRecipe.getRecipeId(),
|
||||
stonecuttingRecipe.getGroup(),
|
||||
stonecuttingRecipe.getIngredient(),
|
||||
stonecuttingRecipe.getResult()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
case SMITHING: {
|
||||
packetRecipe.recipeType = "smithing";
|
||||
|
||||
SmithingRecipe smithingRecipe = (SmithingRecipe) recipe;
|
||||
|
||||
packetRecipe.ingredient = smithingRecipe.getBaseIngredient();
|
||||
packetRecipe.additionIngredient = smithingRecipe.getAdditionIngredient();
|
||||
packetRecipe.result = smithingRecipe.getResult();
|
||||
recipesCache.add(
|
||||
new DeclareRecipesPacket.DeclaredSmithingRecipe(
|
||||
smithingRecipe.getRecipeId(),
|
||||
smithingRecipe.getBaseIngredient(),
|
||||
smithingRecipe.getAdditionIngredient(),
|
||||
smithingRecipe.getResult()
|
||||
)
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
packetRecipe.recipeId = recipe.recipeId;
|
||||
|
||||
recipesCache.add(packetRecipe);
|
||||
}
|
||||
|
||||
declareRecipesPacket.recipes = recipesCache.toArray(new DeclareRecipesPacket.Recipe[0]);
|
||||
declareRecipesPacket.recipes = recipesCache.toArray(new DeclareRecipesPacket.DeclaredRecipe[0]);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,41 +2,70 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class ShapedRecipe extends Recipe {
|
||||
private final int width;
|
||||
private final int height;
|
||||
private String group;
|
||||
private final List<DeclareRecipesPacket.Ingredient> ingredients;
|
||||
private ItemStack result;
|
||||
|
||||
private int width, height;
|
||||
|
||||
private List<DeclareRecipesPacket.Ingredient> ingredients = new ArrayList<>();
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
public ShapedRecipe(String recipeId, String group, int width, int height) {
|
||||
protected ShapedRecipe(@NotNull String recipeId,
|
||||
int width,
|
||||
int height,
|
||||
@NotNull String group,
|
||||
@Nullable List<DeclareRecipesPacket.Ingredient> ingredients,
|
||||
@NotNull ItemStack result) {
|
||||
super(RecipeType.SHAPED, recipeId);
|
||||
setGroup(group);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.group = group;
|
||||
this.ingredients = Objects.requireNonNullElseGet(ingredients, LinkedList::new);
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(@NotNull String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public void addIngredient(DeclareRecipesPacket.Ingredient ingredient) {
|
||||
if (ingredients.size() + 1 > width * height)
|
||||
if (ingredients.size() + 1 > width * height) {
|
||||
throw new IndexOutOfBoundsException("You cannot add more ingredients than width*height");
|
||||
}
|
||||
|
||||
ingredients.add(ingredient);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<DeclareRecipesPacket.Ingredient> getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
@ -2,34 +2,54 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class ShapelessRecipe extends Recipe {
|
||||
private String group;
|
||||
private final List<DeclareRecipesPacket.Ingredient> ingredients;
|
||||
private ItemStack result;
|
||||
|
||||
private List<DeclareRecipesPacket.Ingredient> ingredients = new ArrayList<>();
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
public ShapelessRecipe(String recipeId, String group) {
|
||||
protected ShapelessRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@Nullable List<DeclareRecipesPacket.Ingredient> ingredients,
|
||||
@NotNull ItemStack result
|
||||
) {
|
||||
super(RecipeType.SHAPELESS, recipeId);
|
||||
setGroup(group);
|
||||
this.group = group;
|
||||
this.ingredients = Objects.requireNonNullElseGet(ingredients, LinkedList::new);
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(@NotNull String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
public void addIngredient(DeclareRecipesPacket.Ingredient ingredient) {
|
||||
ingredients.add(ingredient);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<DeclareRecipesPacket.Ingredient> getIngredients() {
|
||||
return ingredients;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
@ -2,35 +2,53 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class SmeltingRecipe extends Recipe {
|
||||
|
||||
private String group;
|
||||
private DeclareRecipesPacket.Ingredient ingredient;
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
private ItemStack result;
|
||||
private float experience;
|
||||
|
||||
private int cookingTime;
|
||||
|
||||
public SmeltingRecipe(String recipeId, String group) {
|
||||
protected SmeltingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(RecipeType.SMELTING, recipeId);
|
||||
setGroup(group);
|
||||
this.group = group;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(@NotNull String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket.Ingredient getIngredient() {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
public void setIngredient(DeclareRecipesPacket.Ingredient ingredient) {
|
||||
public void setIngredient(@NotNull DeclareRecipesPacket.Ingredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
@ -2,40 +2,49 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class SmithingRecipe extends Recipe {
|
||||
|
||||
private DeclareRecipesPacket.Ingredient baseIngredient;
|
||||
private DeclareRecipesPacket.Ingredient additionIngredient;
|
||||
private ItemStack result;
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
protected SmithingRecipe(String recipeId, String group) {
|
||||
protected SmithingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull DeclareRecipesPacket.Ingredient baseIngredient,
|
||||
@NotNull DeclareRecipesPacket.Ingredient additionIngredient,
|
||||
@NotNull ItemStack result
|
||||
) {
|
||||
super(RecipeType.SMITHING, recipeId);
|
||||
setGroup(group);
|
||||
this.baseIngredient = baseIngredient;
|
||||
this.additionIngredient = additionIngredient;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket.Ingredient getBaseIngredient() {
|
||||
return baseIngredient;
|
||||
}
|
||||
|
||||
public void setBaseIngredient(DeclareRecipesPacket.Ingredient baseIngredient) {
|
||||
public void setBaseIngredient(@NotNull DeclareRecipesPacket.Ingredient baseIngredient) {
|
||||
this.baseIngredient = baseIngredient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket.Ingredient getAdditionIngredient() {
|
||||
return additionIngredient;
|
||||
}
|
||||
|
||||
public void setAdditionIngredient(DeclareRecipesPacket.Ingredient additionIngredient) {
|
||||
public void setAdditionIngredient(@NotNull DeclareRecipesPacket.Ingredient additionIngredient) {
|
||||
this.additionIngredient = additionIngredient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
@ -2,35 +2,53 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class SmokingRecipe extends Recipe {
|
||||
|
||||
private String group;
|
||||
private DeclareRecipesPacket.Ingredient ingredient;
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
private ItemStack result;
|
||||
private float experience;
|
||||
|
||||
private int cookingTime;
|
||||
|
||||
public SmokingRecipe(String recipeId, String group) {
|
||||
super(RecipeType.SMELTING, recipeId);
|
||||
setGroup(group);
|
||||
protected SmokingRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull ItemStack result,
|
||||
float experience,
|
||||
int cookingTime
|
||||
) {
|
||||
super(RecipeType.SMOKING, recipeId);
|
||||
this.group = group;
|
||||
this.result = result;
|
||||
this.experience = experience;
|
||||
this.cookingTime = cookingTime;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(@NotNull String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket.Ingredient getIngredient() {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
public void setIngredient(DeclareRecipesPacket.Ingredient ingredient) {
|
||||
public void setIngredient(@NotNull DeclareRecipesPacket.Ingredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
@ -2,31 +2,49 @@ package net.minestom.server.recipe;
|
||||
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class StonecutterRecipe extends Recipe {
|
||||
|
||||
private String group;
|
||||
private DeclareRecipesPacket.Ingredient ingredient;
|
||||
private ItemStack result;
|
||||
|
||||
private ItemStack result = ItemStack.getAirItem();
|
||||
|
||||
protected StonecutterRecipe(String recipeId, String group) {
|
||||
protected StonecutterRecipe(
|
||||
@NotNull String recipeId,
|
||||
@NotNull String group,
|
||||
@NotNull DeclareRecipesPacket.Ingredient ingredient,
|
||||
@NotNull ItemStack result
|
||||
) {
|
||||
super(RecipeType.STONECUTTING, recipeId);
|
||||
setGroup(group);
|
||||
this.group = group;
|
||||
this.ingredient = ingredient;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(@NotNull String group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclareRecipesPacket.Ingredient getIngredient() {
|
||||
return ingredient;
|
||||
}
|
||||
|
||||
public void setIngredient(DeclareRecipesPacket.Ingredient ingredient) {
|
||||
public void setIngredient(@NotNull DeclareRecipesPacket.Ingredient ingredient) {
|
||||
this.ingredient = ingredient;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ItemStack result) {
|
||||
public void setResult(@NotNull ItemStack result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user