feat: Added gravel
This commit is contained in:
@ -28,7 +28,8 @@ public class SpriteLoader {
|
||||
OBSIDIAN,
|
||||
SAND,
|
||||
HAYBALE,
|
||||
|
||||
GRAVEL,
|
||||
|
||||
// Flowers etc
|
||||
GRASS_BUSH,
|
||||
POPPY,
|
||||
@ -50,7 +51,7 @@ public class SpriteLoader {
|
||||
IRON_ORE,
|
||||
GOLD_ORE,
|
||||
DIAMOND_ORE,
|
||||
|
||||
|
||||
COAL_BLOCK,
|
||||
IRON_BLOCK,
|
||||
GOLD_BLOCK,
|
||||
@ -100,6 +101,7 @@ public class SpriteLoader {
|
||||
ITEM_OBSIDIAN,
|
||||
ITEM_SAND,
|
||||
ITEM_HAYBALE,
|
||||
ITEM_GRAVEL,
|
||||
|
||||
// Tall Flowers
|
||||
ITEM_LILAC,
|
||||
@ -119,7 +121,7 @@ public class SpriteLoader {
|
||||
ITEM_IRON_INGOT,
|
||||
ITEM_GOLD_INGOT,
|
||||
DIAMOND,
|
||||
|
||||
|
||||
// Work Items
|
||||
ITEM_CRAFTING_TABLE,
|
||||
ITEM_CHEST,
|
||||
@ -203,6 +205,7 @@ public class SpriteLoader {
|
||||
SPRITES_MAP.put(SPRITES.OBSIDIAN, new SimpleSprite("obsidian.ans"));
|
||||
SPRITES_MAP.put(SPRITES.SAND, new SimpleSprite("sand.ans"));
|
||||
SPRITES_MAP.put(SPRITES.HAYBALE, new SimpleSprite("haybale.ans"));
|
||||
SPRITES_MAP.put(SPRITES.GRAVEL, new SimpleSprite("gravel.ans"));
|
||||
|
||||
// Ores
|
||||
SPRITES_MAP.put(SPRITES.COAL_ORE, new SimpleSprite("coal_ore.ans"));
|
||||
@ -283,6 +286,7 @@ public class SpriteLoader {
|
||||
SPRITES_MAP.put(SPRITES.ITEM_OBSIDIAN, new SimpleSprite("items/obsidian.ans"));
|
||||
SPRITES_MAP.put(SPRITES.ITEM_SAND, new SimpleSprite("items/sand.ans"));
|
||||
SPRITES_MAP.put(SPRITES.ITEM_HAYBALE, new SimpleSprite("items/haybale.ans"));
|
||||
SPRITES_MAP.put(SPRITES.ITEM_GRAVEL, new SimpleSprite("items/gravel.ans"));
|
||||
|
||||
// Tall flowers
|
||||
SPRITES_MAP.put(SPRITES.ITEM_LILAC, new SimpleSprite("items/lilac.ans"));
|
||||
|
@ -0,0 +1,17 @@
|
||||
package cz.jzitnik.game.entities.items.registry.blocks.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.FallingBlock;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@FallingBlock
|
||||
@BlockRegistry("gravel")
|
||||
public class GravelBlock extends Block {
|
||||
public GravelBlock() {
|
||||
super("gravel", SpriteLoader.SPRITES.GRAVEL, 1, ItemType.SHOVEL, new ArrayList<>());
|
||||
}
|
||||
}
|
@ -2,11 +2,13 @@ package cz.jzitnik.game.entities.items.registry.blocks.blocks;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.Flamable;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Flamable
|
||||
@BlockRegistry("oak_leaves")
|
||||
public class OakLeavesBlock extends Block {
|
||||
public OakLeavesBlock() {
|
||||
|
@ -2,12 +2,14 @@ package cz.jzitnik.game.entities.items.registry.blocks.ores.coal;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.Flamable;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.entities.items.ToolVariant;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Flamable
|
||||
@BlockRegistry("coal_block")
|
||||
public class CoalBlock extends Block {
|
||||
public CoalBlock() {
|
||||
|
@ -2,12 +2,14 @@ package cz.jzitnik.game.entities.items.registry.blocks.work;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.Flamable;
|
||||
import cz.jzitnik.game.blocks.Chest;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Flamable
|
||||
@BlockRegistry("chest")
|
||||
public class ChestBlock extends Block {
|
||||
public ChestBlock() {
|
||||
|
@ -2,11 +2,13 @@ package cz.jzitnik.game.entities.items.registry.blocks.work;
|
||||
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
import cz.jzitnik.game.annotations.BlockRegistry;
|
||||
import cz.jzitnik.game.annotations.Flamable;
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.ItemType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@Flamable
|
||||
@BlockRegistry("crafting_table")
|
||||
public class CraftingTableBlock extends Block {
|
||||
public CraftingTableBlock() {
|
||||
|
@ -0,0 +1,13 @@
|
||||
package cz.jzitnik.game.entities.items.registry.items.blocks;
|
||||
|
||||
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("gravel")
|
||||
public class GravelItem extends Item {
|
||||
public GravelItem() {
|
||||
super("gravel", "Gravel", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_GRAVEL);
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package cz.jzitnik.game.generation;
|
||||
|
||||
import cz.jzitnik.game.entities.Block;
|
||||
import cz.jzitnik.game.entities.items.InventoryItem;
|
||||
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
|
||||
import cz.jzitnik.game.Game;
|
||||
import cz.jzitnik.game.SpriteLoader;
|
||||
@ -34,8 +35,7 @@ public class Generation {
|
||||
world[terrainHeight[256] - 1][256].add(steveBlock2);
|
||||
world[terrainHeight[256] - 2][256].add(steveBlock);
|
||||
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("flint"));
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("iron_ingot"));
|
||||
game.getInventory().addItem(new InventoryItem(64, ItemBlockSupplier.getItem("gravel")));
|
||||
}
|
||||
|
||||
private static void initializeWorld(List<Block>[][] world) {
|
||||
|
@ -0,0 +1,42 @@
|
||||
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.entities.items.ItemBlockSupplier;
|
||||
import cz.jzitnik.game.handlers.place.CustomPlaceHandler;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@PlaceHandler("gravel")
|
||||
public class GravelMiningHandler implements CustomPlaceHandler {
|
||||
@Override
|
||||
public boolean place(Game game, int x, int y) {
|
||||
var blocks = game.getWorld()[y][x];
|
||||
var inventory = game.getInventory();
|
||||
|
||||
blocks.add(inventory.getItemInHand().get().getBlock().get());
|
||||
blocks.removeAll(blocks.stream().filter(Block::isFlowing).toList());
|
||||
|
||||
inventory.decreaseItemInHand();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mine(Game game, int x, int y) {
|
||||
var blocks = game.getWorld()[y][x];
|
||||
|
||||
blocks.removeAll(blocks.stream().filter(i -> !i.getBlockId().equals("air") && !i.isMob()).toList());
|
||||
|
||||
Random random = new Random();
|
||||
int percentage = random.nextInt(100);
|
||||
|
||||
if (percentage < 10) {
|
||||
game.getInventory().addItem(ItemBlockSupplier.getItem("flint"));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
@ -8,10 +8,10 @@ import cz.jzitnik.game.entities.items.ItemType;
|
||||
import cz.jzitnik.game.handlers.tooluse.ToolUseHandler;
|
||||
|
||||
@ToolUse(ItemType.FLINT_AND_STEEL)
|
||||
public class FlintAndSteelUse implements ToolUseHandler{
|
||||
public class FlintAndSteelUse implements ToolUseHandler {
|
||||
|
||||
@Override
|
||||
public void handle(Game game, int x, int y) {
|
||||
@Override
|
||||
public void handle(Game game, int x, int y) {
|
||||
var blocks = game.getWorld()[y][x];
|
||||
|
||||
for (Block block : blocks) {
|
||||
@ -19,5 +19,5 @@ public class FlintAndSteelUse implements ToolUseHandler{
|
||||
block.setOnFire(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,11 +28,7 @@ public class FallingLogic implements CustomLogicInterface {
|
||||
var blocks = world[y][x];
|
||||
|
||||
if (world[y+1][x].stream().anyMatch(block -> block.getClass().isAnnotationPresent(BreaksFalling.class))) {
|
||||
var fallingBlocks = blocks.stream().filter(block -> block.getClass().isAnnotationPresent(FallingBlock.class)).toList();
|
||||
for (Block block : fallingBlocks) {
|
||||
blocks.remove(block);
|
||||
game.getInventory().addItem(block.getDrops());
|
||||
}
|
||||
blocks.removeIf(block -> block.getClass().isAnnotationPresent(FallingBlock.class));
|
||||
}
|
||||
|
||||
if (!world[y+1][x].stream().allMatch(block -> block.isGhost())) {
|
||||
|
Reference in New Issue
Block a user