mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-27 13:49:55 +00:00
Skin: debloat geometry in constructor directly
This commit is contained in:
parent
89242543b9
commit
2720ff9607
@ -160,7 +160,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
|
|||||||
*/
|
*/
|
||||||
public function setSkin(Skin $skin) : void{
|
public function setSkin(Skin $skin) : void{
|
||||||
$this->skin = $skin;
|
$this->skin = $skin;
|
||||||
$this->skin->debloatGeometryData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,7 @@ use function implode;
|
|||||||
use function in_array;
|
use function in_array;
|
||||||
use function json_decode;
|
use function json_decode;
|
||||||
use function json_encode;
|
use function json_encode;
|
||||||
|
use function json_last_error_msg;
|
||||||
use function strlen;
|
use function strlen;
|
||||||
|
|
||||||
class Skin{
|
class Skin{
|
||||||
@ -58,7 +59,22 @@ class Skin{
|
|||||||
if($capeData !== "" and strlen($capeData) !== 8192){
|
if($capeData !== "" and strlen($capeData) !== 8192){
|
||||||
throw new \InvalidArgumentException("Invalid cape data size " . strlen($capeData) . " bytes (must be exactly 8192 bytes)");
|
throw new \InvalidArgumentException("Invalid cape data size " . strlen($capeData) . " bytes (must be exactly 8192 bytes)");
|
||||||
}
|
}
|
||||||
//TODO: validate geometry
|
|
||||||
|
if($geometryData !== ""){
|
||||||
|
$decodedGeometry = json_decode($geometryData);
|
||||||
|
if($decodedGeometry === false){
|
||||||
|
throw new \InvalidArgumentException("Invalid geometry data (" . json_last_error_msg() . ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hack to cut down on network overhead due to skins, by un-pretty-printing geometry JSON.
|
||||||
|
*
|
||||||
|
* Mojang, some stupid reason, send every single model for every single skin in the selected skin-pack.
|
||||||
|
* Not only that, they are pretty-printed.
|
||||||
|
* TODO: find out what model crap can be safely dropped from the packet (unless it gets fixed first)
|
||||||
|
*/
|
||||||
|
$geometryData = json_encode($decodedGeometry);
|
||||||
|
}
|
||||||
|
|
||||||
$this->skinId = $skinId;
|
$this->skinId = $skinId;
|
||||||
$this->skinData = $skinData;
|
$this->skinData = $skinData;
|
||||||
@ -101,17 +117,4 @@ class Skin{
|
|||||||
public function getGeometryData() : string{
|
public function getGeometryData() : string{
|
||||||
return $this->geometryData;
|
return $this->geometryData;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Hack to cut down on network overhead due to skins, by un-pretty-printing geometry JSON.
|
|
||||||
*
|
|
||||||
* Mojang, some stupid reason, send every single model for every single skin in the selected skin-pack.
|
|
||||||
* Not only that, they are pretty-printed.
|
|
||||||
* TODO: find out what model crap can be safely dropped from the packet (unless it gets fixed first)
|
|
||||||
*/
|
|
||||||
public function debloatGeometryData() : void{
|
|
||||||
if($this->geometryData !== ""){
|
|
||||||
$this->geometryData = (string) json_encode(json_decode($this->geometryData));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user