65 lines
1.9 KiB
Java

package cz.jzitnik.game;
import cz.jzitnik.game.items.Item;
import cz.jzitnik.game.items.ItemType;
import cz.jzitnik.game.items.ToolVariant;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@Getter
@Setter
public class Block {
private String blockId;
private SpriteLoader.SPRITES sprite;
private Optional<Enum> spriteState = Optional.empty();
private boolean ghost = false;
private boolean isMineable = true;
private int hardness = 1;
private Optional<ItemType> tool = Optional.empty();
private List<ToolVariant> toolVariants = new ArrayList<>();
private List<Item> drops = new ArrayList<>();
public Block(String blockId, SpriteLoader.SPRITES sprite) {
this.blockId = blockId;
this.sprite = sprite;
}
public Block(String blockId, SpriteLoader.SPRITES sprite, boolean ghost, boolean isMineable) {
this.blockId = blockId;
this.sprite = sprite;
this.ghost = ghost;
this.isMineable = isMineable;
}
public Block(String blockId, SpriteLoader.SPRITES sprite, int hardness, ItemType tool, List<ToolVariant> toolVariants) {
this.blockId = blockId;
this.sprite = sprite;
this.hardness = hardness;
this.tool = Optional.of(tool);
this.toolVariants = toolVariants;
}
public void setSpriteState(Enum spriteState) {
this.spriteState = Optional.of(spriteState);
}
public int calculateHardness(Inventory inventory) {
int holdingDecrease = 0;
if (inventory.getItemInHand().isPresent() && tool.isPresent() && inventory.getItemInHand().get().getType().equals(tool.get())) {
holdingDecrease = inventory.getItemInHand().get().getMiningDecrease();
}
int decrease = hardness - holdingDecrease;
if (decrease < 0) {
decrease = 0;
}
return decrease;
}
}