package Hexel.blocks.rules;
import Hexel.blocks.BlockDelta;
import Hexel.blocks.BlockSimulator;
import Hexel.blocks.ProbabilisticFreqBlockRule;
import Hexel.blocks.BlockSimulator.BlockDeltaAdder;
import Hexel.blocks.types.Block;
import Hexel.blocks.types.BlockDirt;
import Hexel.blocks.types.BlockEmpty;
import Hexel.chunk.Chunk;
import Hexel.chunk.Chunks;
import Hexel.chunk.HighestBlockChunk;
import Hexel.math.HexGeometry;
import Hexel.math.Vector2i;
import Hexel.math.Vector3i;
public class GrassGrowRule extends ProbabilisticFreqBlockRule {
public GrassGrowRule() {
super(250, .25);
}
private Vector3i tmp3i = new Vector3i();
@Override
public boolean canApply(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
BlockDirt bd = (BlockDirt)b;
if (bd.hasGrass)
return false;
Block ab = chunks.getBlock(bx, by, bz+1, tmp3i, c);
if (!(ab instanceof BlockEmpty))
return false;
Vector2i[] neighbors = HexGeometry.getNeighbors(bx);
for (int i = 0; i < neighbors.length; i++){
int nx = bx + neighbors[i].x;
int ny = by + neighbors[i].y;
Block nb = chunks.getBlock(nx, ny, bz, tmp3i, c);
if (nb instanceof BlockDirt && ((BlockDirt)nb).hasGrass){
return true;
}
}
return false;
}
@Override
public int probabilisticRun(int bx, int by, int bz, boolean fastMode, Block b, Chunk c,
HighestBlockChunk hbc, Chunks chunks, int step, BlockDeltaAdder blockDeltaAdder) {
blockDeltaAdder.addBlockDelta(BlockDelta.Aquire(bx, by, bz, BlockDirt.Make(b.getHealth(), true), chunks.getStepsToSim(bx, by, bz, tmp3i, c)));
return BlockSimulator.DONT_RUN;
}
}