refactor: ItemBlockSupplier

This commit is contained in:
Jakub Žitník 2025-03-02 00:23:48 +01:00
parent f80c6a9815
commit 1be9f75ae7
Signed by: jzitnik
GPG Key ID: C577A802A6AF4EF3
43 changed files with 640 additions and 284 deletions

View File

@ -9,4 +9,5 @@ import java.lang.annotation.ElementType;
@Target(ElementType.TYPE) @Target(ElementType.TYPE)
public @interface BlockRegistry { public @interface BlockRegistry {
String value(); String value();
String drops() default "";
} }

View File

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

View File

@ -14,92 +14,92 @@ public class CraftingRecipeList {
{"oak_log", null, null}, {"oak_log", null, null},
{null, null, null}, {null, null, null},
{null, null, null} {null, null, null}
}, () -> new InventoryItem(4, ItemBlockSupplier.Items.oakPlanks()))); }, () -> new InventoryItem(4, ItemBlockSupplier.getItem("oak_planks"))));
// Crafting table // Crafting table
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"oak_planks", "oak_planks", null}, {"oak_planks", "oak_planks", null},
{"oak_planks", "oak_planks", null}, {"oak_planks", "oak_planks", null},
{null, null, null} {null, null, null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.craftingTable()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("crafting_table"))));
// Stick // Stick
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"oak_planks", null, null}, {"oak_planks", null, null},
{"oak_planks", null, null}, {"oak_planks", null, null},
{null, null, null} {null, null, null}
}, () -> new InventoryItem(4, ItemBlockSupplier.Items.stick()))); }, () -> new InventoryItem(4, ItemBlockSupplier.getItem("stick"))));
// Wooden pickaxe // Wooden pickaxe
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"oak_planks", "oak_planks", "oak_planks"}, {"oak_planks", "oak_planks", "oak_planks"},
{null, "stick", null}, {null, "stick", null},
{null, "stick", null} {null, "stick", null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.woodenPickaxe()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_pickaxe"))));
// Wooden axe // Wooden axe
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"oak_planks", "oak_planks", null}, {"oak_planks", "oak_planks", null},
{"oak_planks", "stick", null}, {"oak_planks", "stick", null},
{null, "stick", null} {null, "stick", null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.woodenAxe()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{null, "oak_planks", "oak_planks"}, {null, "oak_planks", "oak_planks"},
{null, "stick", "oak_planks"}, {null, "stick", "oak_planks"},
{null, "stick", null} {null, "stick", null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.woodenAxe()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
// Stone pickaxe // Stone pickaxe
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"cobblestone", "cobblestone", "cobblestone"}, {"cobblestone", "cobblestone", "cobblestone"},
{null, "stick", null}, {null, "stick", null},
{null, "stick", null} {null, "stick", null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.stonePickaxe()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
// Stone axe // Stone axe
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"cobblestone", "cobblestone", null}, {"cobblestone", "cobblestone", null},
{"cobblestone", "stick", null}, {"cobblestone", "stick", null},
{null, "stick", null} {null, "stick", null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.stoneAxe()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{null, "cobblestone", "cobblestone"}, {null, "cobblestone", "cobblestone"},
{null, "stick", "cobblestone"}, {null, "stick", "cobblestone"},
{null, "stick", null} {null, "stick", null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.stoneAxe()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_axe"))));
// Chest // Chest
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"oak_planks", "oak_planks", "oak_planks"}, {"oak_planks", "oak_planks", "oak_planks"},
{"oak_planks", null, "oak_planks"}, {"oak_planks", null, "oak_planks"},
{"oak_planks", "oak_planks", "oak_planks"} {"oak_planks", "oak_planks", "oak_planks"}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.chest()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("chest"))));
// Wooden shovel // Wooden shovel
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{null, "oak_planks", null}, {null, "oak_planks", null},
{null, "stick", null}, {null, "stick", null},
{null, "stick", null} {null, "stick", null}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.woodenShovel()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("wooden_shovel"))));
// Stone shovel // Stone shovel
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{null, "cobblestone", null}, {null, "cobblestone", null},
{null, "stick", null}, {null, "stick", 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[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"cobblestone", "cobblestone", "cobblestone"}, {"cobblestone", "cobblestone", "cobblestone"},
{"cobblestone", null, "cobblestone"}, {"cobblestone", null, "cobblestone"},
{"cobblestone", "cobblestone", "cobblestone"} {"cobblestone", "cobblestone", "cobblestone"}
}, () -> new InventoryItem(1, ItemBlockSupplier.Items.furnace()))); }, () -> new InventoryItem(1, ItemBlockSupplier.getItem("furnace"))));
recipes.add(new CraftingRecipe(new String[][]{ recipes.add(new CraftingRecipe(new String[][]{
{"oak_planks", "oak_planks", null}, {"oak_planks", "oak_planks", null},
{"oak_planks", "oak_planks", null}, {"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) { public static Optional<CraftingRecipe> getRecipe(String[] r) {

View File

@ -4,6 +4,7 @@ import cz.jzitnik.game.entities.Block;
import cz.jzitnik.game.SpriteLoader; import cz.jzitnik.game.SpriteLoader;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import lombok.Setter;
import java.util.Optional; import java.util.Optional;
@ -21,6 +22,7 @@ public class Item {
private int stackAmount = 64; private int stackAmount = 64;
private int addHunger = 0; private int addHunger = 0;
private int dealDamage = 1; private int dealDamage = 1;
@Setter
private Optional<Block> block = Optional.empty(); 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) { public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, ToolVariant toolVariant, double miningDecrease, int durability, boolean stackable) {

View File

@ -1,191 +1,124 @@
package cz.jzitnik.game.entities.items; package cz.jzitnik.game.entities.items;
import cz.jzitnik.game.SpriteLoader; import cz.jzitnik.game.annotations.BlockRegistry;
import cz.jzitnik.game.blocks.OakDoorData; import cz.jzitnik.game.annotations.EntityRegistry;
import cz.jzitnik.game.annotations.ItemRegistry;
import cz.jzitnik.game.entities.Block; import cz.jzitnik.game.entities.Block;
import cz.jzitnik.game.blocks.Chest; import org.reflections.Reflections;
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 java.util.ArrayList; import java.lang.reflect.Constructor;
import java.util.Arrays; import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Optional;
import java.util.Set;
import java.util.List; import java.util.List;
public class ItemBlockSupplier { public class ItemBlockSupplier {
// This is necessary to not get infinite recursion private static final HashMap<String, Constructor<Block>> registeredBlocks = new HashMap<>();
private static class Helper { private static final HashMap<String, Constructor<Item>> registeredItems = new HashMap<>();
public static Item dirt(Block ref) { private static final HashMap<String, Constructor<Block>> registeredEntities = new HashMap<>();
return new Item("dirt", "Dirt block", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_DIRT, ref); private static final HashMap<String, String> dropsList = new HashMap<>();
}
public static Item cobblestone(Block ref) { static {
return new Item("cobblestone", "Cobblestone", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_COBBLESTONE, ref); registerItems();
} registerBlocks();
public static Item stone(Block ref) { registerEntities();
return new Item("stone", "Stone", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_STONE, ref); }
}
public static Item oakLog(Block ref) { private static void registerBlocks() {
return new Item("oak_log", "Oak log", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_LOG, ref); Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
} Set<Class<?>> blockClasses = reflections.getTypesAnnotatedWith(BlockRegistry.class);
public static Item oakPlanks(Block ref) {
return new Item("oak_planks", "Oak planks", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_PLANKS, ref); for (Class<?> clazz : blockClasses) {
} try {
public static Item craftingTable(Block ref) { Constructor<Block> blockInstance = (Constructor<Block>) clazz.getDeclaredConstructor();
return new Item("crafting_table", "Crafting table", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_CRAFTING_TABLE, ref); BlockRegistry annotation = clazz.getAnnotation(BlockRegistry.class);
} registeredBlocks.put(annotation.value(), blockInstance);
public static Item chest(Block ref) {
return new Item("chest", "Chest", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_CHEST, ref); if (registeredItems.containsKey(annotation.value())) {
} dropsList.put(annotation.value(), annotation.value());
public static Item furnace(Block ref) { } else {
return new Item("furnace", "Furnace", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_FURNACE, ref); dropsList.put(annotation.value(), annotation.drops());
} }
public static Item oakDoor(Block ref) { } catch (Exception e) {
return new Item("oak_door", "Oak door", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_OAK_DOOR, ref); e.printStackTrace();
}
} }
} }
public static class Blocks { private static void registerEntities() {
public static Block dirt() { Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
var block = new Block("dirt", SpriteLoader.SPRITES.DIRT, 1, ItemType.SHOVEL, new ArrayList<>()); Set<Class<?>> entityClasses = reflections.getTypesAnnotatedWith(EntityRegistry.class);
block.setDrops(List.of(Helper.dirt(block)));
return block; for (Class<?> clazz : entityClasses) {
} try {
public static Block grass() { Constructor<Block> entityInstance = (Constructor<Block>) clazz.getDeclaredConstructor();
var block = new Block("grass", SpriteLoader.SPRITES.GRASS, 1, ItemType.SHOVEL, new ArrayList<>()); EntityRegistry annotation = clazz.getAnnotation(EntityRegistry.class);
block.setDrops(List.of(Items.dirt())); registeredEntities.put(annotation.value(), entityInstance);
return block; } catch (Exception e) {
} e.printStackTrace();
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 private static void registerItems() {
public static class Items { Reflections reflections = new Reflections("cz.jzitnik.game.entities.items.registry");
public static Item dirt() { Set<Class<?>> itemClasses = reflections.getTypesAnnotatedWith(ItemRegistry.class);
return Helper.dirt(Blocks.dirt());
} for (Class<?> clazz : itemClasses) {
public static Item oakPlanks() { try {
return Helper.oakPlanks(Blocks.oakPlanks()); Constructor<Item> itemInstance = (Constructor<Item>) clazz.getDeclaredConstructor();
} ItemRegistry annotation = clazz.getAnnotation(ItemRegistry.class);
public static Item stick() { registeredItems.put(annotation.value(), itemInstance);
return new Item("stick", "Stick", ItemType.USELESS_ITEM, SpriteLoader.SPRITES.ITEM_STICK); } catch (Exception e) {
} e.printStackTrace();
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 getBlock(String key) {
public static Block pig() { try {
// Yes, pig is a block. Cry about it. Block block = registeredBlocks.get(key).newInstance();
var block = new Block("pig", SpriteLoader.SPRITES.PIG); block.setDrops(List.of(getItem(dropsList.get(key), block)));
block.setMob(true);
block.setGhost(true);
block.setSpriteState(Pig.PigState.RIGHT);
block.setMineable(false);
block.setData(new PigData());
block.setHp(10);
return 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); public static Item getItem(String key) {
block.setGhost(true); try {
block.setSpriteState(sheepState); Item item = registeredItems.get(key).newInstance();
block.setMineable(false); if (registeredBlocks.containsKey(key)) {
block.setData(new SheepData()); item.setBlock(Optional.of(registeredBlocks.get(key).newInstance()));
block.setHp(8); }
return block;
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);
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -66,16 +66,16 @@ public class Generation {
for (int i = 0; i < 512; i++) { for (int i = 0; i < 512; i++) {
int hillHeight = terrainHeight[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++) { for (int j = 1; j <= 4; j++) {
if (hillHeight + j < 256) { 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++) { 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)); world[255][i].add(new Block("bedrock", SpriteLoader.SPRITES.BEDROCK));
@ -97,7 +97,7 @@ public class Generation {
for (int j = 0; j < 3; j++) { for (int j = 0; j < 3; j++) {
if (treeBase - j >= 0) { if (treeBase - j >= 0) {
world[treeBase - j - 1][i].add(ItemBlockSupplier.Blocks.oakLog()); world[treeBase - j - 1][i].add(ItemBlockSupplier.getBlock("oak_log"));
} }
} }

View File

@ -3,8 +3,8 @@ package cz.jzitnik.game.handlers.place.handlers;
import cz.jzitnik.game.annotations.PlaceHandler; import cz.jzitnik.game.annotations.PlaceHandler;
import cz.jzitnik.game.entities.Block; import cz.jzitnik.game.entities.Block;
import cz.jzitnik.game.Game; import cz.jzitnik.game.Game;
import cz.jzitnik.game.handlers.place.CustomPlaceHandler;
import cz.jzitnik.game.entities.items.ItemBlockSupplier; import cz.jzitnik.game.entities.items.ItemBlockSupplier;
import cz.jzitnik.game.handlers.place.CustomPlaceHandler;
import cz.jzitnik.game.sprites.OakDoor; import cz.jzitnik.game.sprites.OakDoor;
@PlaceHandler("oak_door") @PlaceHandler("oak_door")
@ -24,7 +24,7 @@ public class DoorPlaceHandler implements CustomPlaceHandler {
block.setSpriteState(OakDoor.OakDoorState.BOTTOMCLOSED); block.setSpriteState(OakDoor.OakDoorState.BOTTOMCLOSED);
blocks.add(block); blocks.add(block);
Block block2 = ItemBlockSupplier.Blocks.oakDoor(); Block block2 = ItemBlockSupplier.getBlock("oak_door");
block2.setSpriteState(OakDoor.OakDoorState.TOPCLOSED); block2.setSpriteState(OakDoor.OakDoorState.TOPCLOSED);
blocksTop.add(block2); blocksTop.add(block2);

View File

@ -119,13 +119,12 @@ public class PigLogic implements EntityLogicInterface, EntitySpawnInterface, Ent
if (countPrasata(lstartX, lendX, lstartY, lendY, game) < 3 && random.nextInt(100) < 2) { if (countPrasata(lstartX, lendX, lstartY, lendY, game) < 3 && random.nextInt(100) < 2) {
var spawnLocations = pigCanSpawn(lstartX, lendX, playerY, game); var spawnLocations = pigCanSpawn(lstartX, lendX, playerY, game);
if (!spawnLocations.isEmpty()) { if (!spawnLocations.isEmpty()) {
System.out.println(spawnLocations.size());
for (int i = 0; i < Math.min(4, spawnLocations.size()); i++) { for (int i = 0; i < Math.min(4, spawnLocations.size()); i++) {
var randomLocation = getRandomEntry(spawnLocations); var randomLocation = getRandomEntry(spawnLocations);
int x = randomLocation.getKey(); int x = randomLocation.getKey();
int y = randomLocation.getValue(); 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) { if (countPrasata(rstartX, rendX, rstartY, rendY, game) < 3 && random.nextInt(100) < 2) {
var spawnLocations = pigCanSpawn(rstartX, rendX, playerY, game); var spawnLocations = pigCanSpawn(rstartX, rendX, playerY, game);
if (!spawnLocations.isEmpty()) { if (!spawnLocations.isEmpty()) {
System.out.println(spawnLocations.size());
for (int i = 0; i < Math.min(random.nextInt(3) + 2, spawnLocations.size()); i++) { for (int i = 0; i < Math.min(random.nextInt(3) + 2, spawnLocations.size()); i++) {
var randomLocation = getRandomEntry(spawnLocations); var randomLocation = getRandomEntry(spawnLocations);
int x = randomLocation.getKey(); int x = randomLocation.getKey();
int y = randomLocation.getValue(); 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 @Override
public void killed(Game game, Block mob) { public void killed(Game game, Block mob) {
int amount = random.nextInt(2) + 1; 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); game.getInventory().addItem(inventoryItem);
} }
} }

View File

@ -135,13 +135,12 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
if (countSheep(lstartX, lendX, lstartY, lendY, game) < 3 && random.nextInt(100) < 2) { if (countSheep(lstartX, lendX, lstartY, lendY, game) < 3 && random.nextInt(100) < 2) {
var spawnLocations = sheepCanSpawn(lstartX, lendX, playerY, game); var spawnLocations = sheepCanSpawn(lstartX, lendX, playerY, game);
if (!spawnLocations.isEmpty()) { if (!spawnLocations.isEmpty()) {
System.out.println(spawnLocations.size());
for (int i = 0; i < Math.min(4, spawnLocations.size()); i++) { for (int i = 0; i < Math.min(4, spawnLocations.size()); i++) {
var randomLocation = getRandomEntry(spawnLocations); var randomLocation = getRandomEntry(spawnLocations);
int x = randomLocation.getKey(); int x = randomLocation.getKey();
int y = randomLocation.getValue(); 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) { if (countSheep(rstartX, rendX, rstartY, rendY, game) < 3 && random.nextInt(100) < 2) {
var spawnLocations = sheepCanSpawn(rstartX, rendX, playerY, game); var spawnLocations = sheepCanSpawn(rstartX, rendX, playerY, game);
if (!spawnLocations.isEmpty()) { if (!spawnLocations.isEmpty()) {
System.out.println(spawnLocations.size());
for (int i = 0; i < Math.min(random.nextInt(3) + 2, spawnLocations.size()); i++) { for (int i = 0; i < Math.min(random.nextInt(3) + 2, spawnLocations.size()); i++) {
var randomLocation = getRandomEntry(spawnLocations); var randomLocation = getRandomEntry(spawnLocations);
int x = randomLocation.getKey(); int x = randomLocation.getKey();
int y = randomLocation.getValue(); 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; 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) { public Sheep.SheepState setHurtAnimation(boolean hurt, Enum current) {
if (hurt) { if (hurt) {
return switch (current) { return switch (current) {
@ -272,7 +246,7 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
@Override @Override
public void killed(Game game, Block mob) { public void killed(Game game, Block mob) {
int amount = random.nextInt(3) + 1; 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); game.getInventory().addItem(inventoryItem);
} }
} }

View File

@ -10,9 +10,9 @@ import java.util.function.Supplier;
public class Smelting { public class Smelting {
public static final HashMap<String, Supplier<Item>> smeltingList = new HashMap<>(); public static final HashMap<String, Supplier<Item>> smeltingList = new HashMap<>();
static { static {
smeltingList.put("cobblestone", ItemBlockSupplier.Items::stone); smeltingList.put("cobblestone", () -> ItemBlockSupplier.getItem("stone"));
smeltingList.put("porkchop", ItemBlockSupplier.Items::cookedPorkchop); smeltingList.put("porkchop", () -> ItemBlockSupplier.getItem("cooked_porkchop"));
smeltingList.put("mutton", ItemBlockSupplier.Items::cookedMutton); smeltingList.put("mutton", () -> ItemBlockSupplier.getItem("cooked_mutton"));
} }
public static final HashMap<String, Double> fuelList = new HashMap<>(); public static final HashMap<String, Double> fuelList = new HashMap<>();