mirror of
https://github.com/PrismarineJS/prismarine-web-client.git
synced 2024-11-24 08:37:51 -05:00
Updatable inventory
This commit is contained in:
parent
68468119e7
commit
d62ecd6b2e
4 changed files with 29 additions and 38 deletions
2
index.js
2
index.js
|
@ -316,7 +316,7 @@ async function connect (options) {
|
|||
renderer.domElement.mozRequestPointerLock ||
|
||||
renderer.domElement.webkitRequestPointerLock
|
||||
document.addEventListener('mousedown', (e) => {
|
||||
if (!chat.inChat && !gameMenu.inMenu) {
|
||||
if (!chat.inChat && !gameMenu.inMenu && !inventoryMenu.inMenu) {
|
||||
renderer.domElement.requestPointerLock()
|
||||
}
|
||||
})
|
||||
|
|
|
@ -96,7 +96,15 @@ class Inventory extends LitElement {
|
|||
return new Item(this.type, this.count)
|
||||
}
|
||||
}
|
||||
inventory['inventoryItems'] = bot.inventory.slots.slice(bot.inventory.inventoryStart, bot.inventory.inventoryEnd + 1).map(slot => slot ? new Item(slot ? slot.name : 'air', slot ? slot.count : 0) : new Item('air', ''))
|
||||
inventory.inventoryItems = bot.inventory.slots.slice(bot.inventory.inventoryStart, bot.inventory.inventoryEnd + 1).map(slot => slot ? new Item(slot ? slot.name : 'air', slot ? slot.count : 0) : new Item('air', ''))
|
||||
bot.inventory.on('updateSlot', (slot, _oldItem, newItem) => {
|
||||
if (newItem) {
|
||||
inventory.inventoryItems[slot - bot.inventory.inventoryStart] = new Item(newItem.name, newItem.count)
|
||||
} else {
|
||||
inventory.inventoryItems[slot - bot.inventory.inventoryStart] = new Item('air', '')
|
||||
}
|
||||
inventory.needsUpdate = true
|
||||
})
|
||||
}
|
||||
|
||||
render () {
|
||||
|
|
|
@ -4,11 +4,7 @@ const invspritePositions = require('../../invsprite.json')
|
|||
|
||||
globalThis.layouts = layouts
|
||||
|
||||
if (window.location.href.includes('127.0.0.1')) {
|
||||
var IMAGE_ROOT = 'textures/'
|
||||
} else {
|
||||
var IMAGE_ROOT = 'https://raw.githubusercontent.com/PrismarineJS/minecraft-assets/master/data/1.16.4/'
|
||||
}
|
||||
const IMAGE_ROOT = 'https://raw.githubusercontent.com/PrismarineJS/minecraft-assets/master/data/1.16.4/'
|
||||
|
||||
function patchPath (path) {
|
||||
if (IMAGE_ROOT.includes('.com')) { path = path.replace('block/', 'blocks/'); path = path.replace('item/', 'items/') }
|
||||
|
@ -17,37 +13,24 @@ function patchPath(path) {
|
|||
return path
|
||||
}
|
||||
|
||||
window.loadedImageBlobs = {}
|
||||
const images = []
|
||||
|
||||
const images = [
|
||||
'item/brick',
|
||||
'block/brain_coral',
|
||||
'item/redstone',
|
||||
'block/powered_rail_on',
|
||||
'block/bookshelf',
|
||||
'item/compass_00',
|
||||
'item/lava_bucket',
|
||||
'item/apple',
|
||||
'item/iron_axe',
|
||||
'item/golden_sword',
|
||||
'item/glass_bottle',
|
||||
'item/chest_minecart',
|
||||
]
|
||||
|
||||
for (const win in layouts) {
|
||||
for (const win in layouts) { // Preload layouts
|
||||
const val = layouts[win]
|
||||
for (const key in val.with) {
|
||||
const path = val.with[key].path
|
||||
if (path && !images.includes(path)) {
|
||||
images.push(path);
|
||||
images.push(path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadAllImagesWeb() {
|
||||
for (let path of images) {
|
||||
var img = new Image(); // Create new img element
|
||||
img.src = patchPath(IMAGE_ROOT + path) + '.png'; // Set source path
|
||||
const loadedImageBlobs = [] // Caching array
|
||||
|
||||
function loadAllImagesWeb () { // Preload all images
|
||||
for (const path of images) {
|
||||
const img = new window.Image() // Create new img element
|
||||
img.src = patchPath(IMAGE_ROOT + path) + '.png' // Set source path
|
||||
img.onload = function () {
|
||||
loadedImageBlobs[path] = this
|
||||
}
|
||||
|
@ -55,9 +38,9 @@ function loadAllImagesWeb() {
|
|||
}
|
||||
|
||||
function loadRuntimeImage (atPath) {
|
||||
var img = new Image(); // Create new img element
|
||||
const img = new window.Image() // Create new img element
|
||||
// if (IMAGE_ROOT.includes('.com')) {atPath = atPath.replace('block/', 'blocks/');atPath=atPath.replace('item/', 'items/')}
|
||||
img.src = patchPath(IMAGE_ROOT + atPath) + '.png'; // Set source path
|
||||
img.src = patchPath(IMAGE_ROOT + atPath) + '.png' // Set source path
|
||||
img.style.imageRendering = 'pixelated'
|
||||
// img.onload = function () {
|
||||
// loadedImageBlobs[path] = this
|
||||
|
@ -66,7 +49,7 @@ function loadRuntimeImage(atPath) {
|
|||
}
|
||||
|
||||
export function getImage (resource) {
|
||||
console.log('getImage triggered with arguments:', resource)
|
||||
// console.log('getImage triggered with arguments:', resource)
|
||||
if ((resource.type ?? 'gui') !== 'item') { // nullishly coalesce to 'gui' because spec says to assume gui if unspecified. Run old code if it isn't an item because the new code is for items lol
|
||||
let path = patchPath(resource.path)
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
"express": "^4.17.1",
|
||||
"ismobilejs": "^1.1.1",
|
||||
"lit": "^2.0.2",
|
||||
"minecraft-inventory-gui": "github:AwesomestCode/prismarine-inventory-gui",
|
||||
"minecraft-inventory-gui": "file:////Users/owl/Documents/GitHub/prismarine-inventory-gui/",
|
||||
"net-browserify": "PrismarineJS/net-browserify",
|
||||
"querystring": "^0.2.1",
|
||||
"url": "^0.11.0"
|
||||
|
|
Loading…
Reference in a new issue