基于js的矿物探测器
会自动输出玩家丢出物品至控制台
不需要的把42行删掉就可以了
请将下述代码写入文件并修改为js后缀(附件不让传js我真的没办法)
会自动输出玩家丢出物品至控制台
不需要的把42行删掉就可以了
请将下述代码写入文件并修改为js后缀(附件不让传js我真的没办法)
JavaScript:
//LiteLoaderScript Dev Helper
/// <reference path="c:\Users\Administrator\Desktop/dts/llaids/src/index.d.ts"/>
ll.registerPlugin(
/* name */ "minedetector",
/* introduction */ "丢出矿物即可开始检测最近的矿物",
/* version */[1, 0, 0],
/* otherInformation */ {}
);
function findNearestBlock(
pos,
blockTypes,
) {
const radius = 8
const { x, y, z, dimid } = pos;
let lastDistance = 0;
let lastBlock;
for (let lx = x - radius; lx <= x + radius; lx += 1) {
for (let ly = y - radius; ly <= y + radius; ly += 1) {
for (let lz = z - radius; lz <= z + radius; lz += 1) {
const block = mc.getBlock(lx, ly, lz, dimid);
if (blockTypes.includes(block.type)) {
const distance = Math.sqrt(
(x - lx) * (x - lx) + (y - ly) * (y - ly) + (z - lz) * (z - lz)
);
if (distance < lastDistance || !lastDistance) {
lastDistance = distance;
lastBlock = block;
}
}
}
}
}
return lastBlock;
}
mc.listen("onDropItem", (player, item) => {
const { x, y, z, dimid } = player.blockPos;
let blockTypes;
let label;
switch (item.type) {
case "minecraft:emerald":
blockTypes = ["minecraft:emerald_ore", "minecraft:deepslate_emerald_ore"];
label = "绿宝石";
break;
case "minecraft:diamond":
blockTypes = ["minecraft:diamond_ore", "minecraft:deepslate_diamond_ore"];
label = "钻石";
break;
case "minecraft:ancient_debris":
blockTypes = ["minecraft:ancient_debris"];
label = "下界残骸";
break;
case "minecraft:lapis_lazuli":
blockTypes = ["minecraft:lapis_ore", "minecraft:deepslate_lapis_ore"];
label = "青金石";
break;
case "minecraft:iron_ingot":
blockTypes = ["minecraft:iron_ore", "minecraft:deepslate_iron_ore"];
label = "铁矿";
break;
default:
return;
}
const found = findNearestBlock(mc.newIntPos(x, y, z, dimid), blockTypes);
const pos = found?.pos;
player.setTitle(
pos
? `最近的${label}位于§e§l(${pos.x}, ${pos.y}, ${pos.z})`
: `附近没有${label}`,
4, 10, 20, 0
);
if (pos) {
let lizi = mc.newParticleSpawner(8, true, true);
lizi.drawOrientedLine(
player.blockPos,
pos,
2,
0.5,
64,
"minecraft:balloon_gas_particle"
);
}
});
const conYellow = '\u001b[0;33m';
logger.info(`${conYellow}插件加载成功,欢迎使用矿物探测器`);