62 lines
2.1 KiB
Java
62 lines
2.1 KiB
Java
package wtf.hak.survivalfabric.veinminer.drills;
|
|
|
|
import net.minecraft.block.Block;
|
|
import net.minecraft.block.BlockState;
|
|
import net.minecraft.registry.RegistryKeys;
|
|
import net.minecraft.registry.tag.TagKey;
|
|
import net.minecraft.server.world.ServerWorld;
|
|
import net.minecraft.util.Identifier;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import wtf.hak.survivalfabric.veinminer.VeinMinerSession;
|
|
|
|
import java.util.ArrayDeque;
|
|
|
|
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
|
|
|
public class LeavesDrill extends DrillBase {
|
|
|
|
public LeavesDrill(VeinMinerSession session) {
|
|
super(session);
|
|
}
|
|
|
|
public static final TagKey<Block> leavesTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "leaves"));
|
|
|
|
@Override
|
|
public boolean canHandle(BlockState blockState) {
|
|
return blockState.isIn(leavesTag);
|
|
}
|
|
|
|
@Override
|
|
public boolean drill(BlockPos startPos) {
|
|
ServerWorld world = session.world;
|
|
Block initialBlock = world.getBlockState(startPos).getBlock();
|
|
int brokenLeaves = 0;
|
|
ArrayDeque<BlockPos> pending = new ArrayDeque<BlockPos>();
|
|
pending.add(startPos);
|
|
|
|
while (!pending.isEmpty() && brokenLeaves < getConfig().maxVeinSize) {
|
|
BlockPos leavesPos = pending.remove();
|
|
Block leavesBlock = world.getBlockState(leavesPos).getBlock();
|
|
if (tryBreakBlock(leavesPos)) {
|
|
if (leavesBlock == initialBlock) {
|
|
brokenLeaves += 1;
|
|
}
|
|
|
|
if (leavesBlock == initialBlock) {
|
|
// look around current block
|
|
forXYZ(leavesPos, 1, newPos -> {
|
|
BlockState newBlockState = world.getBlockState(newPos);
|
|
Block newBlock = newBlockState.getBlock();
|
|
boolean isSameOreBlock = newBlock == leavesBlock;
|
|
if (!pending.contains(newPos) && isSameOreBlock) {
|
|
pending.add(newPos);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
} |