refactor: ItemBlockSupplier
This commit is contained in:
parent
f80c6a9815
commit
1be9f75ae7
@ -9,4 +9,5 @@ import java.lang.annotation.ElementType;
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface BlockRegistry {
|
||||
String value();
|
||||
String drops() default "";
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package cz.jzitnik.game.annotations;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.TYPE)
|
||||
public @interface EntityRegistry {
|
||||
String value();
|
||||
}
|
@ -14,92 +14,92 @@ public class CraftingRecipeList {
|
||||
{"oak_log", null, null},
|
||||
{null, null, null},
|
||||
{null, null, null}
|
||||
}, () -> new InventoryItem(4, ItemBlockSupplier.Items.oakPlanks())));
|
||||
}, () -> new InventoryItem(4, ItemBlockSupplier.getItem("oak_planks"))));
|
||||
|
||||
// Crafting table
|
||||
recipes.add(new CraftingRecipe(new String[][]{
|
||||
{"oak_planks", "oak_planks", null},
|
||||
{"oak_planks", "oak_planks", null},
|
||||
{null, null, null}
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.craftingTable())));
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("crafting_table"))));
|
||||
|
||||
// Stick
|
||||
recipes.add(new CraftingRecipe(new String[][]{
|
||||
{"oak_planks", null, null},
|
||||
{"oak_planks", null, null},
|
||||
{null, null, null}
|
||||
}, () -> new InventoryItem(4, ItemBlockSupplier.Items.stick())));
|
||||
}, () -> new InventoryItem(4, ItemBlockSupplier.getItem("stick"))));
|
||||
|
||||
// Wooden pickaxe
|
||||
recipes.add(new CraftingRecipe(new String[][]{
|
||||
{"oak_planks", "oak_planks", "oak_planks"},
|
||||
{null, "stick", null},
|
||||
{null, "stick", null}
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.woodenPickaxe())));
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_pickaxe"))));
|
||||
|
||||
// Wooden axe
|
||||
recipes.add(new CraftingRecipe(new String[][]{
|
||||
{"oak_planks", "oak_planks", null},
|
||||
{"oak_planks", "stick", null},
|
||||
{null, "stick", null}
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.woodenAxe())));
|
||||
}, () -> 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.Items.woodenAxe())));
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||
|
||||
// Stone pickaxe
|
||||
recipes.add(new CraftingRecipe(new String[][]{
|
||||
{"cobblestone", "cobblestone", "cobblestone"},
|
||||
{null, "stick", null},
|
||||
{null, "stick", null}
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.stonePickaxe())));
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||
|
||||
// Stone axe
|
||||
recipes.add(new CraftingRecipe(new String[][]{
|
||||
{"cobblestone", "cobblestone", null},
|
||||
{"cobblestone", "stick", null},
|
||||
{null, "stick", null}
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.stoneAxe())));
|
||||
}, () -> 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.Items.stoneAxe())));
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
|
||||
|
||||
// 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.Items.chest())));
|
||||
}, () -> 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.Items.woodenShovel())));
|
||||
}, () -> 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.Items.stoneShovel())));
|
||||
}, () -> 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.Items.furnace())));
|
||||
}, () -> 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.Items.oakDoor())));
|
||||
}, () -> new InventoryItem(1, ItemBlockSupplier.getItem("oak_door"))));
|
||||
}
|
||||
|
||||
public static Optional<CraftingRecipe> getRecipe(String[] r) {
|
||||
|
@ -4,6 +4,7 @@ import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -21,6 +22,7 @@ public class Item {
|
||||
private int stackAmount = 64;
|
||||
private int addHunger = 0;
|
||||
private int dealDamage = 1;
|
||||
@Setter
|
||||
private Optional<Block> block = Optional.empty();
|
||||
|
||||
public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, ToolVariant toolVariant, double miningDecrease, int durability, boolean stackable) {
|
||||
|
@ -1,191 +1,124 @@
|
||||
package cz.jzitnik.game.entities.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.blocks.OakDoorData;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.EntityRegistry;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.blocks.Chest;
|
||||
import cz.jzitnik.game.blocks.Furnace;
|
||||
import cz.jzitnik.game.mobs.services.pig.PigData;
|
||||
import cz.jzitnik.game.mobs.services.sheep.SheepData;
|
||||
import cz.jzitnik.game.sprites.Pig;
|
||||
import cz.jzitnik.game.sprites.Sheep;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemBlockSupplier {
|
||||
// This is necessary to not get infinite recursion
|
||||
private static class Helper {
|
||||
public static Item dirt(Block ref) {
|
||||
return new Item("dirt", "Dirt block", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_DIRT, ref);
|
||||
private static final HashMap<String, Constructor<Block>> registeredBlocks = new HashMap<>();
|
||||
private static final HashMap<String, Constructor<Item>> registeredItems = new HashMap<>();
|
||||
private static final HashMap<String, Constructor<Block>> registeredEntities = new HashMap<>();
|
||||
private static final HashMap<String, String> dropsList = new HashMap<>();
|
||||
|
||||
static {
|
||||
registerItems();
|
||||
registerBlocks();
|
||||
registerEntities();
|
||||
}
|
||||
public static Item cobblestone(Block ref) {
|
||||
return new Item("cobblestone", "Cobblestone", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_COBBLESTONE, ref);
|
||||
|
||||
private static void registerBlocks() {
|
||||
Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
|
||||
Set<Class<?>> blockClasses = reflections.getTypesAnnotatedWith(BlockRegistry.class);
|
||||
|
||||
for (Class<?> clazz : blockClasses) {
|
||||
try {
|
||||
Constructor<Block> blockInstance = (Constructor<Block>) clazz.getDeclaredConstructor();
|
||||
BlockRegistry annotation = clazz.getAnnotation(BlockRegistry.class);
|
||||
registeredBlocks.put(annotation.value(), blockInstance);
|
||||
|
||||
if (registeredItems.containsKey(annotation.value())) {
|
||||
dropsList.put(annotation.value(), annotation.value());
|
||||
} else {
|
||||
dropsList.put(annotation.value(), annotation.drops());
|
||||
}
|
||||
public static Item stone(Block ref) {
|
||||
return new Item("stone", "Stone", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_STONE, ref);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static Item oakLog(Block ref) {
|
||||
return new Item("oak_log", "Oak log", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_LOG, ref);
|
||||
}
|
||||
public static Item oakPlanks(Block ref) {
|
||||
return new Item("oak_planks", "Oak planks", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_PLANKS, ref);
|
||||
}
|
||||
public static Item craftingTable(Block ref) {
|
||||
return new Item("crafting_table", "Crafting table", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_CRAFTING_TABLE, ref);
|
||||
}
|
||||
public static Item chest(Block ref) {
|
||||
return new Item("chest", "Chest", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_CHEST, ref);
|
||||
}
|
||||
public static Item furnace(Block ref) {
|
||||
return new Item("furnace", "Furnace", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_FURNACE, ref);
|
||||
}
|
||||
public static Item oakDoor(Block ref) {
|
||||
return new Item("oak_door", "Oak door", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_DOOR, ref);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Blocks {
|
||||
public static Block dirt() {
|
||||
var block = new Block("dirt", SpriteLoader.SPRITES.DIRT, 1, ItemType.SHOVEL, new ArrayList<>());
|
||||
block.setDrops(List.of(Helper.dirt(block)));
|
||||
return block;
|
||||
private static void registerEntities() {
|
||||
Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
|
||||
Set<Class<?>> entityClasses = reflections.getTypesAnnotatedWith(EntityRegistry.class);
|
||||
|
||||
for (Class<?> clazz : entityClasses) {
|
||||
try {
|
||||
Constructor<Block> entityInstance = (Constructor<Block>) clazz.getDeclaredConstructor();
|
||||
EntityRegistry annotation = clazz.getAnnotation(EntityRegistry.class);
|
||||
registeredEntities.put(annotation.value(), entityInstance);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static Block grass() {
|
||||
var block = new Block("grass", SpriteLoader.SPRITES.GRASS, 1, ItemType.SHOVEL, new ArrayList<>());
|
||||
block.setDrops(List.of(Items.dirt()));
|
||||
return block;
|
||||
}
|
||||
public static Block cobblestone() {
|
||||
var block = new Block("cobblestone", SpriteLoader.SPRITES.COBBLESTONE, 15, ItemType.PICKAXE, Arrays.stream(ToolVariant.values()).toList());
|
||||
block.setDrops(List.of(Helper.cobblestone(block)));
|
||||
return block;
|
||||
}
|
||||
public static Block stone() {
|
||||
var block = new Block("stone", SpriteLoader.SPRITES.STONE, 15, ItemType.PICKAXE, Arrays.stream(ToolVariant.values()).toList());
|
||||
block.setDrops(List.of(Items.cobblestone()));
|
||||
return block;
|
||||
}
|
||||
public static Block oakLog() {
|
||||
var block = new Block("oak_log", SpriteLoader.SPRITES.OAK_LOG, 3, ItemType.AXE, new ArrayList<>());
|
||||
block.setDrops(List.of(Helper.oakLog(block)));
|
||||
return block;
|
||||
}
|
||||
public static Block oakPlanks() {
|
||||
var block = new Block("oak_planks", SpriteLoader.SPRITES.OAK_PLANKS, 3, ItemType.AXE, new ArrayList<>());
|
||||
block.setDrops(List.of(Helper.oakPlanks(block)));
|
||||
return block;
|
||||
}
|
||||
public static Block craftingTable() {
|
||||
var block = new Block("crafting_table", SpriteLoader.SPRITES.CRAFTING_TABLE, 3, ItemType.AXE, new ArrayList<>());
|
||||
block.setDrops(List.of(Helper.craftingTable(block)));
|
||||
return block;
|
||||
}
|
||||
public static Block chest() {
|
||||
var block = new Block("chest", SpriteLoader.SPRITES.CHEST, 3, ItemType.AXE, new ArrayList<>(), new Chest());
|
||||
block.setDrops(List.of(Helper.chest(block)));
|
||||
return block;
|
||||
}
|
||||
public static Block furnace() {
|
||||
var block = new Block("furnace", SpriteLoader.SPRITES.FURNACE, 15, ItemType.PICKAXE, Arrays.stream(ToolVariant.values()).toList());
|
||||
block.setData(new Furnace(block));
|
||||
block.setDrops(List.of(Helper.furnace(block)));
|
||||
return block;
|
||||
}
|
||||
public static Block coalOre() {
|
||||
return new Block("coal_ore", SpriteLoader.SPRITES.COAL_ORE);
|
||||
}
|
||||
public static Block oakDoor() {
|
||||
var block = new Block("oak_door", SpriteLoader.SPRITES.OAK_DOOR, 3, ItemType.AXE, new ArrayList<>());
|
||||
block.setData(new OakDoorData());
|
||||
block.setDrops(List.of(Helper.oakDoor(block)));
|
||||
return block;
|
||||
}
|
||||
}
|
||||
|
||||
// I hate this but whatever
|
||||
public static class Items {
|
||||
public static Item dirt() {
|
||||
return Helper.dirt(Blocks.dirt());
|
||||
private static void registerItems() {
|
||||
Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
|
||||
Set<Class<?>> itemClasses = reflections.getTypesAnnotatedWith(ItemRegistry.class);
|
||||
|
||||
for (Class<?> clazz : itemClasses) {
|
||||
try {
|
||||
Constructor<Item> itemInstance = (Constructor<Item>) clazz.getDeclaredConstructor();
|
||||
ItemRegistry annotation = clazz.getAnnotation(ItemRegistry.class);
|
||||
registeredItems.put(annotation.value(), itemInstance);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public static Item oakPlanks() {
|
||||
return Helper.oakPlanks(Blocks.oakPlanks());
|
||||
}
|
||||
public static Item stick() {
|
||||
return new Item("stick", "Stick", ItemType.USELESS_ITEM, SpriteLoader.SPRITES.ITEM_STICK);
|
||||
}
|
||||
public static Item craftingTable() {
|
||||
return Helper.craftingTable(Blocks.craftingTable());
|
||||
}
|
||||
public static Item woodenPickaxe() {
|
||||
return new Item("wooden_pickaxe", "Wooden pickaxe", ItemType.PICKAXE, SpriteLoader.SPRITES.WOODEN_PICKAXE, ToolVariant.WOODEN, 12, 59, false);
|
||||
}
|
||||
public static Item woodenAxe() {
|
||||
return new Item("wooden_axe", "Wooden axe", ItemType.AXE, SpriteLoader.SPRITES.WOODEN_AXE, ToolVariant.WOODEN, 2, 59, false);
|
||||
}
|
||||
public static Item cobblestone() {
|
||||
return Helper.cobblestone(Blocks.cobblestone());
|
||||
}
|
||||
public static Item stonePickaxe() {
|
||||
return new Item("stone_pickaxe", "Stone pickaxe", ItemType.PICKAXE, SpriteLoader.SPRITES.STONE_PICKAXE, ToolVariant.STONE, 12.5, 132, false);
|
||||
}
|
||||
public static Item stoneAxe() {
|
||||
return new Item("stone_axe", "Stone axe", ItemType.AXE, SpriteLoader.SPRITES.STONE_AXE, ToolVariant.STONE, 3, 132, false);
|
||||
}
|
||||
public static Item woodenShovel() {
|
||||
return new Item("wooden_shovel", "Wooden shovel", ItemType.SHOVEL, SpriteLoader.SPRITES.WOODEN_SHOVEL, ToolVariant.WOODEN, 0.3, 59, false);
|
||||
}
|
||||
public static Item chest() {
|
||||
return Helper.chest(Blocks.chest());
|
||||
}
|
||||
public static Item stoneShovel() {
|
||||
return new Item("stone_shovel", "Stone shovel", ItemType.SHOVEL, SpriteLoader.SPRITES.STONE_SHOVEL, ToolVariant.STONE, 0.5, 132, false);
|
||||
}
|
||||
public static Item stone() {
|
||||
return Helper.stone(Blocks.stone());
|
||||
}
|
||||
public static Item furnace() {
|
||||
return Helper.furnace(Blocks.furnace());
|
||||
}
|
||||
public static Item oakDoor() {
|
||||
return Helper.oakDoor(Blocks.oakDoor());
|
||||
}
|
||||
public static Item porkchop() {
|
||||
return new Item("porkchop", "Porkchop", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_PORKCHOP, 3);
|
||||
}
|
||||
public static Item cookedPorkchop() {
|
||||
return new Item("cooked_porkchop", "Cooked porkchop", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_COOKED_PORKCHOP, 4);
|
||||
}
|
||||
public static Item mutton() {
|
||||
return new Item("mutton", "Mutton", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_MUTTON, 2);
|
||||
}
|
||||
public static Item cookedMutton() {
|
||||
return new Item("cooked_mutton", "Cooked mutton", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_COOKED_MUTTON, 6);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Mobs {
|
||||
public static Block pig() {
|
||||
// Yes, pig is a block. Cry about it.
|
||||
var block = new Block("pig", SpriteLoader.SPRITES.PIG);
|
||||
block.setMob(true);
|
||||
block.setGhost(true);
|
||||
block.setSpriteState(Pig.PigState.RIGHT);
|
||||
block.setMineable(false);
|
||||
block.setData(new PigData());
|
||||
block.setHp(10);
|
||||
public static Block getBlock(String key) {
|
||||
try {
|
||||
Block block = registeredBlocks.get(key).newInstance();
|
||||
block.setDrops(List.of(getItem(dropsList.get(key), block)));
|
||||
return block;
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
public static Block sheep(Sheep.SheepState sheepState) {
|
||||
var block = new Block("sheep", SpriteLoader.SPRITES.SHEEP);
|
||||
block.setMob(true);
|
||||
block.setGhost(true);
|
||||
block.setSpriteState(sheepState);
|
||||
block.setMineable(false);
|
||||
block.setData(new SheepData());
|
||||
block.setHp(8);
|
||||
return block;
|
||||
}
|
||||
|
||||
public static Item getItem(String key) {
|
||||
try {
|
||||
Item item = registeredItems.get(key).newInstance();
|
||||
if (registeredBlocks.containsKey(key)) {
|
||||
item.setBlock(Optional.of(registeredBlocks.get(key).newInstance()));
|
||||
}
|
||||
|
||||
return item;
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static Item getItem(String key, Block block) {
|
||||
try {
|
||||
Item item = registeredItems.get(key).newInstance();
|
||||
if (key.equals(block.getBlockId())) {
|
||||
item.setBlock(Optional.of(block));
|
||||
} else if (registeredBlocks.containsKey(key)) {
|
||||
item.setBlock(Optional.of(registeredBlocks.get(key).newInstance()));
|
||||
}
|
||||
|
||||
return item;
|
||||
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Block getEntity(String key) {
|
||||
try {
|
||||
return registeredEntities.get(key).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,57 +0,0 @@
|
||||
package cz.jzitnik.game.entities.items;
|
||||
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import org.reflections.Reflections;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemBlockSupplierNew {
|
||||
private static final HashMap<String, Block> registeredBlocks = new HashMap<>();
|
||||
private static final HashMap<String, Item> registeredItems = new HashMap<>();
|
||||
|
||||
static {
|
||||
registerBlocks();
|
||||
registerItems();
|
||||
}
|
||||
|
||||
private static void registerBlocks() {
|
||||
Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
|
||||
Set<Class<?>> blockClasses = reflections.getTypesAnnotatedWith(BlockRegistry.class);
|
||||
|
||||
for (Class<?> clazz : blockClasses) {
|
||||
try {
|
||||
Block blockInstance = (Block) clazz.getDeclaredConstructor().newInstance();
|
||||
BlockRegistry annotation = clazz.getAnnotation(BlockRegistry.class);
|
||||
registeredBlocks.put(annotation.value(), blockInstance);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void registerItems() {
|
||||
Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
|
||||
Set<Class<?>> itemClasses = reflections.getTypesAnnotatedWith(ItemRegistry.class);
|
||||
|
||||
for (Class<?> clazz : itemClasses) {
|
||||
try {
|
||||
Item itemInstance = (Item) clazz.getDeclaredConstructor().newInstance();
|
||||
ItemRegistry annotation = clazz.getAnnotation(ItemRegistry.class);
|
||||
registeredItems.put(annotation.value(), itemInstance);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Block getBlock(String id) {
|
||||
return registeredBlocks.get(id);
|
||||
}
|
||||
|
||||
public static Item getItem(String id) {
|
||||
return registeredItems.get(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.blocks.Chest;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@BlockRegistry("chest")
|
||||
public class ChestBlock extends Block {
|
||||
public ChestBlock() {
|
||||
super("chest", SpriteLoader.SPRITES.CHEST, 3, ItemType.AXE, new ArrayList<>(), new Chest());
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@BlockRegistry("cobblestone")
|
||||
public class CobblestoneBlock extends Block {
|
||||
public CobblestoneBlock() {
|
||||
super("cobblestone", SpriteLoader.SPRITES.COBBLESTONE, 15, ItemType.PICKAXE, Arrays.stream(ToolVariant.values()).toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@BlockRegistry("crafting_table")
|
||||
public class CraftingTableBlock extends Block {
|
||||
public CraftingTableBlock() {
|
||||
super("crafting_table", SpriteLoader.SPRITES.CRAFTING_TABLE, 3, ItemType.AXE, new ArrayList<>());
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@BlockRegistry("dirt")
|
||||
public class DirtBlock extends Block {
|
||||
public DirtBlock() {
|
||||
super("dirt", SpriteLoader.SPRITES.DIRT, 1, ItemType.SHOVEL, new ArrayList<>());
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.blocks.Furnace;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@BlockRegistry("furnace")
|
||||
public class FurnaceBlock extends Block {
|
||||
public FurnaceBlock() {
|
||||
super("furnace", SpriteLoader.SPRITES.FURNACE, 15, ItemType.PICKAXE, Arrays.stream(ToolVariant.values()).toList());
|
||||
setData(new Furnace(this));
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@BlockRegistry(value = "grass", drops = "dirt")
|
||||
public class GrassBlock extends Block {
|
||||
public GrassBlock() {
|
||||
super("grass", SpriteLoader.SPRITES.GRASS, 1, ItemType.SHOVEL, new ArrayList<>());
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.blocks.OakDoorData;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@BlockRegistry("oak_door")
|
||||
public class OakDoorBlock extends Block {
|
||||
public OakDoorBlock() {
|
||||
super("oak_door", SpriteLoader.SPRITES.OAK_DOOR, 3, ItemType.AXE, new ArrayList<>());
|
||||
setData(new OakDoorData());
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@BlockRegistry("oak_log")
|
||||
public class OakLogBlock extends Block {
|
||||
public OakLogBlock() {
|
||||
super("oak_log", SpriteLoader.SPRITES.OAK_LOG, 3, ItemType.AXE, new ArrayList<>());
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@BlockRegistry("oak_planks")
|
||||
public class OakPlanksBlock extends Block {
|
||||
public OakPlanksBlock() {
|
||||
super("oak_planks", SpriteLoader.SPRITES.OAK_PLANKS, 3, ItemType.AXE, new ArrayList<>());
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@BlockRegistry("stone")
|
||||
public class StoneBlock extends Block {
|
||||
public StoneBlock() {
|
||||
super("stone", SpriteLoader.SPRITES.STONE, 15, ItemType.PICKAXE, Arrays.stream(ToolVariant.values()).toList());
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("chest")
|
||||
public class ChestItem extends Item {
|
||||
public ChestItem() {
|
||||
super("chest", "Chest", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_CHEST);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("cobblestone")
|
||||
public class CobblestoneItem extends Item {
|
||||
public CobblestoneItem() {
|
||||
super("cobblestone", "Cobblestone", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_COBBLESTONE);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("cooked_mutton")
|
||||
public class CookedMutton extends Item {
|
||||
public CookedMutton() {
|
||||
super("cooked_mutton", "Cooked mutton", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_COOKED_MUTTON, 6);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("cooked_porkchop")
|
||||
public class CookedPorkchop extends Item {
|
||||
public CookedPorkchop() {
|
||||
super("cooked_porkchop", "Cooked porkchop", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_COOKED_PORKCHOP, 4);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("crafting_table")
|
||||
public class CraftingTableItem extends Item {
|
||||
public CraftingTableItem() {
|
||||
super("crafting_table", "Crafting table", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_CRAFTING_TABLE);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("dirt")
|
||||
public class DirtItem extends Item {
|
||||
public DirtItem() {
|
||||
super("dirt", "Dirt block", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_DIRT);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("furnace")
|
||||
public class FurnaceItem extends Item {
|
||||
public FurnaceItem() {
|
||||
super("furnace", "Furnace", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_FURNACE);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("mutton")
|
||||
public class Mutton extends Item {
|
||||
public Mutton() {
|
||||
super("mutton", "Mutton", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_MUTTON, 2);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("oak_door")
|
||||
public class OakDoorItem extends Item {
|
||||
public OakDoorItem() {
|
||||
super("oak_door", "Oak door", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_DOOR);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("oak_log")
|
||||
public class OakLogItem extends Item {
|
||||
public OakLogItem() {
|
||||
super("oak_log", "Oak log", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_LOG);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("oak_planks")
|
||||
public class OakPlanksItem extends Item {
|
||||
public OakPlanksItem() {
|
||||
super("oak_planks", "Oak planks", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_PLANKS);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("porkchop")
|
||||
public class Porkchop extends Item {
|
||||
public Porkchop() {
|
||||
super("porkchop", "Porkchop", ItemType.FOOD, SpriteLoader.SPRITES.ITEM_PORKCHOP, 3);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("stick")
|
||||
public class Stick extends Item {
|
||||
public Stick() {
|
||||
super("stick", "Stick", ItemType.USELESS_ITEM, SpriteLoader.SPRITES.ITEM_STICK);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
@ItemRegistry("stone_axe")
|
||||
public class StoneAxe extends Item {
|
||||
public StoneAxe() {
|
||||
super("stone_axe", "Stone axe", ItemType.AXE, SpriteLoader.SPRITES.STONE_AXE, ToolVariant.STONE, 3, 132, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
@ItemRegistry("stone")
|
||||
public class StoneItem extends Item {
|
||||
public StoneItem() {
|
||||
super("stone", "Stone", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_STONE);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
@ItemRegistry("stone_pickaxe")
|
||||
public class StonePickaxe extends Item {
|
||||
public StonePickaxe() {
|
||||
super("stone_pickaxe", "Stone pickaxe", ItemType.PICKAXE, SpriteLoader.SPRITES.STONE_PICKAXE, ToolVariant.STONE, 12.5, 132, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
@ItemRegistry("stone_shovel")
|
||||
public class StoneShovel extends Item {
|
||||
public StoneShovel() {
|
||||
super("stone_shovel", "Stone shovel", ItemType.SHOVEL, SpriteLoader.SPRITES.STONE_SHOVEL, ToolVariant.STONE, 0.5, 132, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
@ItemRegistry("wooden_axe")
|
||||
public class WoodenAxe extends Item {
|
||||
public WoodenAxe() {
|
||||
super("wooden_axe", "Wooden axe", ItemType.AXE, SpriteLoader.SPRITES.WOODEN_AXE, ToolVariant.WOODEN, 2, 59, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
@ItemRegistry("wooden_pickaxe")
|
||||
public class WoodenPickaxe extends Item {
|
||||
public WoodenPickaxe() {
|
||||
super("wooden_pickaxe", "Wooden pickaxe", ItemType.PICKAXE, SpriteLoader.SPRITES.WOODEN_PICKAXE, ToolVariant.WOODEN, 12, 59, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.ItemRegistry;
|
||||
import cz.jzitnik.game.entities.items.Item;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
@ItemRegistry("wooden_shovel")
|
||||
public class WoodenShovel extends Item {
|
||||
public WoodenShovel() {
|
||||
super("wooden_shovel", "Wooden shovel", ItemType.SHOVEL, SpriteLoader.SPRITES.WOODEN_SHOVEL, ToolVariant.WOODEN, 0.3, 59, false);
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package cz.jzitnik.game.entities.items.registry.mobs;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.EntityRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.mobs.services.pig.PigData;
|
||||
|
||||
// Yes, pig is a block. Cry about it.
|
||||
@EntityRegistry("pig")
|
||||
public class Pig extends Block {
|
||||
public Pig () {
|
||||
super("pig", SpriteLoader.SPRITES.PIG);
|
||||
setMob(true);
|
||||
setGhost(true);
|
||||
setSpriteState(cz.jzitnik.game.sprites.Pig.PigState.RIGHT);
|
||||
setMineable(false);
|
||||
setData(new PigData());
|
||||
setHp(10);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package cz.jzitnik.game.entities.items.registry.mobs;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.EntityRegistry;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.mobs.services.sheep.SheepData;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import static cz.jzitnik.game.sprites.Sheep.SheepState.*;
|
||||
|
||||
|
||||
@EntityRegistry("sheep")
|
||||
public class Sheep extends Block {
|
||||
private cz.jzitnik.game.sprites.Sheep.SheepState getSheep() {
|
||||
Random random = new Random();
|
||||
int num = random.nextInt(100);
|
||||
|
||||
if (num < 1) {
|
||||
return PINK_RIGHT;
|
||||
}
|
||||
|
||||
if (num < 4) {
|
||||
return BROWN_RIGHT;
|
||||
}
|
||||
|
||||
if (num < 15) {
|
||||
int num1 = random.nextInt(3);
|
||||
return switch (num1) {
|
||||
case 0 -> LIGHT_GRAY_RIGHT;
|
||||
case 1 -> GRAY_RIGHT;
|
||||
case 2 -> BLACK_RIGHT;
|
||||
default -> throw new IllegalStateException("Unexpected value: " + num1);
|
||||
};
|
||||
}
|
||||
|
||||
return WHITE_RIGHT;
|
||||
}
|
||||
|
||||
public Sheep() {
|
||||
super("sheep", SpriteLoader.SPRITES.SHEEP);
|
||||
setMob(true);
|
||||
setGhost(true);
|
||||
setSpriteState(getSheep());
|
||||
setMineable(false);
|
||||
setData(new SheepData());
|
||||
setHp(8);
|
||||
}
|
||||
}
|
@ -66,16 +66,16 @@ public class Generation {
|
||||
for (int i = 0; i < 512; i++) {
|
||||
int hillHeight = terrainHeight[i];
|
||||
|
||||
world[hillHeight][i].add(ItemBlockSupplier.Blocks.grass());
|
||||
world[hillHeight][i].add(ItemBlockSupplier.getBlock("grass"));
|
||||
|
||||
for (int j = 1; j <= 4; j++) {
|
||||
if (hillHeight + j < 256) {
|
||||
world[hillHeight + j][i].add(ItemBlockSupplier.Blocks.dirt());
|
||||
world[hillHeight + j][i].add(ItemBlockSupplier.getBlock("dirt"));
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = hillHeight + 5; j < 250; j++) {
|
||||
world[j][i].add(ItemBlockSupplier.Blocks.stone());
|
||||
world[j][i].add(ItemBlockSupplier.getBlock("stone"));
|
||||
}
|
||||
|
||||
world[255][i].add(new Block("bedrock", SpriteLoader.SPRITES.BEDROCK));
|
||||
@ -97,7 +97,7 @@ public class Generation {
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (treeBase - j >= 0) {
|
||||
world[treeBase - j - 1][i].add(ItemBlockSupplier.Blocks.oakLog());
|
||||
world[treeBase - j - 1][i].add(ItemBlockSupplier.getBlock("oak_log"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,8 +3,8 @@ package cz.jzitnik.game.handlers.place.handlers;
|
||||
import cz.jzitnik.game.annotations.PlaceHandler;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.handlers.place.CustomPlaceHandler;
|
||||
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
|
||||
import cz.jzitnik.game.handlers.place.CustomPlaceHandler;
|
||||
import cz.jzitnik.game.sprites.OakDoor;
|
||||
|
||||
@PlaceHandler("oak_door")
|
||||
@ -24,7 +24,7 @@ public class DoorPlaceHandler implements CustomPlaceHandler {
|
||||
block.setSpriteState(OakDoor.OakDoorState.BOTTOMCLOSED);
|
||||
blocks.add(block);
|
||||
|
||||
Block block2 = ItemBlockSupplier.Blocks.oakDoor();
|
||||
Block block2 = ItemBlockSupplier.getBlock("oak_door");
|
||||
block2.setSpriteState(OakDoor.OakDoorState.TOPCLOSED);
|
||||
blocksTop.add(block2);
|
||||
|
||||
|
@ -119,13 +119,12 @@ public class PigLogic implements EntityLogicInterface, EntitySpawnInterface, Ent
|
||||
if (countPrasata(lstartX, lendX, lstartY, lendY, game) < 3 && random.nextInt(100) < 2) {
|
||||
var spawnLocations = pigCanSpawn(lstartX, lendX, playerY, game);
|
||||
if (!spawnLocations.isEmpty()) {
|
||||
System.out.println(spawnLocations.size());
|
||||
for (int i = 0; i < Math.min(4, spawnLocations.size()); i++) {
|
||||
var randomLocation = getRandomEntry(spawnLocations);
|
||||
int x = randomLocation.getKey();
|
||||
int y = randomLocation.getValue();
|
||||
|
||||
world[y][x].add(ItemBlockSupplier.Mobs.pig());
|
||||
world[y][x].add(ItemBlockSupplier.getEntity("pig"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -139,13 +138,12 @@ public class PigLogic implements EntityLogicInterface, EntitySpawnInterface, Ent
|
||||
if (countPrasata(rstartX, rendX, rstartY, rendY, game) < 3 && random.nextInt(100) < 2) {
|
||||
var spawnLocations = pigCanSpawn(rstartX, rendX, playerY, game);
|
||||
if (!spawnLocations.isEmpty()) {
|
||||
System.out.println(spawnLocations.size());
|
||||
for (int i = 0; i < Math.min(random.nextInt(3) + 2, spawnLocations.size()); i++) {
|
||||
var randomLocation = getRandomEntry(spawnLocations);
|
||||
int x = randomLocation.getKey();
|
||||
int y = randomLocation.getValue();
|
||||
|
||||
world[y][x].add(ItemBlockSupplier.Mobs.pig());
|
||||
world[y][x].add(ItemBlockSupplier.getEntity("pig"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -201,7 +199,7 @@ public class PigLogic implements EntityLogicInterface, EntitySpawnInterface, Ent
|
||||
@Override
|
||||
public void killed(Game game, Block mob) {
|
||||
int amount = random.nextInt(2) + 1;
|
||||
InventoryItem inventoryItem = new InventoryItem(amount, ItemBlockSupplier.Items.mutton());
|
||||
InventoryItem inventoryItem = new InventoryItem(amount, ItemBlockSupplier.getItem("mutton"));
|
||||
game.getInventory().addItem(inventoryItem);
|
||||
}
|
||||
}
|
||||
|
@ -135,13 +135,12 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
|
||||
if (countSheep(lstartX, lendX, lstartY, lendY, game) < 3 && random.nextInt(100) < 2) {
|
||||
var spawnLocations = sheepCanSpawn(lstartX, lendX, playerY, game);
|
||||
if (!spawnLocations.isEmpty()) {
|
||||
System.out.println(spawnLocations.size());
|
||||
for (int i = 0; i < Math.min(4, spawnLocations.size()); i++) {
|
||||
var randomLocation = getRandomEntry(spawnLocations);
|
||||
int x = randomLocation.getKey();
|
||||
int y = randomLocation.getValue();
|
||||
|
||||
world[y][x].add(getSheep());
|
||||
world[y][x].add(ItemBlockSupplier.getEntity("sheep"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,13 +154,12 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
|
||||
if (countSheep(rstartX, rendX, rstartY, rendY, game) < 3 && random.nextInt(100) < 2) {
|
||||
var spawnLocations = sheepCanSpawn(rstartX, rendX, playerY, game);
|
||||
if (!spawnLocations.isEmpty()) {
|
||||
System.out.println(spawnLocations.size());
|
||||
for (int i = 0; i < Math.min(random.nextInt(3) + 2, spawnLocations.size()); i++) {
|
||||
var randomLocation = getRandomEntry(spawnLocations);
|
||||
int x = randomLocation.getKey();
|
||||
int y = randomLocation.getValue();
|
||||
|
||||
world[y][x].add(getSheep());
|
||||
world[y][x].add(ItemBlockSupplier.getEntity("sheep"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,30 +196,6 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
|
||||
return sheepAmount;
|
||||
}
|
||||
|
||||
private Block getSheep() {
|
||||
int num = random.nextInt(100);
|
||||
|
||||
if (num < 1) {
|
||||
return ItemBlockSupplier.Mobs.sheep(PINK_RIGHT);
|
||||
}
|
||||
|
||||
if (num < 4) {
|
||||
return ItemBlockSupplier.Mobs.sheep(BROWN_RIGHT);
|
||||
}
|
||||
|
||||
if (num < 15) {
|
||||
int num1 = random.nextInt(3);
|
||||
return switch (num1) {
|
||||
case 0 -> ItemBlockSupplier.Mobs.sheep(LIGHT_GRAY_RIGHT);
|
||||
case 1 -> ItemBlockSupplier.Mobs.sheep(GRAY_RIGHT);
|
||||
case 2 -> ItemBlockSupplier.Mobs.sheep(BLACK_RIGHT);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + num1);
|
||||
};
|
||||
}
|
||||
|
||||
return ItemBlockSupplier.Mobs.sheep(WHITE_RIGHT);
|
||||
}
|
||||
|
||||
public Sheep.SheepState setHurtAnimation(boolean hurt, Enum current) {
|
||||
if (hurt) {
|
||||
return switch (current) {
|
||||
@ -272,7 +246,7 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
|
||||
@Override
|
||||
public void killed(Game game, Block mob) {
|
||||
int amount = random.nextInt(3) + 1;
|
||||
InventoryItem inventoryItem = new InventoryItem(amount, ItemBlockSupplier.Items.porkchop());
|
||||
InventoryItem inventoryItem = new InventoryItem(amount, ItemBlockSupplier.getItem("mutton"));
|
||||
game.getInventory().addItem(inventoryItem);
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@ import java.util.function.Supplier;
|
||||
public class Smelting {
|
||||
public static final HashMap<String, Supplier<Item>> smeltingList = new HashMap<>();
|
||||
static {
|
||||
smeltingList.put("cobblestone", ItemBlockSupplier.Items::stone);
|
||||
smeltingList.put("porkchop", ItemBlockSupplier.Items::cookedPorkchop);
|
||||
smeltingList.put("mutton", ItemBlockSupplier.Items::cookedMutton);
|
||||
smeltingList.put("cobblestone", () -> ItemBlockSupplier.getItem("stone"));
|
||||
smeltingList.put("porkchop", () -> ItemBlockSupplier.getItem("cooked_porkchop"));
|
||||
smeltingList.put("mutton", () -> ItemBlockSupplier.getItem("cooked_mutton"));
|
||||
}
|
||||
|
||||
public static final HashMap<String, Double> fuelList = new HashMap<>();
|
||||
|
Loading…
x
Reference in New Issue
Block a user