diff --git a/src/main/java/fr/themode/demo/Main.java b/src/main/java/fr/themode/demo/Main.java index 5725637f5..c8a9197d9 100644 --- a/src/main/java/fr/themode/demo/Main.java +++ b/src/main/java/fr/themode/demo/Main.java @@ -6,6 +6,7 @@ import fr.themode.demo.commands.HealthCommand; import fr.themode.demo.commands.SimpleCommand; import net.minestom.server.MinecraftServer; import net.minestom.server.command.CommandManager; +import net.minestom.server.entity.Player; import net.minestom.server.instance.block.BlockManager; import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule; import net.minestom.server.item.ItemStack; @@ -33,7 +34,12 @@ public class Main { commandManager.register(new SimpleCommand()); RecipeManager recipeManager = MinecraftServer.getRecipeManager(); - ShapelessRecipe shapelessRecipe = new ShapelessRecipe("test", "groupname"); + ShapelessRecipe shapelessRecipe = new ShapelessRecipe("test", "groupname") { + @Override + public boolean shouldShow(Player player) { + return true; + } + }; shapelessRecipe.setResult(new ItemStack(Material.STONE, (byte) 1)); DeclareRecipesPacket.Ingredient ingredient = new DeclareRecipesPacket.Ingredient(); ingredient.items = new ItemStack[]{new ItemStack(Material.STONE, (byte) 3)}; diff --git a/src/main/java/net/minestom/server/entity/pathfinding/AStarPathfinder.java b/src/main/java/net/minestom/server/entity/pathfinding/AStarPathfinder.java index f271bec8d..1e40b70fc 100644 --- a/src/main/java/net/minestom/server/entity/pathfinding/AStarPathfinder.java +++ b/src/main/java/net/minestom/server/entity/pathfinding/AStarPathfinder.java @@ -30,16 +30,12 @@ public class AStarPathfinder { int checkCount = 0; while (!open.isEmpty()) { - checkCount++; - if (checkCount >= maxCheck) - break; - Node current = getCurrentNode(open); open.remove(current); closed.add(current); if (isTargetNode(end, current)) { - System.out.println("FOUND, RETURN: " + (System.nanoTime() - time)); + //System.out.println("FOUND, RETURN: " + (System.nanoTime() - time)); return buildPath(current); } @@ -59,6 +55,10 @@ public class AStarPathfinder { } } + // To do not check the whole world + checkCount++; + if (checkCount >= maxCheck) + break; } return null; diff --git a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java index de49de6af..c03218b8e 100644 --- a/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java +++ b/src/main/java/net/minestom/server/network/packet/client/login/LoginStartPacket.java @@ -113,7 +113,9 @@ public class LoginStartPacket implements ClientPreplayPacket { List recipesIdentifier = new ArrayList<>(); for (Recipe recipe : recipeManager.getRecipes()) { - // TODO check condition + if (!recipe.shouldShow(player)) + continue; + recipesIdentifier.add(recipe.getRecipeId()); } String[] identifiers = recipesIdentifier.toArray(new String[recipesIdentifier.size()]); diff --git a/src/main/java/net/minestom/server/recipe/Recipe.java b/src/main/java/net/minestom/server/recipe/Recipe.java index 086a0d092..433e0ac34 100644 --- a/src/main/java/net/minestom/server/recipe/Recipe.java +++ b/src/main/java/net/minestom/server/recipe/Recipe.java @@ -1,6 +1,8 @@ package net.minestom.server.recipe; -public class Recipe { +import net.minestom.server.entity.Player; + +public abstract class Recipe { protected RecipeType recipeType; protected String recipeId; @@ -11,6 +13,8 @@ public class Recipe { this.recipeId = recipeId; } + public abstract boolean shouldShow(Player player); + public String getGroup() { return group; } diff --git a/src/main/java/net/minestom/server/recipe/ShapedRecipe.java b/src/main/java/net/minestom/server/recipe/ShapedRecipe.java index 8f1e00ecd..5b9fd2810 100644 --- a/src/main/java/net/minestom/server/recipe/ShapedRecipe.java +++ b/src/main/java/net/minestom/server/recipe/ShapedRecipe.java @@ -6,7 +6,7 @@ import net.minestom.server.network.packet.server.play.DeclareRecipesPacket; import java.util.ArrayList; import java.util.List; -public class ShapedRecipe extends Recipe { +public abstract class ShapedRecipe extends Recipe { private int width, height; diff --git a/src/main/java/net/minestom/server/recipe/ShapelessRecipe.java b/src/main/java/net/minestom/server/recipe/ShapelessRecipe.java index 6a9be3827..9cfcd579b 100644 --- a/src/main/java/net/minestom/server/recipe/ShapelessRecipe.java +++ b/src/main/java/net/minestom/server/recipe/ShapelessRecipe.java @@ -6,7 +6,7 @@ import net.minestom.server.network.packet.server.play.DeclareRecipesPacket; import java.util.ArrayList; import java.util.List; -public class ShapelessRecipe extends Recipe { +public abstract class ShapelessRecipe extends Recipe { private List ingredients = new ArrayList<>(); diff --git a/src/main/java/net/minestom/server/recipe/SmeltingRecipe.java b/src/main/java/net/minestom/server/recipe/SmeltingRecipe.java index 074940f0e..a3c44e167 100644 --- a/src/main/java/net/minestom/server/recipe/SmeltingRecipe.java +++ b/src/main/java/net/minestom/server/recipe/SmeltingRecipe.java @@ -3,7 +3,7 @@ package net.minestom.server.recipe; import net.minestom.server.item.ItemStack; import net.minestom.server.network.packet.server.play.DeclareRecipesPacket; -public class SmeltingRecipe extends Recipe { +public abstract class SmeltingRecipe extends Recipe { private DeclareRecipesPacket.Ingredient ingredient;