На этом канале публикуются все истории (как и что я делаю в Майнкрафте).
Основной канал: https://t.me/botikdeadpriz
Post #87
115
БО @botikst
Showing posts older than #88 · Back to latest
import { system, world } from "@minecraft/server";
function checkiuseit(player) {
try {
const inventory = player.getComponent('inventory')?.container;
if (!inventory) return {bread: 0, chicken: 0};
let breadTotal = 0;
let chickenTotal = 0;
for (let i = 0; i < inventory.size; i++) {
const item = inventory.getItem(i);
if (item?.typeId === 'minecraft:bread') {
breadTotal += item.amount;
} else if (item?.typeId === 'minecraft:cooked_chicken') {
chickenTotal += item.amount;
}
}
return {bread: breadTotal, chicken: chickenTotal};
} catch {
return {bread: 0, chicken: 0};
}
}
const choic = new Map();
world.afterEvents.itemUse.subscribe(event => {
const player = event.source;
const item = event.itemStack;
if ((item.typeId === 'minecraft:bread' || item.typeId === 'minecraft:cooked_chicken') && player.isValid()) {
const currentCounts = checkiuseit(player);
choic.set(player.id, {
breadCount: currentCounts.bread,
chickenCount: currentCounts.chicken,
lastUsedItem: item.typeId,
startTick: system.currentTick
});
}
});
system.runInterval(() => {
const currentTick = system.currentTick;
for (const [playerId, data] of choic) {
const player = [...world.getPlayers()].find(p => p.id === playerId);
if (!player || !player.isValid()) {
choic.delete(playerId);
continue;
}
if (currentTick - data.startTick > 600) {
choic.delete(playerId);
continue;
}
const currentCounts = checkiuseit(player);
if (currentCounts.bread < data.breadCount && data.lastUsedItem === 'minecraft:bread') {
player.runCommandAsync('title @a title 1');
choic.delete(playerId);
} else if (currentCounts.chicken < data.chickenCount && data.lastUsedItem === 'minecraft:cooked_chicken') {
player.runCommandAsync('title @a title 2');
choic.delete(playerId);
}
}
}, 5);import { world, system } from "@minecraft/server";
const off = { x: -0.75, y: 0, z: -3 };
const stp = 0.1;
const min = 0.5;
const max = 3.5;
const ez = 0.1;
function gdv(rot) {
const yaw = rot.y * (Math.PI / 180);
const pit = rot.x * (Math.PI / 180);
const fwd = {
x: -Math.sin(yaw) * Math.cos(pit),
y: -Math.sin(pit),
z: Math.cos(yaw) * Math.cos(pit)
};
const up = { x: 0, y: 1, z: 0 };
const cx = up.y * fwd.z - up.z * fwd.y;
const cy = up.z * fwd.x - up.x * fwd.z;
const cz = up.x * fwd.y - up.y * fwd.x;
const len = Math.sqrt(cx*cx + cy*cy + cz*cz);
const rgt = {
x: cx / len,
y: cy / len,
z: cz / len
};
return { fwd, rgt };
}
function fsp(plr, eye, dir, tgt) {
const dv = {
x: tgt.x - eye.x,
y: tgt.y - eye.y,
z: tgt.z - eye.z
};
const dst = Math.sqrt(dv.x**2 + dv.y**2 + dv.z**2);
if (dst < 0.01) return eye;
const dn = {
x: dv.x / dst,
y: dv.y / dst,
z: dv.z / dst
};
let lst = eye;
const cd = Math.min(dst, max);
for (let d = min; d <= cd; d += stp) {
const cp = {
x: eye.x + dn.x * d,
y: eye.y + dn.y * d,
z: eye.z + dn.z * d
};
const blk = plr.dimension.getBlock(cp);
if (blk && blk.typeId !== "minecraft:air") {
return {
x: eye.x + dn.x * (d - stp),
y: eye.y + dn.y * (d - stp),
z: eye.z + dn.z * (d - stp)
};
}
lst = cp;
}
return lst;
}
system.runInterval(() => {
const plrs = world.getPlayers({ tags: [ "v" ] });
for (const plr of plrs) {
try {
const eye = plr.getHeadLocation();
const rot = plr.getRotation();
const { fwd, rgt } = gdv(rot);
const tgt = {
x: eye.x + rgt.x * off.x + fwd.x * off.z,
y: eye.y + rgt.y * off.x + fwd.y * off.z,
z: eye.z + rgt.z * off.x + fwd.z * off.z
};
const saf = fsp(
plr,
eye,
{ x: tgt.x - eye.x, y: tgt.y - eye.y, z: tgt.z - eye.z },
tgt
);
plr.runCommand(
`camera @s set minecraft:free ease ${ez} linear ` +
`pos ${saf.x.toFixed(2)} ${saf.y.toFixed(2)} ${saf.z.toFixed(2)} ` +
`rot ${rot.x} ${rot.y}`
);
} catch (e) {
console.warn("Camera error: " + e);
}
}
});Forwarded from Dd
import { world, system, Player } from "@minecraft/server";
function rot(player) {
const rotation = player.getRotation();
return {
y: Math.round(rotation.y * 10) / 10,
x: Math.round(rotation.x * 10) / 10
};
}
system.runInterval(() => {
const players = world.getPlayers();
for (const player of players) {
const rotation = rot(player);
player.runCommandAsync(`title @a actionbar y ${rotation.y} x ${rotation.x}`);
if (rotation.y <= -70.0 && rotation.y >= -89.9) {
player.runCommandAsync(`title @a title ВВЕРХ`);
}
}
});import { world, system } from "@minecraft/server";
function scriptik() {
const players = world.getPlayers();
for (const player of players) {
if (player.isSneaking) { //проверка шифта
player.runCommandAsync("title @a actionbar Вы сидите");
} else { //если игрок не сидит, то. . .
player.runCommandAsync("title @a actionbar Вы стоите");
}
}
system.runTimeout(scriptik, 1);
}
system.runTimeout(scriptik, 1);import { world, system } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
function UI(player) {
const form = new ActionFormData();
form.title("меню");
form.body(`чтобы появилась кнопка, выдайте себе тег "custom" и кнопка появится в меню`);
form.button("кнопка без тега");
if (player.hasTag("custom")) {
form.button("кнопка с тегом №1");
}
if (player.hasTag("cus")) {
form.button("кнопка с тегом №2");
}
form.show(player).then(result => {
if (result.selection === undefined) return;
if (result.selection === 0) {
player.sendMessage("Вы нажали кнопку без тега");
} else if (result.selection === 1 && player.hasTag("custom")) {
player.sendMessage("Вы нажали кнопку с тегом №1");
} else if (result.selection === 2 && player.hasTag("cus")) {
player.sendMessage("Вы нажали кнопку с тегом №2");
}
});
}
world.beforeEvents.itemUse.subscribe((eventData) => {
if (eventData.itemStack?.typeId === "minecraft:stick") {
let player = eventData.source;
system.run(() => {
UI(player);
});
}
});{
"format_version": "1.20.60",
"minecraft:block": {
"description": {
"identifier": "custom:block",
"menu_category": {
"category": "construction"
}
},
"components": {
"minecraft:destructible_by_mining": {
"seconds_to_destroy": 3.0
},
"minecraft:destructible_by_explosion": {
"explosion_resistance": 3.0
},
"minecraft:friction": 0.4,
"minecraft:map_color": "#FFFFFF",
"minecraft:light_dampening": 0,
"minecraft:light_emission": 4,
"minecraft:loot": "loot_tables/blocks/custom_block.json",
"minecraft:collision_box": {
"origin": [
-8.0,
0.0,
-8.0
],
"size": [
16.0,
16.0,
16.0
]
},
"minecraft:selection_box": {
"origin": [
-8.0,
0.0,
-8.0
],
"size": [
16.0,
16.0,
16.0
]
},
"minecraft:material_instances": {
"*": {
"texture": "custom_block",
"render_method": "opaque"
}
},
"tags": [
"wood"
],
"minecraft:custom_components": [
"custom_block:trigger"
]
},
"events": {
},
"permutations": [
]
}
}