Skip to content

Commit 668b636

Browse files
committed
working player skin in inventory
1 parent d73d57c commit 668b636

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

lib/server.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const netApi = require('./proxy.js')
44
const port = process.env.PORT || 8080
55
const cors = require('cors')
66
const axios = require('axios');
7+
const atob = require('atob');
78

89
app.use(cors())
910
app.use(netApi({ allowOrigin: '*' }))
@@ -28,12 +29,21 @@ app.get("/getId",(req,res,next)=>{
2829

2930
app.get("/getSkin",(req,res,next)=>{
3031
axios.get(`https://sessionserver.mojang.com/session/minecraft/profile/${req.query.id}?legacy=true`,{responseType: 'json'})
31-
.then(function (response) {
32-
res.json(response.data)
33-
})
34-
.catch(function (error) {
35-
res.send("ERR")
36-
})
32+
.then(function (response) {
33+
var url=JSON.parse(atob(response.data.properties[0].value)).textures.SKIN.url
34+
axios.get(url,{responseType: 'arraybuffer'})
35+
.then(function (response) {
36+
var headers = {'Content-Type': 'image/jpeg'};
37+
res.writeHead(200, headers);
38+
res.end(response.data, 'binary');
39+
})
40+
.catch(function (error) {
41+
res.send("ERR")
42+
})
43+
})
44+
.catch(function (error) {
45+
res.send("ERR")
46+
})
3747
})
3848

3949
app.listen(port, () => {

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"node": "14.x"
2929
},
3030
"dependencies": {
31+
"atob": "^2.1.2",
3132
"axios": "^0.24.0",
3233
"body-parser": "^1.19.0",
3334
"cors": "^2.8.5",

src/scripts/Setup.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Stats from 'three/examples/jsm/libs/stats.module.js'
22
import * as dat from 'three/examples/jsm/libs/dat.gui.module.js'
3-
import { WebGLRenderer, Scene, PerspectiveCamera, AmbientLight } from 'three'
3+
import { WebGLRenderer, Scene, PerspectiveCamera, AmbientLight, TextureLoader } from 'three'
44
import { DistanceBasedFog } from './rendering/DistanceBasedFog.js'
55
import { UrlParams } from './UrlParams.js'
66
import { gpuInfo } from './additional/gpuInfo.js'
@@ -45,7 +45,7 @@ function Setup (game) {
4545
UrlParams(game)
4646
console.warn(gpuInfo())
4747
game.socket = new Socket(game)
48-
game.pii = new PlayerInInventory(game)
48+
game.pii = new PlayerInInventory(game)
4949
game.bb = new BlockBreak(game)
5050
game.bp = new BlockPlace(game)
5151
game.world = new World(game)
@@ -81,20 +81,20 @@ function Setup (game) {
8181
if(id!=="ERR"){
8282
console.log(`UUID: ${id}`)
8383
//SKIN
84-
fetch(`${document.location.protocol}//${hostname}:${port}/getSkin?id=${id}`)
85-
.then(response => response.json())
86-
.then(data => {
87-
// console.log(data)
88-
const nd=JSON.parse(atob(data.properties[0].value))
89-
// console.log(nd)
90-
console.log(`SKIN: ${nd.textures.SKIN.url}`)
91-
});
84+
game.skinUrl=`${document.location.protocol}//${hostname}:${port}/getSkin?id=${id}`
85+
console.log(game.skinUrl)
86+
new TextureLoader().load(game.skinUrl, (texture) => {
87+
game.pii.setup(texture)
88+
})
89+
9290
}else{
9391
console.log("UUID not found!")
92+
game.pii.setup(game.al.get('playerTex'))
9493
}
9594
});
9695
}
9796
});
97+
9898
game.distanceBasedFog.addShaderToMaterials([
9999
game.world.material,
100100
game.ent.mobMaterial,

src/scripts/gui/PlayerInInventory.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ class PlayerInInventory {
1919
this.scene.background = new Color('black')
2020
const light = new AmbientLight(0xffffff)
2121
this.scene.add(light)
22-
const player = this.game.al.get('player')
23-
const playerTex = this.game.al.get('playerTex')
24-
playerTex.magFilter = NearestFilter
25-
player.children[0].material.map = playerTex
22+
}
23+
24+
setup (texture) {
25+
const player = this.game.al.get('player')
26+
texture.magFilter = NearestFilter
27+
player.children[0].material.map = texture
2628
this.scene.add(player)
2729
this.camera = new PerspectiveCamera(70, 140 / 204, 0.1, 1000)
2830
this.camera.rotation.order = 'YXZ'
@@ -50,7 +52,7 @@ class PlayerInInventory {
5052
wychX * top)
5153
}
5254
})
53-
}
55+
}
5456

5557
render () {
5658
return this.renderer.render(this.scene, this.camera)

0 commit comments

Comments
 (0)