Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.1.5 #3

Merged
merged 5 commits into from
Nov 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update main.js
Fixed formatting
  • Loading branch information
FondUnicycle authored Nov 29, 2022
commit 71ead925485ab0f9f8058f02534b6616a3e04542
153 changes: 49 additions & 104 deletions Bingo[BP]/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,121 +1,66 @@
import { system, world } from '@minecraft/server';

import * as Game from './game.js';

import * as BookUI from './ui_screens.js';

const overworld = world.getDimension('overworld');

let host;

let hostSelected = false;

const excludeJoinedPlayers = { excludeTags: ['joined'] };

let ticks = 0;

world.events.itemUse.subscribe( itemUseData => {

let item = itemUseData.item; let player = itemUseData.source;

if(item.typeId === 'fond:bingo_card' && player.getItemCooldown('card') === 0) {

switch (Game.gameRunning || Game.winnerFound) {

case false:

Game.setNewCard(player);

break;

case true:

if(player.card) {

if(player.card.isDisplaying) {

player.card.display(false);

}

else {

player.card.display(true);

}

}

else {

overworld.runCommandAsync(`w "${player.nameTag}" §b§lSorry, players can't set a card while a game is running.`)

}

break;

}

}

if (item.typeId === 'fond:info_book' && !Game.gameRunning) {

BookUI.mainScreen(player);

}

let item = itemUseData.item;
let player = itemUseData.source;
if(item.typeId === 'fond:bingo_card' && player.getItemCooldown('card') === 0) {
switch (Game.gameRunning || Game.winnerFound) {
case false:
Game.setNewCard(player);
break;
case true:
if(player.card) {
if(player.card.isDisplaying) {
player.card.display(false);
}
else {
player.card.display(true);
}
}
else {
overworld.runCommandAsync(`w "${player.nameTag}" §b§lSorry, players can't set a card while a game is running.`)
}
break;
}
}
if (item.typeId === 'fond:info_book' && !Game.gameRunning) {
BookUI.mainScreen(player);
}
});

function joinEvent() {



if(!hostSelected) {

try {

for(const p of [...world.getPlayers()]) {

p.addTag('host');

host = p;

break;

}

overworld.runCommandAsync('gamerule doDaylightCycle false');

if(host) hostSelected = true;

} catch {}

}

if(!Game.gameRunning) {

try {

for (const player of [...world.getPlayers(excludeJoinedPlayers)]) {

overworld.runCommandAsync('gamerule sendCommandFeedback false');

player.runCommandAsync('gamemode adventure');

player.addTag('joined');

player.runCommandAsync('give @s fond:bingo_card 1 0 {"minecraft:keep_on_death":{},"minecraft:item_lock":{"mode":"lock_in_inventory"}}');

player.runCommandAsync('give @s fond:info_book');

overworld.runCommandAsync('gamerule sendCommandFeedback true');

}

} catch {}

}


if(!hostSelected) {
try {
for(const p of [...world.getPlayers()]) {
p.addTag('host');
host = p;
break;
}
overworld.runCommandAsync('gamerule doDaylightCycle false');
if(host) hostSelected = true;
} catch {}
}
if(!Game.gameRunning) {
try {
for (const player of [...world.getPlayers(excludeJoinedPlayers)]) {
overworld.runCommandAsync('gamerule sendCommandFeedback false');
player.runCommandAsync('gamemode adventure');
player.addTag('joined');
player.runCommandAsync('give @s fond:bingo_card 1 0 {"minecraft:keep_on_death":{},"minecraft:item_lock":{"mode":"lock_in_inventory"}}');
player.runCommandAsync('give @s fond:info_book');
overworld.runCommandAsync('gamerule sendCommandFeedback true');
}
} catch {}
}
};

system.runSchedule(joinEvent, 1);