Compare commits
1 Commits
d84c71f279
...
12f7157dc7
Author | SHA1 | Date | |
---|---|---|---|
12f7157dc7 |
@ -1,11 +0,0 @@
|
|||||||
package cz.jzitnik.game.annotations;
|
|
||||||
|
|
||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
public @interface CraftingRecipeRegistry {
|
|
||||||
String[] recipe();
|
|
||||||
String result();
|
|
||||||
int amount();
|
|
||||||
}
|
|
@ -2,8 +2,6 @@ package cz.jzitnik.game.crafting;
|
|||||||
|
|
||||||
import cz.jzitnik.game.entities.items.InventoryItem;
|
import cz.jzitnik.game.entities.items.InventoryItem;
|
||||||
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
|
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
import org.reflections.Reflections;
|
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@ -11,44 +9,97 @@ public class CraftingRecipeList {
|
|||||||
private static final List<CraftingRecipe> recipes = new ArrayList<>();
|
private static final List<CraftingRecipe> recipes = new ArrayList<>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
registerRecipes();
|
// Oak planks
|
||||||
}
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
|
{"oak_log", null, null},
|
||||||
|
{null, null, null},
|
||||||
|
{null, null, null}
|
||||||
|
}, () -> new InventoryItem(4, ItemBlockSupplier.getItem("oak_planks"))));
|
||||||
|
|
||||||
private static void registerRecipes() {
|
// Crafting table
|
||||||
Reflections reflections = new Reflections("cz.jzitnik.game.crafting.recipes");
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
Set<Class<?>> recipeClasses = reflections.getTypesAnnotatedWith(CraftingRecipeRegistry.class);
|
{"oak_planks", "oak_planks", null},
|
||||||
|
{"oak_planks", "oak_planks", null},
|
||||||
|
{null, null, null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("crafting_table"))));
|
||||||
|
|
||||||
for (Class<?> clazz : recipeClasses) {
|
// Stick
|
||||||
try {
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
CraftingRecipeRegistry annotation = clazz.getAnnotation(CraftingRecipeRegistry.class);
|
{"oak_planks", null, null},
|
||||||
String[][] recipeGrid = convertTo2DGrid(annotation.recipe());
|
{"oak_planks", null, null},
|
||||||
|
{null, null, null}
|
||||||
|
}, () -> new InventoryItem(4, ItemBlockSupplier.getItem("stick"))));
|
||||||
|
|
||||||
recipes.add(new CraftingRecipe(recipeGrid,
|
// Wooden pickaxe
|
||||||
() -> new InventoryItem(annotation.amount(), ItemBlockSupplier.getItem(annotation.result()))));
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
} catch (Exception e) {
|
{"oak_planks", "oak_planks", "oak_planks"},
|
||||||
e.printStackTrace();
|
{null, "stick", null},
|
||||||
}
|
{null, "stick", null}
|
||||||
}
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_pickaxe"))));
|
||||||
}
|
|
||||||
|
|
||||||
private static String[][] convertTo2DGrid(String[] flatGrid) {
|
// Wooden axe
|
||||||
int size = (int) Math.sqrt(flatGrid.length); // Assumes 3x3
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
String[][] grid = new String[size][size];
|
{"oak_planks", "oak_planks", null},
|
||||||
|
{"oak_planks", "stick", null},
|
||||||
|
{null, "stick", null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||||
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
|
{null, "oak_planks", "oak_planks"},
|
||||||
|
{null, "stick", "oak_planks"},
|
||||||
|
{null, "stick", null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
// Stone pickaxe
|
||||||
System.arraycopy(flatGrid, i * size, grid[i], 0, size);
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
}
|
{"cobblestone", "cobblestone", "cobblestone"},
|
||||||
|
{null, "stick", null},
|
||||||
|
{null, "stick", null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||||
|
|
||||||
// Convert "_" placeholders back to null
|
// Stone axe
|
||||||
for (int i = 0; i < size; i++) {
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
for (int j = 0; j < size; j++) {
|
{"cobblestone", "cobblestone", null},
|
||||||
if (grid[i][j].equals("_")) {
|
{"cobblestone", "stick", null},
|
||||||
grid[i][j] = null;
|
{null, "stick", null}
|
||||||
}
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||||
}
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
}
|
{null, "cobblestone", "cobblestone"},
|
||||||
|
{null, "stick", "cobblestone"},
|
||||||
|
{null, "stick", null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||||
|
|
||||||
return grid;
|
// Chest
|
||||||
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
|
{"oak_planks", "oak_planks", "oak_planks"},
|
||||||
|
{"oak_planks", null, "oak_planks"},
|
||||||
|
{"oak_planks", "oak_planks", "oak_planks"}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("chest"))));
|
||||||
|
|
||||||
|
// Wooden shovel
|
||||||
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
|
{null, "oak_planks", null},
|
||||||
|
{null, "stick", null},
|
||||||
|
{null, "stick", null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_shovel"))));
|
||||||
|
|
||||||
|
// Stone shovel
|
||||||
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
|
{null, "cobblestone", null},
|
||||||
|
{null, "stick", null},
|
||||||
|
{null, "stick", null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("stone_shovel"))));
|
||||||
|
|
||||||
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
|
{"cobblestone", "cobblestone", "cobblestone"},
|
||||||
|
{"cobblestone", null, "cobblestone"},
|
||||||
|
{"cobblestone", "cobblestone", "cobblestone"}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("furnace"))));
|
||||||
|
|
||||||
|
recipes.add(new CraftingRecipe(new String[][]{
|
||||||
|
{"oak_planks", "oak_planks", null},
|
||||||
|
{"oak_planks", "oak_planks", null},
|
||||||
|
{"oak_planks", "oak_planks", null}
|
||||||
|
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("oak_door"))));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<CraftingRecipe> getRecipe(String[] r) {
|
public static Optional<CraftingRecipe> getRecipe(String[] r) {
|
||||||
@ -64,6 +115,7 @@ public class CraftingRecipeList {
|
|||||||
int n = array.length;
|
int n = array.length;
|
||||||
int minRow = n, maxRow = -1, minCol = n, maxCol = -1;
|
int minRow = n, maxRow = -1, minCol = n, maxCol = -1;
|
||||||
|
|
||||||
|
// Find the bounding box of non-null values
|
||||||
for (int i = 0; i < n; i++) {
|
for (int i = 0; i < n; i++) {
|
||||||
for (int j = 0; j < n; j++) {
|
for (int j = 0; j < n; j++) {
|
||||||
if (array[i][j] != null) {
|
if (array[i][j] != null) {
|
||||||
@ -75,6 +127,7 @@ public class CraftingRecipeList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If all elements are null, return an empty array
|
||||||
if (maxRow == -1) {
|
if (maxRow == -1) {
|
||||||
return new String[0][0];
|
return new String[0][0];
|
||||||
}
|
}
|
||||||
@ -83,6 +136,7 @@ public class CraftingRecipeList {
|
|||||||
int newSizeCol = maxCol - minCol + 1;
|
int newSizeCol = maxCol - minCol + 1;
|
||||||
String[][] trimmedArray = new String[newSizeRow][newSizeCol];
|
String[][] trimmedArray = new String[newSizeRow][newSizeCol];
|
||||||
|
|
||||||
|
// Copy the relevant portion of the array
|
||||||
for (int i = 0; i < newSizeRow; i++) {
|
for (int i = 0; i < newSizeRow; i++) {
|
||||||
System.arraycopy(array[minRow + i], minCol, trimmedArray[i], 0, newSizeCol);
|
System.arraycopy(array[minRow + i], minCol, trimmedArray[i], 0, newSizeCol);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"oak_planks", "oak_planks", "oak_planks",
|
|
||||||
"oak_planks", "_", "oak_planks",
|
|
||||||
"oak_planks", "oak_planks", "oak_planks"
|
|
||||||
},
|
|
||||||
result = "chest",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class ChestRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"oak_planks", "oak_planks", "_",
|
|
||||||
"oak_planks", "oak_planks", "_",
|
|
||||||
"_", "_", "_"
|
|
||||||
},
|
|
||||||
result = "crafting_table",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class CraftingTableRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"cobblestone", "cobblestone", "cobblestone",
|
|
||||||
"cobblestone", "_", "cobblestone",
|
|
||||||
"cobblestone", "cobblestone", "cobblestone"
|
|
||||||
},
|
|
||||||
result = "furnace",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class FurnaceRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"oak_planks", "oak_planks", "_",
|
|
||||||
"oak_planks", "oak_planks", "_",
|
|
||||||
"oak_planks", "oak_planks", "_"
|
|
||||||
},
|
|
||||||
result = "oak_door",
|
|
||||||
amount = 3
|
|
||||||
)
|
|
||||||
public class OakDoorRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"oak_log", "_", "_",
|
|
||||||
"_", "_", "_",
|
|
||||||
"_", "_", "_"
|
|
||||||
},
|
|
||||||
result = "oak_planks",
|
|
||||||
amount = 4
|
|
||||||
)
|
|
||||||
public class OakPlanksRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"oak_planks", "_", "_",
|
|
||||||
"oak_planks", "_", "_",
|
|
||||||
"_", "_", "_"
|
|
||||||
},
|
|
||||||
result = "stick",
|
|
||||||
amount = 4
|
|
||||||
)
|
|
||||||
public class StickRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"_", "cobblestone", "cobblestone",
|
|
||||||
"_", "stick", "cobblestone",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "stone_pickaxe",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class StoneAxe2Recipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"cobblestone", "cobblestone", "_",
|
|
||||||
"cobblestone", "stick", "_",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "stone_pickaxe",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class StoneAxeRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"cobblestone", "cobblestone", "cobblestone",
|
|
||||||
"_", "stick", "_",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "stone_pickaxe",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class StonePickaxeRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"_", "cobblestone", "_",
|
|
||||||
"_", "stick", "_",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "stone_shovel",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class StoneShovelRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"_", "oak_planks", "oak_planks",
|
|
||||||
"_", "stick", "oak_planks",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "wooden_axe",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class WoodenAxe2Recipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"oak_planks", "oak_planks", "_",
|
|
||||||
"oak_planks", "stick", "_",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "oak_planks",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class WoodenAxeRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"oak_planks", "oak_planks", "oak_planks",
|
|
||||||
"_", "stick", "_",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "wooden_pickaxe",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class WoodenPickaxeRecipe {}
|
|
@ -1,14 +0,0 @@
|
|||||||
package cz.jzitnik.game.crafting.recipes;
|
|
||||||
|
|
||||||
import cz.jzitnik.game.annotations.CraftingRecipeRegistry;
|
|
||||||
|
|
||||||
@CraftingRecipeRegistry(
|
|
||||||
recipe = {
|
|
||||||
"_", "oak_planks", "_",
|
|
||||||
"_", "stick", "_",
|
|
||||||
"_", "stick", "_"
|
|
||||||
},
|
|
||||||
result = "wooden_shovel",
|
|
||||||
amount = 1
|
|
||||||
)
|
|
||||||
public class WoodenShovelRecipe {}
|
|
Loading…
x
Reference in New Issue
Block a user