Files
BP
RP
Code
34 780
BP/scripts/main.js
import { world, system, EquipmentSlot, EnchantmentTypes } from "@minecraft/server";
const ITEM = {
necklace: "darkness:dark_dragon_necklace",
mace: "darkness:darkness_mace",
sword: "darkness:darkness_sword",
grimoire: "darkness:shadow_grimoire",
chestplate: "darkness:shadow_chestplate",
pickaxe: "darkness:mystic_pickaxe",
axe: "darkness:mystic_axe",
shovel: "darkness:mystic_shovel",
voidBook: "darkness:void_touch_book",
massBook: "darkness:shadow_mass_book"
};
const cooldowns = new Map();
const flightUntil = new Map();
const jumpHeld = new Map();
const sneakHeld = new Map();
let tick = 0;
function equipped(player, slot) {
return player.getComponent("minecraft:equippable")?.getEquipment(slot);
}
function hasItem(player, id) {
return equipped(player, EquipmentSlot.Mainhand)?.typeId === id ||
equipped(player, EquipmentSlot.Offhand)?.typeId === id;
}
function mobsNear(dimension, location, radius) {
return dimension.getEntities({ location, maxDistance: radius }).filter(entity =>
entity.typeId !== "minecraft:player" && entity.typeId !== "darkness:shadow_guardian"
);
}
function useCooldown(player, key, seconds) {
const id = `${player.id}:${key}`;
const until = cooldowns.get(id) ?? 0;
if (tick < until) return false;
cooldowns.set(id, tick + seconds * 20);
return true;
}
function notify(player, text) {
player.sendMessage(`§5[Relíquias] §r${text}`);
}
function burst(dimension, location, particle, count = 12, spread = 0.7) {
for (let i = 0; i < count; i++) {
dimension.spawnParticle(particle, {
x: location.x + (Math.random() - 0.5) * spread,
y: location.y + Math.random() * spread,
z: location.z + (Math.random() - 0.5) * spread
});
}
}
function knockAway(source, target, strength, lift = 0.45) {
const dx = target.location.x - source.location.x;
const dz = target.location.z - source.location.z;
const length = Math.max(0.01, Math.hypot(dx, dz));
target.applyKnockback({ x: dx / length * strength, z: dz / length * strength }, lift);
}
function roar(player) {
if (!useCooldown(player, "roar", 12)) return notify(player, "Rugido do Vazio ainda está recarregando.");
for (const mob of mobsNear(player.dimension, player.location, 10)) {
knockAway(player, mob, 2.8, 0.9);
mob.addEffect("blindness", 100, { amplifier: 0 });
mob.addEffect("weakness", 100, { amplifier: 1 });
mob.addEffect("slowness", 60, { amplifier: 1 });
}
burst(player.dimension, player.location, "minecraft:soul_fire_flame", 28, 2.2);
notify(player, "Rugido do Vazio!");
}
function shadowBoost(player) {
if (!useCooldown(player, "shadow_boost", 10)) return notify(player, "Impulso das Sombras ainda está recarregando.");
player.applyImpulse({ x: 0, y: 1.6, z: 0 });
burst(player.dimension, player.location, "minecraft:soul_fire_flame", 24, 1.8);
notify(player, "Impulso das Sombras!");
}
function shadowBolt(player) {
if (!useCooldown(player, "shadow_bolt", 8)) return notify(player, "O disparo sombrio ainda está recarregando.");
const direction = player.getViewDirection();
const origin = player.getHeadLocation();
const hitIds = new Set();
let step = 1;
const task = system.runInterval(() => {
if (step > 22 || !player.isValid) return system.clearRun(task);
const point = {
x: origin.x + direction.x * step,
y: origin.y + direction.y * step,
z: origin.z + direction.z * step
};
burst(player.dimension, point, "minecraft:basic_smoke_particle", 3, 0.45);
for (const mob of mobsNear(player.dimension, point, 2.0)) {
if (hitIds.has(mob.id)) continue;
hitIds.add(mob.id);
mob.applyDamage(8);
mob.addEffect("blindness", 80, { amplifier: 0 });
mob.addEffect("slowness", 100, { amplifier: 4 });
}
step++;
}, 1);
}
function summonGuardians(player) {
if (!useCooldown(player, "grimoire", 20)) return notify(player, "O grimório ainda está recarregando.");
for (let i = 0; i < 3; i++) {
const angle = Math.PI * 2 * i / 3;
const point = {
x: player.location.x + Math.cos(angle) * 2,
y: player.location.y,
z: player.location.z + Math.sin(angle) * 2
};
const guardian = player.dimension.spawnEntity("darkness:shadow_guardian", point);
guardian.addTag(`darkness_owner_${player.id}`);
burst(player.dimension, point, "minecraft:basic_smoke_particle", 14, 1.2);
system.runTimeout(() => {
if (guardian.isValid) guardian.remove();
}, 300);
}
notify(player, "Três Guardiões Sombrios defendem você por 15 segundos!");
}
function shadowAura(player) {
if (!useCooldown(player, "shadow_aura", 15)) return notify(player, "A Aura de Sombras ainda está recarregando.");
for (const mob of mobsNear(player.dimension, player.location, 8)) knockAway(player, mob, 2.2, 0.8);
player.addEffect("regeneration", 100, { amplifier: 3 });
burst(player.dimension, player.location, "minecraft:basic_smoke_particle", 32, 2.5);
notify(player, "Aura de Sombras!");
}
world.afterEvents.itemUse.subscribe(event => {
const { source, itemStack } = event;
if (itemStack.typeId === ITEM.necklace) roar(source);
else if (itemStack.typeId === ITEM.mace) shadowBoost(source);
else if (itemStack.typeId === ITEM.sword) shadowBolt(source);
else if (itemStack.typeId === ITEM.grimoire) summonGuardians(source);
else if (itemStack.typeId === ITEM.chestplate) shadowAura(source);
});
function armorSetComplete(player) {
return equipped(player, EquipmentSlot.Head)?.typeId === "darkness:shadow_helmet" &&
equipped(player, EquipmentSlot.Chest)?.typeId === ITEM.chestplate &&
equipped(player, EquipmentSlot.Legs)?.typeId === "darkness:shadow_leggings" &&
equipped(player, EquipmentSlot.Feet)?.typeId === "darkness:shadow_boots";
}
function applyLegalEnchantments(stack) {
const component = stack.getComponent("minecraft:enchantable");
if (!component) return stack;
let changed = false;
const requested = stack.typeId === ITEM.mace
? [["density", 5], ["breach", 4], ["wind_burst", 3]]
: stack.typeId === ITEM.sword
? [["sharpness", 5], ["fire_aspect", 2], ["unbreaking", 3], ["looting", 3]]
: stack.typeId === ITEM.pickaxe || stack.typeId === ITEM.axe || stack.typeId === ITEM.shovel
? [["efficiency", 5], ["unbreaking", 3], ["fortune", 3]]
: stack.typeId.startsWith("darkness:shadow_")
? [["protection", 4], ["thorns", 3], ["unbreaking", 3]]
: [];
for (const [id, wantedLevel] of requested) {
const type = EnchantmentTypes.get(`minecraft:${id}`);
if (!type || component.hasEnchantment(type)) continue;
try {
component.addEnchantment({ type, level: Math.min(wantedLevel, type.maxLevel) });
changed = true;
} catch {
// A given enchantment may not be compatible with this custom item's slot.
}
}
return changed ? stack : undefined;
}
function enchantEquipped(player, slot) {
const equippable = player.getComponent("minecraft:equippable");
const stack = equippable?.getEquipment(slot);
if (!stack || !stack.typeId.startsWith("darkness:")) return;
const enchanted = applyLegalEnchantments(stack);
if (enchanted) equippable.setEquipment(slot, enchanted);
}
function passives(player) {
const mainhand = equipped(player, EquipmentSlot.Mainhand);
const necklace = hasItem(player, ITEM.necklace);
const mace = hasItem(player, ITEM.mace);
const sword = mainhand?.typeId === ITEM.sword;
if (necklace) {
player.addEffect("fire_resistance", 40, { amplifier: 0, showParticles: false });
player.addEffect("regeneration", 40, { amplifier: 1, showParticles: false });
}
if (mace) {
player.addEffect("resistance", 40, { amplifier: 2, showParticles: false });
for (const mob of mobsNear(player.dimension, player.location, 4)) {
mob.addEffect("slowness", 30, { amplifier: 0 });