90 lines
2.7 KiB
Java
90 lines
2.7 KiB
Java
package cz.jzitnik.game.entities;
|
|
|
|
import cz.jzitnik.game.SpriteLoader;
|
|
import cz.jzitnik.game.entities.items.Item;
|
|
import cz.jzitnik.game.entities.items.ItemType;
|
|
import cz.jzitnik.game.entities.items.ToolVariant;
|
|
import cz.jzitnik.game.ui.Inventory;
|
|
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<>();
|
|
private Object data = null;
|
|
private boolean flowing = false;
|
|
private boolean isMob = false;
|
|
private int hp = 0;
|
|
|
|
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) {
|
|
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;
|
|
this.hardness = hardness;
|
|
this.tool = Optional.of(tool);
|
|
this.toolVariants = toolVariants;
|
|
}
|
|
|
|
public Block(String blockId, SpriteLoader.SPRITES sprite, int hardness, ItemType tool, List<ToolVariant> toolVariants, Object data) {
|
|
this.blockId = blockId;
|
|
this.sprite = sprite;
|
|
this.hardness = hardness;
|
|
this.tool = Optional.of(tool);
|
|
this.toolVariants = toolVariants;
|
|
this.data = data;
|
|
}
|
|
|
|
public void setSpriteState(Enum spriteState) {
|
|
this.spriteState = Optional.of(spriteState);
|
|
}
|
|
|
|
public double calculateHardness(Inventory inventory) {
|
|
double holdingDecrease = 0;
|
|
if (inventory.getItemInHand().isPresent() && tool.isPresent() && inventory.getItemInHand().get().getType().equals(tool.get())) {
|
|
holdingDecrease = inventory.getItemInHand().get().getMiningDecrease();
|
|
}
|
|
|
|
double decrease = hardness - holdingDecrease;
|
|
|
|
if (decrease < 0) {
|
|
decrease = 0;
|
|
}
|
|
|
|
return decrease;
|
|
}
|
|
|
|
public void decreaseHp(int amount) {
|
|
hp -= amount;
|
|
}
|
|
}
|