Use item atlas
This commit is contained in:
parent
f0294abf9e
commit
267afce9db
6 changed files with 4838 additions and 50 deletions
BIN
assets/invsprite.png
Normal file
BIN
assets/invsprite.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.2 MiB |
|
@ -6,7 +6,6 @@
|
|||
<link rel="favicon" href="favicon.ico">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<img id="crosshair" src="extra-textures/icons.png" style="display: none;">
|
||||
<div id="chat-wrapper" class="chat-wrapper chat-display-wrapper" style="display: none;">
|
||||
<div class="chat" id="chat">
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
const { LitElement, html, css } = require('lit-element')
|
||||
const invsprite = require('./invsprite.json')
|
||||
|
||||
class HotBar extends LitElement {
|
||||
updated (changedProperties) {
|
||||
|
@ -13,8 +14,6 @@ class HotBar extends LitElement {
|
|||
init () {
|
||||
this.reloadHotbar()
|
||||
this.reloadHotbarSelected(0)
|
||||
const baseUrl = window.location.href.match(/(^[^#]*)/)[0]
|
||||
const self = this
|
||||
document.addEventListener('wheel', (e) => {
|
||||
const newSlot = ((this.bot.quickBarSlot + Math.sign(e.deltaY)) % 9 + 9) % 9
|
||||
this.reloadHotbarSelected(newSlot)
|
||||
|
@ -24,41 +23,20 @@ class HotBar extends LitElement {
|
|||
if (slot >= this.bot.inventory.hotbarStart + 9) return
|
||||
if (slot < this.bot.inventory.hotbarStart) return
|
||||
|
||||
// eslint-disable-next-line no-undef
|
||||
const http = new XMLHttpRequest()
|
||||
let url = newItem ? baseUrl + 'textures/' + this.viewerVersion + '/items/' + newItem.name + '.png' : ''
|
||||
http.open('HEAD', url)
|
||||
|
||||
http.onreadystatechange = function () {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 404) {
|
||||
url = newItem ? baseUrl + 'textures/' + self.viewerVersion + '/blocks/' + newItem.name + '.png' : ''
|
||||
}
|
||||
self.shadowRoot.getElementById('hotbar-' + (slot - self.bot.inventory.hotbarStart)).src = url
|
||||
}
|
||||
}
|
||||
http.send()
|
||||
const sprite = newItem ? invsprite[newItem.name] : invsprite.air
|
||||
const slotImage = this.shadowRoot.getElementById('hotbar-' + (slot - this.bot.inventory.hotbarStart))
|
||||
slotImage.style['background-position-x'] = `-${sprite.x * 2}px`
|
||||
slotImage.style['background-position-y'] = `-${sprite.y * 2}px`
|
||||
})
|
||||
}
|
||||
|
||||
async reloadHotbar () {
|
||||
const baseUrl = window.location.href.match(/(^[^#]*)/)[0]
|
||||
const self = this
|
||||
for (let i = 0; i < 9; i++) {
|
||||
// eslint-disable-next-line no-undef
|
||||
const http = new XMLHttpRequest()
|
||||
let url = this.bot.inventory.slots[this.bot.inventory.hotbarStart + i] ? baseUrl + 'textures/' + this.viewerVersion + '/items/' + this.bot.inventory.slots[this.bot.inventory.hotbarStart + i].name + '.png' : ''
|
||||
http.open('HEAD', url)
|
||||
|
||||
http.onreadystatechange = function () {
|
||||
if (this.readyState === this.DONE) {
|
||||
if (this.status === 404) {
|
||||
url = self.bot.inventory.slots[self.bot.inventory.hotbarStart + i] ? baseUrl + 'textures/' + self.viewerVersion + '/blocks/' + self.bot.inventory.slots[self.bot.inventory.hotbarStart + i].name + '.png' : ''
|
||||
}
|
||||
self.shadowRoot.getElementById('hotbar-' + i).src = url
|
||||
}
|
||||
}
|
||||
http.send()
|
||||
const item = this.bot.inventory.slots[this.bot.inventory.hotbarStart + i]
|
||||
const sprite = item ? invsprite[item.name] : invsprite.air
|
||||
const slotImage = this.shadowRoot.getElementById('hotbar-' + i)
|
||||
slotImage.style['background-position-x'] = `-${sprite.x * 2}px`
|
||||
slotImage.style['background-position-y'] = `-${sprite.y * 2}px`
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -126,10 +104,12 @@ class HotBar extends LitElement {
|
|||
}
|
||||
|
||||
.hotbar-item {
|
||||
height: calc(16px * 4);
|
||||
width: calc(16px * 4);
|
||||
margin-top: calc(3px * 4);
|
||||
margin-left: calc(3px * 4);
|
||||
height: 64px;
|
||||
width: 64px;
|
||||
margin-top: 12px;
|
||||
margin-left: 12px;
|
||||
background-image: url('invsprite.png');
|
||||
background-size: 2048px auto;
|
||||
}
|
||||
`
|
||||
}
|
||||
|
@ -140,15 +120,15 @@ class HotBar extends LitElement {
|
|||
<img id="hotbar-image" src="textures/1.16.4/gui/widgets.png">
|
||||
<img id="hotbar-highlight" src="textures/1.16.4/gui/widgets.png">
|
||||
<div id="hotbar-items-wrapper">
|
||||
<img class="hotbar-item" id="hotbar-0" src="textures/1.16.4/blocks/stone.png">
|
||||
<img class="hotbar-item" id="hotbar-1" src="textures/1.16.4/items/chain.png">
|
||||
<img class="hotbar-item" id="hotbar-2" src="textures/1.16.4/items/flint_and_steel.png">
|
||||
<img class="hotbar-item" id="hotbar-3" src="textures/1.16.4/items/firework_rocket.png">
|
||||
<img class="hotbar-item" id="hotbar-4" src="textures/1.16.4/items/golden_carrot.png">
|
||||
<img class="hotbar-item" id="hotbar-5" src="textures/1.16.4/items/netherite_pickaxe.png">
|
||||
<img class="hotbar-item" id="hotbar-6" src="textures/1.16.4/items/netherite_pickaxe.png">
|
||||
<img class="hotbar-item" id="hotbar-7" src="textures/1.16.4/items/netherite_axe.png">
|
||||
<img class="hotbar-item" id="hotbar-8" src="textures/1.16.4/items/netherite_shovel.png">
|
||||
<img class="hotbar-item" id="hotbar-0">
|
||||
<img class="hotbar-item" id="hotbar-1">
|
||||
<img class="hotbar-item" id="hotbar-2">
|
||||
<img class="hotbar-item" id="hotbar-3">
|
||||
<img class="hotbar-item" id="hotbar-4">
|
||||
<img class="hotbar-item" id="hotbar-5">
|
||||
<img class="hotbar-item" id="hotbar-6">
|
||||
<img class="hotbar-item" id="hotbar-7">
|
||||
<img class="hotbar-item" id="hotbar-8">
|
||||
</div>
|
||||
</div>
|
||||
`
|
||||
|
|
4812
lib/invsprite.json
Normal file
4812
lib/invsprite.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -91,4 +91,3 @@ body {
|
|||
-ms-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,9 +64,7 @@ const config = {
|
|||
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/textures/'), to: './textures/' },
|
||||
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/worker.js'), to: './' },
|
||||
{ from: path.join(__dirname, '/node_modules/prismarine-viewer/public/supportedVersions.json'), to: './' },
|
||||
{ from: path.join(__dirname, 'assets/minecraftia.woff'), to: './' },
|
||||
{ from: path.join(__dirname, 'assets/mojangles.ttf'), to: './' },
|
||||
{ from: path.join(__dirname, 'assets/prismarinejs.ico'), to: './favicon.ico' },
|
||||
{ from: path.join(__dirname, 'assets/'), to: './' },
|
||||
{ from: path.join(__dirname, 'extra-textures/'), to: './extra-textures/' }
|
||||
]
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue