Skip to content

Commit

Permalink
FIXED BACK BUTTON + Fixed GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
smell-of-curry committed Sep 20, 2022
1 parent 77c37d3 commit c7e7163
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
19 changes: 14 additions & 5 deletions scripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,21 @@ console.warn(`LOADING RUBEDO, START MS: ${Date.now()}`);
import { BLOCK_CONTAINERS, CHECK_SIZE } from "./config/moderation";
import { OBJECTIVES } from "./config/objectives";
import { BlockInventory } from "./modules/models/BlockInventory";
import { BlockLocation, Location, world } from "mojang-minecraft";
import {
BlockLocation,
ItemStack,
Location,
MinecraftItemTypes,
world,
} from "mojang-minecraft";
import { Database } from "./lib/Database/Database.js";
import { setTickInterval } from "./lib/Scheduling/utils.js";
import { PROTECTIONS } from "./config/protections";
import { MANAGERS } from "./config/managers";
import { COMMANDS } from "./config/commands";
import { PAGES } from "./config/chest";
import "./lib/Commands/index.js";
import "./lib/Chest GUI/index.js";

/**
* All the Database tables that are created
Expand All @@ -36,6 +44,11 @@ export let CONTAINER_LOCATIONS = {};
*/
export let NPC_LOCATIONS = [];

/**
* This is air as a item,
*/
export const AIR = new ItemStack(MinecraftItemTypes.stick, 0);

/**
* Converts a location to a block location
* @param {Location} loc a location to convert
Expand Down Expand Up @@ -96,10 +109,6 @@ for (const command of TABLES.config.get("commands") ?? COMMANDS) {
});
}

import "./lib/Commands/index.js";

import "./lib/Chest GUI/index.js";

for (const page of PAGES) {
import(`./modules/pages/${page}.js`).catch((error) => {
console.warn(`Error on Loading Page ${page}: ` + error + error.stack);
Expand Down
11 changes: 3 additions & 8 deletions scripts/lib/Chest GUI/Models/FillTypes.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {
Entity,
InventoryComponentContainer,
ItemStack,
MinecraftItemTypes,
} from "mojang-minecraft";
import { Entity, InventoryComponentContainer } from "mojang-minecraft";
import { AIR } from "../../../index.js";

/**
* Fills a entity with desired itmes
Expand All @@ -16,14 +12,13 @@ export function DefaultFill(entity, page, extras) {
* @type {InventoryComponentContainer}
*/
const container = entity.getComponent("minecraft:inventory").container;

for (let i = 0; i < container.size; i++) {
/**
* @type {import("./Page").Slot}
*/
const slot = page.slots[i];
if (!slot || !slot.item) {
container.setItem(i, new ItemStack(MinecraftItemTypes.air));
container.setItem(i, AIR);
continue;
}
container.setItem(i, slot.item.setComponents());
Expand Down
3 changes: 2 additions & 1 deletion scripts/lib/Chest GUI/Models/ItemGrabbedCallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export class ItemGrabbedCallback {
BackAction(amount = 1) {
if (this.gui.pageHistory.length < amount)
return new Error(`Tried to Go back to a page number that doesnt exist`);
const pageID = this.gui.pageHistory.slice(-1 - amount)[0];
console.warn(JSON.stringify(this.gui.pageHistory));
const pageID = this.gui.pageHistory.splice(-1 - amount)[0];
console.warn(JSON.stringify(this.gui.page.extras));
this.PageAction(pageID, this.gui.page.extras);
}
Expand Down
15 changes: 7 additions & 8 deletions scripts/lib/Chest GUI/database/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MinecraftItemTypes,
world,
} from "mojang-minecraft";
import { AIR } from "../../../index.js";

/**
* Minecraft Bedrock Item Database
Expand Down Expand Up @@ -41,13 +42,11 @@ export class ItemDatabase {
* @returns {Array<Entity>}
*/
get ENTITIES() {
return world
.getDimension("overworld")
.getEntities({
type: ENTITY_DATABSE_ID,
location: ENTITY_LOCATION,
tags: [this.TABLE_NAME],
});
return world.getDimension("overworld").getEntities({
type: ENTITY_DATABSE_ID,
location: ENTITY_LOCATION,
tags: [this.TABLE_NAME],
});
}

/**
Expand Down Expand Up @@ -140,7 +139,7 @@ export class ItemDatabase {
for (let i = 0; i < inv.size; i++) {
const item = inv.getItem(i);
if (!item || !item.getLore().includes(id)) continue;
inv.setItem(i, new ItemStack(MinecraftItemTypes.air));
inv.setItem(i, AIR);
return true;
}
}
Expand Down
35 changes: 26 additions & 9 deletions scripts/modules/pages/see.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
PlayerInventoryComponentContainer,
world,
} from "mojang-minecraft";
import { AIR } from "../../index.js";
import { BackButton, CloseGuiButton } from "../../lib/Chest GUI/Models/Buttons";
import { Item } from "../../lib/Chest GUI/Models/Item";
import { Page } from "../../lib/Chest GUI/Models/Page";
Expand Down Expand Up @@ -46,7 +47,7 @@ export function ViewPlayersFill(entity, page, extras) {
*/
const slot = page.slots[i];
if (!slot || !slot.item) {
container.setItem(i, new ItemStack(MinecraftItemTypes.air));
container.setItem(i, AIR);
continue;
}
container.setItem(i, slot.item.setComponents());
Expand Down Expand Up @@ -82,13 +83,13 @@ export function ViewPlayerInventoryFill(entity, page, extras) {
*/
const slot = page.slots[i];
if (!slot || !slot.item) {
container.setItem(i, new ItemStack(MinecraftItemTypes.air));
container.setItem(i, AIR);
continue;
}
container.setItem(i, slot.item.setComponents());
}
const EnderChestItem = new Item("minecraft:ender_chest", 1, 0, {
nameTag: `§eView §f${extras.name}§e Ender Chest\n§fNote: §cThis will not grab §lANY NBT!§r`,
nameTag: `§eView §f${extras?.name}§e Ender Chest\n§fNote: §cThis will not grab §lANY NBT!§r`,
});
container.setItem(49, EnderChestItem.setComponents());
page.slots[49] = {
Expand Down Expand Up @@ -153,12 +154,12 @@ export function ViewPlayerEnderChestFill(entity, page, extras) {
*/
const slot = page.slots[i];
if (!slot || !slot.item) {
container.setItem(i, new ItemStack(MinecraftItemTypes.air));
container.setItem(i, AIR);
continue;
}
container.setItem(i, slot.item.setComponents());
}
const player = [...world.getPlayers()].find((p) => p.name == extras.name);
const player = [...world.getPlayers()].find((p) => p.name == extras?.name);
if (!player) return;
/**
* the value of how many slots have been taken
Expand Down Expand Up @@ -212,8 +213,16 @@ new Page("moderation:see", 54, ViewPlayersFill)
ctx.SetAction();
}
)
.setButtonAtSlot(48, CloseGuiButton)
.setButtonAtSlot(50, BackButton);
.setSlots(
[50],
new Item("minecraft:arrow", 1, 0, {
nameTag: "§fBack",
}),
(ctx) => {
ctx.PageAction("home");
}
)
.setButtonAtSlot(48, CloseGuiButton);

new Page("moderation:see_inventory", 54, ViewPlayerInventoryFill)
.setSlots(
Expand All @@ -225,8 +234,16 @@ new Page("moderation:see_inventory", 54, ViewPlayerInventoryFill)
ctx.SetAction();
}
)
.setButtonAtSlot(48, CloseGuiButton)
.setButtonAtSlot(50, BackButton);
.setSlots(
[50],
new Item("minecraft:arrow", 1, 0, {
nameTag: "§fBack",
}),
(ctx) => {
ctx.PageAction("moderation:see");
}
)
.setButtonAtSlot(48, CloseGuiButton);

new Page("moderation:see_ender_chest", 54, ViewPlayerEnderChestFill)
.setSlots(
Expand Down

0 comments on commit c7e7163

Please sign in to comment.