Optimization + added Recipe#shouldShow check

This commit is contained in:
Felix Cravic 2020-04-26 04:50:38 +02:00
parent 9d0cec23df
commit 3614c378f3
7 changed files with 23 additions and 11 deletions

View File

@ -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)};

View File

@ -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;

View File

@ -113,7 +113,9 @@ public class LoginStartPacket implements ClientPreplayPacket {
List<String> 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()]);

View File

@ -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;
}

View File

@ -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;

View File

@ -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<DeclareRecipesPacket.Ingredient> ingredients = new ArrayList<>();

View File

@ -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;