Skip to content

Commit

Permalink
添加IRecipe接口类
Browse files Browse the repository at this point in the history
  • Loading branch information
YufiriaMazenta committed Feb 18, 2024
1 parent 7735f28 commit 99d3ea3
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.github.yufiria.craftorithm.recipe;

import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public abstract class BaseRecipe<T> implements IRecipe<T> {

protected Integer priority;
protected NamespacedKey recipeKey;

public BaseRecipe(NamespacedKey recipeKey) {
this.recipeKey = recipeKey;
}

@Override
@NotNull
public NamespacedKey key() {
return recipeKey;
}

@Override
public @Nullable Integer priority() {
return this.priority;
}

@Override
public void setPriority(@Nullable Integer priority) {
this.priority = priority;
}
}
21 changes: 21 additions & 0 deletions src/main/java/com/github/yufiria/craftorithm/recipe/IRecipe.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.github.yufiria.craftorithm.recipe;

import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public interface IRecipe<T> {

@NotNull NamespacedKey key();

ItemStack result(Player player);

boolean match(T matchObj);

@Nullable Integer priority();

void setPriority(@Nullable Integer priority);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.github.yufiria.craftorithm.recipe;

import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;

public class ShapedRecipe extends BaseRecipe<String[][]> {

protected ItemStack result;
protected String[][] ingredients;

public ShapedRecipe(NamespacedKey recipeKey) {
super(recipeKey);
this.priority = 0;
}

public ShapedRecipe(NamespacedKey recipeKey, ItemStack result, String[][] ingredients, Integer priority) {
super(recipeKey);
this.result = result;
this.ingredients = ingredients;
this.priority = priority;
}

public String[][] ingredientIds() {
return ingredients;
}

public ShapedRecipe setIngredients(String[][] ingredients) {
this.ingredients = ingredients;
return this;
}

public ShapedRecipe setResult(ItemStack result) {
this.result = result;
return this;
}

@Override
@NotNull
public ItemStack result(Player player) {
return result;
}

@Override
public boolean match(String[][] matchObj) {
//TODO
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.github.yufiria.craftorithm.recipe.handler;

import crypticlib.listener.BukkitListener;

@BukkitListener
public class ShapedRecipeHandler {


}

0 comments on commit 99d3ea3

Please sign in to comment.