blob: 33ebcbd403aee00862024af669346e99529cc31e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#include "stdafx.h"
#include "net.minecraft.world.level.tile.entity.h"
#include "ContainerOpenPacket.h"
#include "PlayerEnderChestContainer.h"
PlayerEnderChestContainer::PlayerEnderChestContainer() : SimpleContainer(IDS_TILE_ENDERCHEST, L"", false, 9 * 3)
{
activeChest = nullptr;
}
int PlayerEnderChestContainer::getContainerType()
{
return ContainerOpenPacket::ENDER_CHEST;
}
void PlayerEnderChestContainer::setActiveChest(shared_ptr<EnderChestTileEntity> activeChest)
{
this->activeChest = activeChest;
}
void PlayerEnderChestContainer::setItemsByTag(ListTag<CompoundTag> *enderItemsList)
{
for (int i = 0; i < getContainerSize(); i++)
{
setItem(i, nullptr);
}
for (int i = 0; i < enderItemsList->size(); i++)
{
CompoundTag *tag = enderItemsList->get(i);
int slot = tag->getByte(L"Slot") & 0xff;
if (slot >= 0 && slot < getContainerSize()) setItem(slot, ItemInstance::fromTag(tag));
}
}
ListTag<CompoundTag> *PlayerEnderChestContainer::createTag()
{
ListTag<CompoundTag> *items = new ListTag<CompoundTag>(L"EnderItems");
for (int i = 0; i < getContainerSize(); i++)
{
shared_ptr<ItemInstance> item = getItem(i);
if (item != nullptr)
{
CompoundTag *tag = new CompoundTag();
tag->putByte(L"Slot", static_cast<byte>(i));
item->save(tag);
items->add(tag);
}
}
return items;
}
bool PlayerEnderChestContainer::stillValid(shared_ptr<Player> player)
{
if (activeChest != nullptr && !activeChest->stillValid(player))
{
return false;
}
return SimpleContainer::stillValid(player);
}
void PlayerEnderChestContainer::startOpen()
{
if (activeChest != nullptr)
{
activeChest->startOpen();
}
SimpleContainer::startOpen();
}
void PlayerEnderChestContainer::stopOpen()
{
if (activeChest)
{
activeChest->stopOpen();
}
SimpleContainer::stopOpen();
activeChest = nullptr;
}
bool PlayerEnderChestContainer::canPlaceItem(int slot, shared_ptr<ItemInstance> item)
{
return true;
}
|