2025-03-02 09:31:07 +01:00

80 lines
2.3 KiB
Java

package cz.jzitnik.game.entities.items;
import cz.jzitnik.game.entities.Block;
import cz.jzitnik.game.SpriteLoader;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
import java.util.Optional;
@Getter
@AllArgsConstructor
public class Item {
private String id;
private String name;
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;
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) {
this.id = id;
this.name = name;
this.type = type;
this.sprite = sprite;
this.toolVariant = Optional.of(toolVariant);
this.miningDecrease = miningDecrease;
this.durability = durability;
this.stackable = stackable;
}
public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, Block block) {
this.id = id;
this.name = name;
this.type = type;
this.sprite = sprite;
this.block = Optional.of(block);
}
public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite) {
this.id = id;
this.name = name;
this.type = type;
this.sprite = sprite;
}
public Item(String id, String name, ItemType type, SpriteLoader.SPRITES sprite, int addHunger) {
this.id = id;
this.name = name;
this.type = type;
this.sprite = sprite;
this.addHunger = addHunger;
}
public void use() {
durability--;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Item item = (Item) o;
return name.equals(item.name);
}
public void setSpriteState(Enum spriteState) {
this.spriteState = Optional.of(spriteState);
}
}