mirror of
https://github.com/Minestom/Minestom.git
synced 2024-12-26 19:18:12 +01:00
Optimization + added Recipe#shouldShow check
This commit is contained in:
parent
9d0cec23df
commit
3614c378f3
@ -6,6 +6,7 @@ import fr.themode.demo.commands.HealthCommand;
|
|||||||
import fr.themode.demo.commands.SimpleCommand;
|
import fr.themode.demo.commands.SimpleCommand;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.command.CommandManager;
|
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.BlockManager;
|
||||||
import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule;
|
import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule;
|
||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
@ -33,7 +34,12 @@ public class Main {
|
|||||||
commandManager.register(new SimpleCommand());
|
commandManager.register(new SimpleCommand());
|
||||||
|
|
||||||
RecipeManager recipeManager = MinecraftServer.getRecipeManager();
|
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));
|
shapelessRecipe.setResult(new ItemStack(Material.STONE, (byte) 1));
|
||||||
DeclareRecipesPacket.Ingredient ingredient = new DeclareRecipesPacket.Ingredient();
|
DeclareRecipesPacket.Ingredient ingredient = new DeclareRecipesPacket.Ingredient();
|
||||||
ingredient.items = new ItemStack[]{new ItemStack(Material.STONE, (byte) 3)};
|
ingredient.items = new ItemStack[]{new ItemStack(Material.STONE, (byte) 3)};
|
||||||
|
@ -30,16 +30,12 @@ public class AStarPathfinder {
|
|||||||
int checkCount = 0;
|
int checkCount = 0;
|
||||||
|
|
||||||
while (!open.isEmpty()) {
|
while (!open.isEmpty()) {
|
||||||
checkCount++;
|
|
||||||
if (checkCount >= maxCheck)
|
|
||||||
break;
|
|
||||||
|
|
||||||
Node current = getCurrentNode(open);
|
Node current = getCurrentNode(open);
|
||||||
open.remove(current);
|
open.remove(current);
|
||||||
closed.add(current);
|
closed.add(current);
|
||||||
|
|
||||||
if (isTargetNode(end, current)) {
|
if (isTargetNode(end, current)) {
|
||||||
System.out.println("FOUND, RETURN: " + (System.nanoTime() - time));
|
//System.out.println("FOUND, RETURN: " + (System.nanoTime() - time));
|
||||||
return buildPath(current);
|
return buildPath(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +55,10 @@ public class AStarPathfinder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To do not check the whole world
|
||||||
|
checkCount++;
|
||||||
|
if (checkCount >= maxCheck)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -113,7 +113,9 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
|||||||
|
|
||||||
List<String> recipesIdentifier = new ArrayList<>();
|
List<String> recipesIdentifier = new ArrayList<>();
|
||||||
for (Recipe recipe : recipeManager.getRecipes()) {
|
for (Recipe recipe : recipeManager.getRecipes()) {
|
||||||
// TODO check condition
|
if (!recipe.shouldShow(player))
|
||||||
|
continue;
|
||||||
|
|
||||||
recipesIdentifier.add(recipe.getRecipeId());
|
recipesIdentifier.add(recipe.getRecipeId());
|
||||||
}
|
}
|
||||||
String[] identifiers = recipesIdentifier.toArray(new String[recipesIdentifier.size()]);
|
String[] identifiers = recipesIdentifier.toArray(new String[recipesIdentifier.size()]);
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package net.minestom.server.recipe;
|
package net.minestom.server.recipe;
|
||||||
|
|
||||||
public class Recipe {
|
import net.minestom.server.entity.Player;
|
||||||
|
|
||||||
|
public abstract class Recipe {
|
||||||
|
|
||||||
protected RecipeType recipeType;
|
protected RecipeType recipeType;
|
||||||
protected String recipeId;
|
protected String recipeId;
|
||||||
@ -11,6 +13,8 @@ public class Recipe {
|
|||||||
this.recipeId = recipeId;
|
this.recipeId = recipeId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public abstract boolean shouldShow(Player player);
|
||||||
|
|
||||||
public String getGroup() {
|
public String getGroup() {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ShapedRecipe extends Recipe {
|
public abstract class ShapedRecipe extends Recipe {
|
||||||
|
|
||||||
private int width, height;
|
private int width, height;
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ShapelessRecipe extends Recipe {
|
public abstract class ShapelessRecipe extends Recipe {
|
||||||
|
|
||||||
private List<DeclareRecipesPacket.Ingredient> ingredients = new ArrayList<>();
|
private List<DeclareRecipesPacket.Ingredient> ingredients = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package net.minestom.server.recipe;
|
|||||||
import net.minestom.server.item.ItemStack;
|
import net.minestom.server.item.ItemStack;
|
||||||
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
import net.minestom.server.network.packet.server.play.DeclareRecipesPacket;
|
||||||
|
|
||||||
public class SmeltingRecipe extends Recipe {
|
public abstract class SmeltingRecipe extends Recipe {
|
||||||
|
|
||||||
private DeclareRecipesPacket.Ingredient ingredient;
|
private DeclareRecipesPacket.Ingredient ingredient;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user