40 private const TAG_FIRST_INPUT_ITEM =
"Item1";
41 private const TAG_SECOND_INPUT_ITEM =
"Item2";
42 private const TAG_THIRD_INPUT_ITEM =
"Item3";
43 private const TAG_FOURTH_INPUT_ITEM =
"Item4";
45 private const TAG_FIRST_COOKING_TIME =
"ItemTime1";
46 private const TAG_SECOND_COOKING_TIME =
"ItemTime2";
47 private const TAG_THIRD_COOKING_TIME =
"ItemTime3";
48 private const TAG_FOURTH_COOKING_TIME =
"ItemTime4";
52 private array $cookingTimes = [];
55 parent::__construct($world, $pos);
57 $this->inventory->getListeners()->add(CallbackInventoryListener::onAnyChange(
58 static function(
Inventory $unused) use ($world, $pos) :
void{
60 if($block instanceof BlockCampfire){
68 return $this->inventory;
72 return $this->inventory;
80 return $this->cookingTimes;
88 $this->cookingTimes = $cookingTimes;
91 public function readSaveData(
CompoundTag $nbt) : void{
93 $listeners = $this->inventory->getListeners()->toArray();
94 $this->inventory->getListeners()->remove(...$listeners);
97 [0, self::TAG_FIRST_INPUT_ITEM, self::TAG_FIRST_COOKING_TIME],
98 [1, self::TAG_SECOND_INPUT_ITEM, self::TAG_SECOND_COOKING_TIME],
99 [2, self::TAG_THIRD_INPUT_ITEM, self::TAG_THIRD_COOKING_TIME],
100 [3, self::TAG_FOURTH_INPUT_ITEM, self::TAG_FOURTH_COOKING_TIME],
101 ] as [$slot, $itemTag, $cookingTimeTag]){
103 $items[$slot] = Item::nbtDeserialize($tag);
105 if(($tag = $nbt->
getTag($cookingTimeTag)) instanceof IntTag){
106 $this->cookingTimes[$slot] = $tag->getValue();
109 $this->inventory->setContents($items);
110 $this->inventory->getListeners()->add(...$listeners);
115 [0, self::TAG_FIRST_INPUT_ITEM, self::TAG_FIRST_COOKING_TIME],
116 [1, self::TAG_SECOND_INPUT_ITEM, self::TAG_SECOND_COOKING_TIME],
117 [2, self::TAG_THIRD_INPUT_ITEM, self::TAG_THIRD_COOKING_TIME],
118 [3, self::TAG_FOURTH_INPUT_ITEM, self::TAG_FOURTH_COOKING_TIME],
119 ] as [$slot, $itemTag, $cookingTimeTag]){
120 $item = $this->inventory->getItem($slot);
121 if(!$item->isNull()){
122 $nbt->setTag($itemTag, $item->nbtSerialize());
123 if(isset($this->cookingTimes[$slot])){
124 $nbt->setInt($cookingTimeTag, $this->cookingTimes[$slot]);
132 0 => self::TAG_FIRST_INPUT_ITEM,
133 1 => self::TAG_SECOND_INPUT_ITEM,
134 2 => self::TAG_THIRD_INPUT_ITEM,
135 3 => self::TAG_FOURTH_INPUT_ITEM
137 $item = $this->inventory->getItem($slot);
138 if(!$item->isNull()){
139 $nbt->setTag($tag, TypeConverter::getInstance()->getItemTranslator()->toNetworkNbt($item));