Skin: debloat geometry in constructor directly

This commit is contained in:
Dylan K. Taylor 2019-05-27 16:45:55 +01:00
parent 89242543b9
commit 2720ff9607
2 changed files with 17 additions and 15 deletions

View File

@ -160,7 +160,6 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
*/
public function setSkin(Skin $skin) : void{
$this->skin = $skin;
$this->skin->debloatGeometryData();
}
/**

View File

@ -27,6 +27,7 @@ use function implode;
use function in_array;
use function json_decode;
use function json_encode;
use function json_last_error_msg;
use function strlen;
class Skin{
@ -58,7 +59,22 @@ class Skin{
if($capeData !== "" and strlen($capeData) !== 8192){
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->skinData = $skinData;
@ -101,17 +117,4 @@ class Skin{
public function getGeometryData() : string{
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));
}
}
}