forked from jzitnik/twodcraft
feat: Implemented catching on fire from lava
This commit is contained in:
parent
d7b4e28e81
commit
0bd9dfb412
@ -9,4 +9,5 @@ import java.lang.annotation.ElementType;
|
|||||||
@Target(ElementType.TYPE)
|
@Target(ElementType.TYPE)
|
||||||
@RequireAnnotation(BlockRegistry.class)
|
@RequireAnnotation(BlockRegistry.class)
|
||||||
public @interface Flamable {
|
public @interface Flamable {
|
||||||
|
boolean value() default true;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import cz.jzitnik.game.entities.items.ItemType;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Flamable
|
@Flamable(false)
|
||||||
@BlockRegistry("chest")
|
@BlockRegistry("chest")
|
||||||
public class ChestBlock extends Block {
|
public class ChestBlock extends Block {
|
||||||
public ChestBlock() {
|
public ChestBlock() {
|
||||||
|
@ -8,7 +8,7 @@ import cz.jzitnik.game.entities.items.ItemType;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@Flamable
|
@Flamable(false)
|
||||||
@BlockRegistry("crafting_table")
|
@BlockRegistry("crafting_table")
|
||||||
public class CraftingTableBlock extends Block {
|
public class CraftingTableBlock extends Block {
|
||||||
public CraftingTableBlock() {
|
public CraftingTableBlock() {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package cz.jzitnik.game.generation;
|
package cz.jzitnik.game.generation;
|
||||||
|
|
||||||
import cz.jzitnik.game.entities.Block;
|
import cz.jzitnik.game.entities.Block;
|
||||||
import cz.jzitnik.game.entities.items.InventoryItem;
|
|
||||||
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
|
import cz.jzitnik.game.entities.items.ItemBlockSupplier;
|
||||||
import cz.jzitnik.game.Game;
|
import cz.jzitnik.game.Game;
|
||||||
import cz.jzitnik.game.SpriteLoader;
|
import cz.jzitnik.game.SpriteLoader;
|
||||||
@ -35,7 +34,9 @@ public class Generation {
|
|||||||
world[terrainHeight[256] - 1][256].add(steveBlock2);
|
world[terrainHeight[256] - 1][256].add(steveBlock2);
|
||||||
world[terrainHeight[256] - 2][256].add(steveBlock);
|
world[terrainHeight[256] - 2][256].add(steveBlock);
|
||||||
|
|
||||||
game.getInventory().addItem(new InventoryItem(64, ItemBlockSupplier.getItem("gravel")));
|
game.getInventory().addItem(ItemBlockSupplier.getItem("lava_bucket"));
|
||||||
|
game.getInventory().addItem(ItemBlockSupplier.getItem("crafting_table"));
|
||||||
|
game.getInventory().addItem(ItemBlockSupplier.getItem("oak_planks"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initializeWorld(List<Block>[][] world) {
|
private static void initializeWorld(List<Block>[][] world) {
|
||||||
|
@ -31,7 +31,7 @@ public class FireSpreadingLogic implements CustomLogicInterface {
|
|||||||
var blocks = world[y][x];
|
var blocks = world[y][x];
|
||||||
|
|
||||||
for (Block block : blocks) {
|
for (Block block : blocks) {
|
||||||
if (block.isOnFire()) {
|
if (block.isOnFire() && block.getClass().getAnnotation(Flamable.class).value()) {
|
||||||
int maxTime = random.nextInt(30) + 15;
|
int maxTime = random.nextInt(30) + 15;
|
||||||
block.setBurningTime2(block.getBurningTime2() + 1);
|
block.setBurningTime2(block.getBurningTime2() + 1);
|
||||||
if (block.getBurningTime2() >= maxTime) {
|
if (block.getBurningTime2() >= maxTime) {
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
package cz.jzitnik.game.logic.services.flowing;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import cz.jzitnik.game.Game;
|
||||||
|
import cz.jzitnik.game.annotations.CustomLogic;
|
||||||
|
import cz.jzitnik.game.annotations.Flamable;
|
||||||
|
import cz.jzitnik.game.entities.Block;
|
||||||
|
import cz.jzitnik.game.logic.CustomLogicInterface;
|
||||||
|
|
||||||
|
@CustomLogic
|
||||||
|
public class LavaFireLogic implements CustomLogicInterface {
|
||||||
|
private static final int RADIUS = 30;
|
||||||
|
private Random random = new Random();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void nextIteration(Game game) {
|
||||||
|
int[] data = game.getPlayerCords();
|
||||||
|
var world = game.getWorld();
|
||||||
|
int playerX = data[0];
|
||||||
|
int playerY = data[1];
|
||||||
|
|
||||||
|
int startX = Math.max(0, playerX - RADIUS);
|
||||||
|
int startY = Math.max(0, playerY - RADIUS);
|
||||||
|
int endX = Math.min(world[0].length - 1, playerX + RADIUS);
|
||||||
|
int endY = Math.min(world.length - 1, playerY + RADIUS);
|
||||||
|
|
||||||
|
for (int y = startY; y <= endY; y++) {
|
||||||
|
for (int x = startX; x <= endX; x++) {
|
||||||
|
var blocks = world[y][x];
|
||||||
|
|
||||||
|
if (blocks.stream().anyMatch(block -> block.getBlockId().equals("lava"))) {
|
||||||
|
setOnFire(game, x + 1, y);
|
||||||
|
setOnFire(game, x - 1, y);
|
||||||
|
setOnFire(game, x, y + 1);
|
||||||
|
setOnFire(game, x, y - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnFire(Game game, int x, int y) {
|
||||||
|
var world = game.getWorld();
|
||||||
|
|
||||||
|
if (x < 0 || y < 0 || y >= world.length || x >= world[0].length) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Block block : world[y][x]) {
|
||||||
|
if (block.getClass().isAnnotationPresent(Flamable.class) && !block.isOnFire()) {
|
||||||
|
int maxTime = random.nextInt(8) + 5;
|
||||||
|
block.setBurningTime(block.getBurningTime() + 1);
|
||||||
|
if (block.getBurningTime() >= maxTime) {
|
||||||
|
block.setOnFire(true);
|
||||||
|
block.setBurningTime(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user