#UI Flicker
1 messages · Page 1 of 1 (latest)
Drop the codes, let me sniff 👃 that if logics
import { world } from "@minecraft/server";
import { ActionFormData, uiManager } from "@minecraft/server-ui";
async function test1(player) {
const form = new ActionFormData()
.title("Test")
.body("Test")
.button("Test");
const response = await form.show(player);
if (response.selection === 0) {
console.log("Test1: Button clicked");
}
}
async function test2(player) {
const form = new ActionFormData()
.title("Test2")
.body("Test2")
.button("Test2");
const response = await form.show(player);
if (response.selection === 0) {
console.log("Test2: Button clicked");
}
}
world.afterEvents.playerPlaceBlock.subscribe(async (event) => {
const player = event.player;
await test1(player);
uiManager.closeAllForms(player);
await test2(player);
});
i have no idea if this is correct way to use uimanage btw
Try doing
test1(player);
await system.waitTicks(10); //delay by 10 ticks
uiManager.closeAllForms(player);
test2(player);
Oh sure, let me walk around in this digital room real quick
hehe
how hard would it be to make like a list of 7 items and each one spins in a rolling animation kinda
Imma try one real quick
import { world, system } from "@minecraft/server";
import { ActionFormData, uiManager } from "@minecraft/server-ui";
import { ChestFormData } from "../extensions/forms";
async function test1(player) {
const form = new ChestFormData('small')
.title("Test1")
.button("Test1");
form.pattern([
'xxxxXxxxx',
'xdedededx',
'xxxxXxxxx',
], {
x: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_red' },
X: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_lime' },
d: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'minecraft:diamond' },
e: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'minecraft:emerald' },
});
const response = await form.show(player);
if (response.selection === 0) {
}
}
async function test2(player) {
const form = new ChestFormData('small')
.title("Test2")
.button("Test2");
form.pattern([
'xxxxXxxxx',
'xedededex',
'xxxxXxxxx',
], {
x: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_red' },
X: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'textures/blocks/glass_lime' },
d: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'minecraft:diamond' },
e: { itemName: '', itemDesc: [], enchanted: false, stackAmount: 1, texture: 'minecraft:emerald' },
});
const response = await form.show(player);
if (response.selection === 0) {
}
}
world.afterEvents.playerPlaceBlock.subscribe(async (event) => {
const player = event.player;
test1(player);
await system.waitTicks(10);
uiManager.closeAllForms(player);
test2(player);
});
i also kind of want to make it so i can change the delay in between each ui change
any luck?
idk this seems a little to ehh
planned it out better in my head unless i can figure out how to do a real chest ui then i wont do a animated chest ui crate
I dont have the "no animation" UI for testing it with server form, but I kinda recreated the animation
reference:
const items = [
"§c[]",
"§6[]",
"§e[]",
"§a[]",
"§b[]",
"§d[]",
"§f[]"
]
world.afterEvents.playerPlaceBlock.subscribe(async (event) => {
let speed = rand(4,8);
const slowdown = rand(0.9,0.95)
const player = event.player;
let indexSpeed = 0;
let index = 0;
while (speed > 0.001) {
indexSpeed = (indexSpeed + speed) % items.length;
index = Math.floor(indexSpeed)
speed *= slowdown;
await system.waitTicks(1);
showRoll(player,index);
}
player.onScreenDisplay.setActionBar(`You won: ${items[index] ?? items[0]}`)
});
function showRoll(player,index) {
const leftRange = 3;
const leftRolls = [...(index-leftRange<0?items.slice(index-leftRange):[]),...items.slice(Math.max(index-leftRange,0),index)]
const rightRange = 3;
const rightRolls = [...items.slice(index+1,Math.min(index+rightRange+1,items.length)),...(index+rightRange>=items.length?items.slice(0,index+rightRange-items.length+1):[])]
const pick = items[index] ?? items[0]
player.onScreenDisplay.setActionBar(`${leftRolls.join("§r§8 | ")} §f> ${pick}§r §f< §8${rightRolls.join("§r§8 | ")}`)
}
function rand(a,b) {
return Math.random()*(a-b)+b
}