feat: Colored wool
This commit is contained in:
@ -42,7 +42,12 @@ public class Main {
|
||||
inputHandlerThread.start();
|
||||
|
||||
while (isRunning[0]) {
|
||||
entityLogicProvider.update(game);
|
||||
try {
|
||||
entityLogicProvider.update(game);
|
||||
} catch (Exception ignored) {
|
||||
// Yeah, yeah I know. Deal with it
|
||||
}
|
||||
|
||||
if (game.getWindow() == Window.WORLD) {
|
||||
screenRenderer.render(game);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class SpriteLoader {
|
||||
BREAKING,
|
||||
COBBLESTONE,
|
||||
FURNACE,
|
||||
WOOL,
|
||||
|
||||
CHEST,
|
||||
CRAFTING_TABLE,
|
||||
@ -44,6 +45,7 @@ public class SpriteLoader {
|
||||
ITEM_STONE,
|
||||
ITEM_FURNACE,
|
||||
ITEM_OAK_DOOR,
|
||||
ITEM_WOOL,
|
||||
|
||||
ITEM_CRAFTING_TABLE,
|
||||
ITEM_CHEST,
|
||||
@ -80,6 +82,7 @@ public class SpriteLoader {
|
||||
SPRITES_MAP.put(SPRITES.FURNACE, new Furnace());
|
||||
SPRITES_MAP.put(SPRITES.COAL_ORE, new SimpleSprite("coal_ore.ans"));
|
||||
SPRITES_MAP.put(SPRITES.OAK_DOOR, new OakDoor());
|
||||
SPRITES_MAP.put(SPRITES.WOOL, new Wool());
|
||||
|
||||
SPRITES_MAP.put(SPRITES.WOODEN_PICKAXE, new SimpleSprite("items/wooden_pickaxe.ans"));
|
||||
SPRITES_MAP.put(SPRITES.STONE_PICKAXE, new SimpleSprite("items/stone_pickaxe.ans"));
|
||||
@ -99,6 +102,7 @@ public class SpriteLoader {
|
||||
SPRITES_MAP.put(SPRITES.ITEM_OAK_DOOR, new SimpleSprite("oak_door/items/oak_door.ans"));
|
||||
SPRITES_MAP.put(SPRITES.ITEM_PORKCHOP, new SimpleSprite("items/porkchop.ans"));
|
||||
SPRITES_MAP.put(SPRITES.ITEM_COOKED_PORKCHOP, new SimpleSprite("items/cooked_porkchop.ans"));
|
||||
SPRITES_MAP.put(SPRITES.ITEM_WOOL, new WoolItem());
|
||||
|
||||
SPRITES_MAP.put(SPRITES.ITEM_MUTTON, new SimpleSprite("items/mutton.ans"));
|
||||
SPRITES_MAP.put(SPRITES.ITEM_COOKED_MUTTON, new SimpleSprite("items/cooked_mutton.ans"));
|
||||
@ -108,7 +112,6 @@ public class SpriteLoader {
|
||||
|
||||
SPRITES_MAP.put(SPRITES.PIG, new Pig());
|
||||
SPRITES_MAP.put(SPRITES.SHEEP, new Sheep());
|
||||
|
||||
}
|
||||
|
||||
public static SpriteList<SPRITES> load() {
|
||||
|
@ -44,7 +44,9 @@ public class Furnace implements RightClickHandler {
|
||||
List<String> sprites = game.getInventory().getSprites(items, spriteList, inventory.getSelectedItemInv() - 50);
|
||||
|
||||
String[] outputSprite = outputItem == null ? null : SpriteCombiner.combineTwoSprites(
|
||||
spriteList.getSprite(outputItem.getItem().getFirst().getSprite()).getSprite(),
|
||||
outputItem.getItem().getFirst().getSpriteState().isPresent() ?
|
||||
spriteList.getSprite(outputItem.getItem().getFirst().getSprite()).getSprite(outputItem.getItem().getFirst().getSpriteState().get()) :
|
||||
spriteList.getSprite(outputItem.getItem().getFirst().getSprite()).getSprite() ,
|
||||
Numbers.getNumberSprite(outputItem.getAmount())
|
||||
).split("\n");
|
||||
|
||||
|
@ -40,6 +40,12 @@ public class Block {
|
||||
this.isMineable = isMineable;
|
||||
}
|
||||
|
||||
public Block(String blockId, SpriteLoader.SPRITES sprite, int hardness) {
|
||||
this.blockId = blockId;
|
||||
this.sprite = sprite;
|
||||
this.hardness = hardness;
|
||||
}
|
||||
|
||||
public Block(String blockId, SpriteLoader.SPRITES sprite, int hardness, ItemType tool, List<ToolVariant> toolVariants) {
|
||||
this.blockId = blockId;
|
||||
this.sprite = sprite;
|
||||
|
@ -16,6 +16,7 @@ public class Item {
|
||||
private ItemType type;
|
||||
private Optional<ToolVariant> toolVariant = Optional.empty();
|
||||
private SpriteLoader.SPRITES sprite;
|
||||
private Optional<Enum> spriteState = Optional.empty();
|
||||
private boolean stackable = true;
|
||||
private int durability;
|
||||
private double miningDecrease = 0;
|
||||
@ -71,4 +72,8 @@ public class Item {
|
||||
|
||||
return name.equals(item.name);
|
||||
}
|
||||
|
||||
public void setSpriteState(Enum spriteState) {
|
||||
this.spriteState = Optional.of(spriteState);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
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.sprites.Wool;
|
||||
|
||||
@BlockRegistry("black_wool")
|
||||
public class BlackWoolBlock extends Block {
|
||||
public BlackWoolBlock() {
|
||||
super("black_wool", SpriteLoader.SPRITES.WOOL, 3);
|
||||
setSpriteState(Wool.WoolState.BLACK);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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.sprites.Wool;
|
||||
|
||||
@BlockRegistry("brown_wool")
|
||||
public class BrownWoolBlock extends Block {
|
||||
public BrownWoolBlock() {
|
||||
super("brown_wool", SpriteLoader.SPRITES.WOOL, 3);
|
||||
setSpriteState(Wool.WoolState.BROWN);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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.sprites.Wool;
|
||||
|
||||
@BlockRegistry("gray_wool")
|
||||
public class GrayWoolBlock extends Block {
|
||||
public GrayWoolBlock() {
|
||||
super("gray_wool", SpriteLoader.SPRITES.WOOL, 3);
|
||||
setSpriteState(Wool.WoolState.GRAY);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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.sprites.Wool;
|
||||
|
||||
@BlockRegistry("light_gray_wool")
|
||||
public class LightGrayWoolBlock extends Block {
|
||||
public LightGrayWoolBlock() {
|
||||
super("light_gray_wool", SpriteLoader.SPRITES.WOOL, 3);
|
||||
setSpriteState(Wool.WoolState.LIGHT_GRAY);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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.sprites.Wool;
|
||||
|
||||
@BlockRegistry("pink_wool")
|
||||
public class PinkWoolBlock extends Block {
|
||||
public PinkWoolBlock() {
|
||||
super("pink_wool", SpriteLoader.SPRITES.WOOL, 3);
|
||||
setSpriteState(Wool.WoolState.PINK);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
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.sprites.Wool;
|
||||
|
||||
@BlockRegistry("white_wool")
|
||||
public class WhiteWoolBlock extends Block {
|
||||
public WhiteWoolBlock() {
|
||||
super("white_wool", SpriteLoader.SPRITES.WOOL, 3);
|
||||
setSpriteState(Wool.WoolState.WHITE);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
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.sprites.WoolItem;
|
||||
|
||||
@ItemRegistry("black_wool")
|
||||
public class BlackWoolItem extends Item {
|
||||
public BlackWoolItem() {
|
||||
super("black_wool", "Black wool", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_WOOL);
|
||||
setSpriteState(WoolItem.WoolItemState.BLACK);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
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.sprites.WoolItem;
|
||||
|
||||
@ItemRegistry("brown_wool")
|
||||
public class BrownWoolItem extends Item {
|
||||
public BrownWoolItem() {
|
||||
super("brown_wool", "Brown wool", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_WOOL);
|
||||
setSpriteState(WoolItem.WoolItemState.BROWN);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
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.sprites.WoolItem;
|
||||
|
||||
@ItemRegistry("gray_wool")
|
||||
public class GrayWoolItem extends Item {
|
||||
public GrayWoolItem() {
|
||||
super("gray_wool", "Gray wool", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_WOOL);
|
||||
setSpriteState(WoolItem.WoolItemState.GRAY);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
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.sprites.WoolItem;
|
||||
|
||||
@ItemRegistry("light_gray_wool")
|
||||
public class LightGrayWoolItem extends Item {
|
||||
public LightGrayWoolItem() {
|
||||
super("light_gray_wool", "Light gray wool", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_WOOL);
|
||||
setSpriteState(WoolItem.WoolItemState.LIGHT_GRAY);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
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.sprites.WoolItem;
|
||||
|
||||
@ItemRegistry("pink_wool")
|
||||
public class PinkWoolItem extends Item {
|
||||
public PinkWoolItem() {
|
||||
super("pink_wool", "Pink wool", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_WOOL);
|
||||
setSpriteState(WoolItem.WoolItemState.PINK);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
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.sprites.WoolItem;
|
||||
|
||||
@ItemRegistry("white_wool")
|
||||
public class WhiteWoolItem extends Item {
|
||||
public WhiteWoolItem() {
|
||||
super("white_wool", "White wool", ItemType.BLOCK, SpriteLoader.SPRITES.ITEM_WOOL);
|
||||
setSpriteState(WoolItem.WoolItemState.WHITE);
|
||||
}
|
||||
}
|
@ -4,46 +4,56 @@ 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 cz.jzitnik.game.mobs.services.sheep.SheepVariant;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
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() {
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
private static class SheepDTO {
|
||||
private cz.jzitnik.game.sprites.Sheep.SheepState state;
|
||||
private SheepVariant variant;
|
||||
}
|
||||
|
||||
private SheepDTO getSheep() {
|
||||
Random random = new Random();
|
||||
int num = random.nextInt(100);
|
||||
|
||||
if (num < 1) {
|
||||
return PINK_RIGHT;
|
||||
return new SheepDTO(PINK_RIGHT, SheepVariant.PINK);
|
||||
}
|
||||
|
||||
if (num < 4) {
|
||||
return BROWN_RIGHT;
|
||||
return new SheepDTO(BROWN_RIGHT, SheepVariant.BROWN);
|
||||
}
|
||||
|
||||
if (num < 15) {
|
||||
int num1 = random.nextInt(3);
|
||||
return switch (num1) {
|
||||
case 0 -> LIGHT_GRAY_RIGHT;
|
||||
case 1 -> GRAY_RIGHT;
|
||||
case 2 -> BLACK_RIGHT;
|
||||
case 0 -> new SheepDTO(LIGHT_GRAY_RIGHT, SheepVariant.LIGHT_GRAY);
|
||||
case 1 -> new SheepDTO(GRAY_RIGHT, SheepVariant.GRAY);
|
||||
case 2 -> new SheepDTO(BLACK_RIGHT, SheepVariant.BLACK);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + num1);
|
||||
};
|
||||
}
|
||||
|
||||
return WHITE_RIGHT;
|
||||
return new SheepDTO(WHITE_RIGHT, SheepVariant.WHITE);
|
||||
}
|
||||
|
||||
public Sheep() {
|
||||
super("sheep", SpriteLoader.SPRITES.SHEEP);
|
||||
var dto = getSheep();
|
||||
setMob(true);
|
||||
setGhost(true);
|
||||
setSpriteState(getSheep());
|
||||
setSpriteState(dto.getState());
|
||||
setMineable(false);
|
||||
setData(new SheepData());
|
||||
setData(new SheepData(dto.getVariant()));
|
||||
setHp(8);
|
||||
}
|
||||
}
|
||||
|
@ -9,4 +9,9 @@ public class SheepData {
|
||||
private int lastDirection = 1; // 1 = right, -1 = left
|
||||
private int movementCooldown = 0;
|
||||
private int jumpAttempts = 0;
|
||||
private SheepVariant variant;
|
||||
|
||||
public SheepData(SheepVariant variant) {
|
||||
this.variant = variant;
|
||||
}
|
||||
}
|
||||
|
@ -48,33 +48,7 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
|
||||
}
|
||||
sheepData.setLastDirection(direction);
|
||||
|
||||
boolean isHurt = sheep.getSpriteState().get().name().endsWith("_HURT");
|
||||
Sheep.SheepState newState = switch (sheep.getSpriteState().get()) {
|
||||
case WHITE_LEFT, WHITE_RIGHT, WHITE_LEFT_HURT, WHITE_RIGHT_HURT ->
|
||||
isHurt ? (direction == 1 ? WHITE_RIGHT_HURT : WHITE_LEFT_HURT)
|
||||
: (direction == 1 ? WHITE_RIGHT : WHITE_LEFT);
|
||||
|
||||
case LIGHT_GRAY_LEFT, LIGHT_GRAY_RIGHT, LIGHT_GRAY_LEFT_HURT, LIGHT_GRAY_RIGHT_HURT ->
|
||||
isHurt ? (direction == 1 ? LIGHT_GRAY_RIGHT_HURT : LIGHT_GRAY_LEFT_HURT)
|
||||
: (direction == 1 ? LIGHT_GRAY_RIGHT : LIGHT_GRAY_LEFT);
|
||||
|
||||
case GRAY_LEFT, GRAY_RIGHT, GRAY_LEFT_HURT, GRAY_RIGHT_HURT ->
|
||||
isHurt ? (direction == 1 ? GRAY_RIGHT_HURT : GRAY_LEFT_HURT)
|
||||
: (direction == 1 ? GRAY_RIGHT : GRAY_LEFT);
|
||||
|
||||
case BLACK_LEFT, BLACK_RIGHT, BLACK_LEFT_HURT, BLACK_RIGHT_HURT ->
|
||||
isHurt ? (direction == 1 ? BLACK_RIGHT_HURT : BLACK_LEFT_HURT)
|
||||
: (direction == 1 ? BLACK_RIGHT : BLACK_LEFT);
|
||||
|
||||
case BROWN_LEFT, BROWN_RIGHT, BROWN_LEFT_HURT, BROWN_RIGHT_HURT ->
|
||||
isHurt ? (direction == 1 ? BROWN_RIGHT_HURT : BROWN_LEFT_HURT)
|
||||
: (direction == 1 ? BROWN_RIGHT : BROWN_LEFT);
|
||||
|
||||
case PINK_LEFT, PINK_RIGHT, PINK_LEFT_HURT, PINK_RIGHT_HURT ->
|
||||
isHurt ? (direction == 1 ? PINK_RIGHT_HURT : PINK_LEFT_HURT)
|
||||
: (direction == 1 ? PINK_RIGHT : PINK_LEFT);
|
||||
default -> throw new IllegalStateException("Unexpected value: " + sheep.getSpriteState().get());
|
||||
};
|
||||
Sheep.SheepState newState = getSheepState(sheep, sheepData, direction);
|
||||
sheep.setSpriteState(newState);
|
||||
|
||||
|
||||
@ -118,6 +92,36 @@ public class SheepLogic implements EntityLogicInterface, EntitySpawnInterface, E
|
||||
sheepData.setMovementCooldown(random.nextInt(3) + 1); // 1-3 iterations cooldown
|
||||
}
|
||||
|
||||
private static Sheep.SheepState getSheepState(Block sheep, SheepData sheepData, int direction) {
|
||||
boolean isHurt = sheep.getSpriteState().get().name().endsWith("_HURT");
|
||||
Sheep.SheepState newState = switch (sheepData.getVariant()) {
|
||||
case WHITE ->
|
||||
isHurt ? (direction == 1 ? WHITE_RIGHT_HURT : WHITE_LEFT_HURT)
|
||||
: (direction == 1 ? WHITE_RIGHT : WHITE_LEFT);
|
||||
|
||||
case LIGHT_GRAY ->
|
||||
isHurt ? (direction == 1 ? LIGHT_GRAY_RIGHT_HURT : LIGHT_GRAY_LEFT_HURT)
|
||||
: (direction == 1 ? LIGHT_GRAY_RIGHT : LIGHT_GRAY_LEFT);
|
||||
|
||||
case GRAY ->
|
||||
isHurt ? (direction == 1 ? GRAY_RIGHT_HURT : GRAY_LEFT_HURT)
|
||||
: (direction == 1 ? GRAY_RIGHT : GRAY_LEFT);
|
||||
|
||||
case BLACK ->
|
||||
isHurt ? (direction == 1 ? BLACK_RIGHT_HURT : BLACK_LEFT_HURT)
|
||||
: (direction == 1 ? BLACK_RIGHT : BLACK_LEFT);
|
||||
|
||||
case BROWN ->
|
||||
isHurt ? (direction == 1 ? BROWN_RIGHT_HURT : BROWN_LEFT_HURT)
|
||||
: (direction == 1 ? BROWN_RIGHT : BROWN_LEFT);
|
||||
|
||||
case PINK ->
|
||||
isHurt ? (direction == 1 ? PINK_RIGHT_HURT : PINK_LEFT_HURT)
|
||||
: (direction == 1 ? PINK_RIGHT : PINK_LEFT);
|
||||
};
|
||||
return newState;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void spawn(int playerX, int playerY, Game game, Terminal terminal) {
|
||||
// Cordinates where player can see
|
||||
@ -246,7 +250,19 @@ 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.getItem("mutton"));
|
||||
game.getInventory().addItem(inventoryItem);
|
||||
var sheepData = (SheepData) mob.getData();
|
||||
|
||||
InventoryItem mutton = new InventoryItem(amount, ItemBlockSupplier.getItem("mutton"));
|
||||
InventoryItem wool = new InventoryItem(1, ItemBlockSupplier.getItem(switch (sheepData.getVariant()) {
|
||||
case WHITE -> "white_wool";
|
||||
case LIGHT_GRAY -> "light_gray_wool";
|
||||
case GRAY -> "gray_wool";
|
||||
case BLACK -> "black_wool";
|
||||
case BROWN -> "brown_wool";
|
||||
case PINK -> "pink_wool";
|
||||
}));
|
||||
|
||||
game.getInventory().addItem(mutton);
|
||||
game.getInventory().addItem(wool);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package cz.jzitnik.game.mobs.services.sheep;
|
||||
|
||||
public enum SheepVariant {
|
||||
WHITE,
|
||||
LIGHT_GRAY,
|
||||
GRAY,
|
||||
BLACK,
|
||||
BROWN,
|
||||
PINK
|
||||
}
|
34
src/main/java/cz/jzitnik/game/sprites/Wool.java
Normal file
34
src/main/java/cz/jzitnik/game/sprites/Wool.java
Normal file
@ -0,0 +1,34 @@
|
||||
package cz.jzitnik.game.sprites;
|
||||
|
||||
import cz.jzitnik.tui.ResourceLoader;
|
||||
import cz.jzitnik.tui.Sprite;
|
||||
|
||||
public class Wool extends Sprite {
|
||||
public enum WoolState {
|
||||
WHITE,
|
||||
LIGHT_GRAY,
|
||||
GRAY,
|
||||
BLACK,
|
||||
BROWN,
|
||||
PINK,
|
||||
}
|
||||
|
||||
public String getSprite() {
|
||||
return getSprite(WoolState.WHITE);
|
||||
}
|
||||
|
||||
public String getSprite(Enum e) {
|
||||
return ResourceLoader.loadResource(
|
||||
switch (e) {
|
||||
case WoolState.WHITE -> "white_wool.ans";
|
||||
case WoolState.LIGHT_GRAY -> "light_gray_wool.ans";
|
||||
case WoolState.GRAY -> "gray_wool.ans";
|
||||
case WoolState.BLACK -> "black_wool.ans";
|
||||
case WoolState.BROWN -> "brown_wool.ans";
|
||||
case WoolState.PINK -> "pink_wool.ans";
|
||||
|
||||
default -> throw new IllegalStateException("Unexpected value: " + e);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
34
src/main/java/cz/jzitnik/game/sprites/WoolItem.java
Normal file
34
src/main/java/cz/jzitnik/game/sprites/WoolItem.java
Normal file
@ -0,0 +1,34 @@
|
||||
package cz.jzitnik.game.sprites;
|
||||
|
||||
import cz.jzitnik.tui.ResourceLoader;
|
||||
import cz.jzitnik.tui.Sprite;
|
||||
|
||||
public class WoolItem extends Sprite {
|
||||
public enum WoolItemState {
|
||||
WHITE,
|
||||
LIGHT_GRAY,
|
||||
GRAY,
|
||||
BLACK,
|
||||
BROWN,
|
||||
PINK,
|
||||
}
|
||||
|
||||
public String getSprite() {
|
||||
return getSprite(WoolItemState.WHITE);
|
||||
}
|
||||
|
||||
public String getSprite(Enum e) {
|
||||
return ResourceLoader.loadResource(
|
||||
switch (e) {
|
||||
case WoolItemState.WHITE -> "items/white_wool.ans";
|
||||
case WoolItemState.LIGHT_GRAY -> "items/light_gray_wool.ans";
|
||||
case WoolItemState.GRAY -> "items/gray_wool.ans";
|
||||
case WoolItemState.BLACK -> "items/black_wool.ans";
|
||||
case WoolItemState.BROWN -> "items/brown_wool.ans";
|
||||
case WoolItemState.PINK -> "items/pink_wool.ans";
|
||||
|
||||
default -> throw new IllegalStateException("Unexpected value: " + e);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
@ -65,7 +65,9 @@ public class CraftingTable {
|
||||
Optional<InventoryItem> craftedItem = recipe.map(craftingRecipe -> craftingRecipe.getItemSupplier().get());
|
||||
|
||||
String[] craftedSprite = craftedItem.map(inventoryItem -> SpriteCombiner.combineTwoSprites(
|
||||
spriteList.getSprite(inventoryItem.getItem().getFirst().getSprite()).getSprite(),
|
||||
inventoryItem.getItem().getFirst().getSpriteState().isPresent() ?
|
||||
spriteList.getSprite(inventoryItem.getItem().getFirst().getSprite()).getSprite(inventoryItem.getItem().getFirst().getSpriteState().get()) :
|
||||
spriteList.getSprite(inventoryItem.getItem().getFirst().getSprite()).getSprite() ,
|
||||
Numbers.getNumberSprite(inventoryItem.getAmount())
|
||||
).split("\n")).orElse(null);
|
||||
|
||||
|
@ -223,14 +223,18 @@ public class Inventory {
|
||||
|
||||
if (i == selectedItem) {
|
||||
sprites.add(SpriteCombiner.combineTwoSprites(getHotbarBackground(), SpriteCombiner.combineTwoSprites(
|
||||
spriteList.getSprite(item.getItem().getFirst().getSprite()).getSprite(),
|
||||
item.getItem().getFirst().getSpriteState().isPresent() ?
|
||||
spriteList.getSprite(item.getItem().getFirst().getSprite()).getSprite(item.getItem().getFirst().getSpriteState().get()) :
|
||||
spriteList.getSprite(item.getItem().getFirst().getSprite()).getSprite(),
|
||||
Numbers.getNumberSprite(item.getAmount())
|
||||
)));
|
||||
continue;
|
||||
}
|
||||
|
||||
sprites.add(SpriteCombiner.combineTwoSprites(
|
||||
spriteList.getSprite(item.getItem().getFirst().getSprite()).getSprite(),
|
||||
item.getItem().getFirst().getSpriteState().isPresent() ?
|
||||
spriteList.getSprite(item.getItem().getFirst().getSprite()).getSprite(item.getItem().getFirst().getSpriteState().get()) :
|
||||
spriteList.getSprite(item.getItem().getFirst().getSprite()).getSprite(),
|
||||
Numbers.getNumberSprite(item.getAmount())
|
||||
));
|
||||
}
|
||||
|
@ -52,7 +52,9 @@ public class SmallCraftingTable {
|
||||
Optional<InventoryItem> craftedItem = recipe.map(craftingRecipe -> craftingRecipe.getItemSupplier().get());
|
||||
|
||||
String[] craftedSprite = craftedItem.map(inventoryItem -> SpriteCombiner.combineTwoSprites(
|
||||
spriteList.getSprite(inventoryItem.getItem().getFirst().getSprite()).getSprite(),
|
||||
inventoryItem.getItem().getFirst().getSpriteState().isPresent() ?
|
||||
spriteList.getSprite(inventoryItem.getItem().getFirst().getSprite()).getSprite(inventoryItem.getItem().getFirst().getSpriteState().get()) :
|
||||
spriteList.getSprite(inventoryItem.getItem().getFirst().getSprite()).getSprite() ,
|
||||
Numbers.getNumberSprite(inventoryItem.getAmount())
|
||||
).split("\n")).orElse(null);
|
||||
|
||||
|
Reference in New Issue
Block a user