Fixed crafting (cannot test enchanting)

This commit is contained in:
Dylan K. Taylor 2016-10-04 20:08:43 +01:00
parent ff40c0a070
commit 85c50731f8
2 changed files with 19 additions and 20 deletions

View File

@ -58,12 +58,12 @@ class CraftingDataPacket extends DataPacket{
} }
private static function writeShapelessRecipe(ShapelessRecipe $recipe, BinaryStream $stream){ private static function writeShapelessRecipe(ShapelessRecipe $recipe, BinaryStream $stream){
$stream->putInt($recipe->getIngredientCount()); $stream->putUnsignedVarInt($recipe->getIngredientCount());
foreach($recipe->getIngredientList() as $item){ foreach($recipe->getIngredientList() as $item){
$stream->putSlot($item); $stream->putSlot($item);
} }
$stream->putInt(1); $stream->putUnsignedVarInt(1);
$stream->putSlot($recipe->getResult()); $stream->putSlot($recipe->getResult());
$stream->putUUID($recipe->getId()); $stream->putUUID($recipe->getId());
@ -72,8 +72,8 @@ class CraftingDataPacket extends DataPacket{
} }
private static function writeShapedRecipe(ShapedRecipe $recipe, BinaryStream $stream){ private static function writeShapedRecipe(ShapedRecipe $recipe, BinaryStream $stream){
$stream->putInt($recipe->getWidth()); $stream->putVarInt($recipe->getWidth());
$stream->putInt($recipe->getHeight()); $stream->putVarInt($recipe->getHeight());
for($z = 0; $z < $recipe->getHeight(); ++$z){ for($z = 0; $z < $recipe->getHeight(); ++$z){
for($x = 0; $x < $recipe->getWidth(); ++$x){ for($x = 0; $x < $recipe->getWidth(); ++$x){
@ -81,7 +81,7 @@ class CraftingDataPacket extends DataPacket{
} }
} }
$stream->putInt(1); $stream->putUnsignedVarInt(1);
$stream->putSlot($recipe->getResult()); $stream->putSlot($recipe->getResult());
$stream->putUUID($recipe->getId()); $stream->putUUID($recipe->getId());
@ -91,12 +91,13 @@ class CraftingDataPacket extends DataPacket{
private static function writeFurnaceRecipe(FurnaceRecipe $recipe, BinaryStream $stream){ private static function writeFurnaceRecipe(FurnaceRecipe $recipe, BinaryStream $stream){
if($recipe->getInput()->getDamage() !== 0){ //Data recipe if($recipe->getInput()->getDamage() !== 0){ //Data recipe
$stream->putInt(($recipe->getInput()->getId() << 16) | ($recipe->getInput()->getDamage())); $stream->putVarInt($recipe->getInput()->getDamage());
$stream->putVarInt($recipe->getInput()->getId());
$stream->putSlot($recipe->getResult()); $stream->putSlot($recipe->getResult());
return CraftingDataPacket::ENTRY_FURNACE_DATA; return CraftingDataPacket::ENTRY_FURNACE_DATA;
}else{ }else{
$stream->putInt($recipe->getInput()->getId()); $stream->putVarInt($recipe->getInput()->getId());
$stream->putSlot($recipe->getResult()); $stream->putSlot($recipe->getResult());
return CraftingDataPacket::ENTRY_FURNACE; return CraftingDataPacket::ENTRY_FURNACE;
@ -104,15 +105,15 @@ class CraftingDataPacket extends DataPacket{
} }
private static function writeEnchantList(EnchantmentList $list, BinaryStream $stream){ private static function writeEnchantList(EnchantmentList $list, BinaryStream $stream){
//TODO: check this works on 0.16 (cannot currently test)
$stream->putByte($list->getSize()); $stream->putByte($list->getSize());
for($i = 0; $i < $list->getSize(); ++$i){ for($i = 0; $i < $list->getSize(); ++$i){
$entry = $list->getSlot($i); $entry = $list->getSlot($i);
$stream->putInt($entry->getCost()); $stream->putUnsignedVarInt($entry->getCost());
$stream->putByte(count($entry->getEnchantments())); $stream->putUnsignedVarInt(count($entry->getEnchantments()));
foreach($entry->getEnchantments() as $enchantment){ foreach($entry->getEnchantments() as $enchantment){
$stream->putInt($enchantment->getId()); $stream->putUnsignedVarInt($enchantment->getId());
$stream->putInt($enchantment->getLevel()); $stream->putUnsignedVarInt($enchantment->getLevel());
} }
$stream->putString($entry->getRandomName()); $stream->putString($entry->getRandomName());
} }
@ -147,18 +148,16 @@ class CraftingDataPacket extends DataPacket{
public function encode(){ public function encode(){
$this->reset(); $this->reset();
$this->putInt(count($this->entries)); $this->putUnsignedVarInt(count($this->entries));
$writer = new BinaryStream(); $writer = new BinaryStream();
foreach($this->entries as $d){ foreach($this->entries as $d){
$entryType = self::writeEntry($d, $writer); $entryType = self::writeEntry($d, $writer);
if($entryType >= 0){ if($entryType >= 0){
$this->putInt($entryType); $this->putVarInt($entryType);
$this->putInt(strlen($writer->getBuffer()));
$this->put($writer->getBuffer()); $this->put($writer->getBuffer());
}else{ }else{
$this->putInt(-1); $this->putVarInt(-1);
$this->putInt(0);
} }
$writer->reset(); $writer->reset();

View File

@ -41,15 +41,15 @@ class CraftingEventPacket extends DataPacket{
public function decode(){ public function decode(){
$this->windowId = $this->getByte(); $this->windowId = $this->getByte();
$this->type = $this->getInt(); $this->type = $this->getVarInt();
$this->id = $this->getUUID(); $this->id = $this->getUUID();
$size = $this->getInt(); $size = $this->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){ for($i = 0; $i < $size and $i < 128; ++$i){
$this->input[] = $this->getSlot(); $this->input[] = $this->getSlot();
} }
$size = $this->getInt(); $size = $this->getUnsignedVarInt();
for($i = 0; $i < $size and $i < 128; ++$i){ for($i = 0; $i < $size and $i < 128; ++$i){
$this->output[] = $this->getSlot(); $this->output[] = $this->getSlot();
} }