64 lines
2.1 KiB
Java
64 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 java.util.ArrayDeque;
|
|
|
|
import net.minecraft.registry.Registries;
|
|
import net.minecraft.util.math.BlockPos;
|
|
import wtf.hak.survivalfabric.veinminer.VeinMinerSession;
|
|
|
|
import static wtf.hak.survivalfabric.config.ConfigManager.getConfig;
|
|
|
|
public class OreDrill extends DrillBase {
|
|
|
|
public OreDrill(VeinMinerSession session) {
|
|
super(session);
|
|
}
|
|
|
|
public static final TagKey<Block> oreTag = TagKey.of(RegistryKeys.BLOCK, Identifier.of("survivalfabric", "ore"));
|
|
|
|
@Override
|
|
public boolean canHandle(BlockState blockState) {
|
|
return blockState.isIn(oreTag);
|
|
}
|
|
|
|
@Override
|
|
public boolean drill(BlockPos startPos) {
|
|
ServerWorld world = session.world;
|
|
Block initialBlock = world.getBlockState(startPos).getBlock();
|
|
int brokenOre = 0;
|
|
ArrayDeque<BlockPos> pending = new ArrayDeque<BlockPos>();
|
|
pending.add(startPos);
|
|
|
|
while (!pending.isEmpty() && brokenOre < getConfig().maxVeinSize) {
|
|
BlockPos orePos = pending.remove();
|
|
Block oreBlock = world.getBlockState(orePos).getBlock();
|
|
if (tryBreakBlock(orePos)) {
|
|
if (oreBlock == initialBlock) {
|
|
brokenOre += 1;
|
|
}
|
|
|
|
if (oreBlock == initialBlock) {
|
|
// look around current block
|
|
forXYZ(orePos, 1, newPos -> {
|
|
BlockState newBlockState = world.getBlockState(newPos);
|
|
Block newBlock = newBlockState.getBlock();
|
|
boolean isSameOreBlock = newBlock == oreBlock;
|
|
if (!pending.contains(newPos) && isSameOreBlock) {
|
|
pending.add(newPos);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
} |