forked from jzitnik/twodcraft
93 lines
2.8 KiB
Java
93 lines
2.8 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.io.Serializable;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
@Getter
|
|
@Setter
|
|
public class Block implements Serializable {
|
|
private String blockId;
|
|
private SpriteLoader.SPRITES sprite;
|
|
private MyOptional<Enum> spriteState = MyOptional.empty();
|
|
private boolean ghost = false;
|
|
private boolean isMineable = true;
|
|
private int hardness = 1;
|
|
private MyOptional<ItemType> tool = MyOptional.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 = MyOptional.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 = MyOptional.of(tool);
|
|
this.toolVariants = toolVariants;
|
|
this.data = data;
|
|
}
|
|
|
|
public void setSpriteState(Enum spriteState) {
|
|
this.spriteState = MyOptional.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;
|
|
}
|
|
}
|