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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
#include "stdafx.h"
#include "..\Minecraft.Client\Minecraft.h"
#include "net.minecraft.world.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "com.mojang.nbt.h"
#include "ArmorItem.h"
const int ArmorItem::healthPerSlot[] = {
11, 16, 15, 13
};
const wstring ArmorItem::LEATHER_OVERLAYS[] = {
L"helmetCloth_overlay", L"chestplateCloth_overlay", L"leggingsCloth_overlay", L"bootsCloth_overlay"
};
const wstring ArmorItem::TEXTURE_EMPTY_SLOTS[] = {
L"slot_empty_helmet", L"slot_empty_chestplate", L"slot_empty_leggings", L"slot_empty_boots"
};
shared_ptr<ItemInstance> ArmorItem::ArmorDispenseItemBehavior::execute(BlockSource *source, shared_ptr<ItemInstance> dispensed, eOUTCOME &outcome)
{
FacingEnum *facing = DispenserTile::getFacing(source->getData());
int x = source->getBlockX() + facing->getStepX();
int y = source->getBlockY() + facing->getStepY();
int z = source->getBlockZ() + facing->getStepZ();
AABB *bb = AABB::newTemp(x, y, z, x + 1, y + 1, z + 1);
EntitySelector *selector = new MobCanWearArmourEntitySelector(dispensed);
vector<shared_ptr<Entity> > *entities = source->getWorld()->getEntitiesOfClass(typeid(LivingEntity), bb, selector);
delete selector;
if (entities->size() > 0)
{
shared_ptr<LivingEntity> target = dynamic_pointer_cast<LivingEntity>( entities->at(0) );
int offset = target->instanceof(eTYPE_PLAYER) ? 1 : 0;
int slot = Mob::getEquipmentSlotForItem(dispensed);
shared_ptr<ItemInstance> equip = dispensed->copy();
equip->count = 1;
target->setEquippedSlot(slot - offset, equip);
if (target->instanceof(eTYPE_MOB)) dynamic_pointer_cast<Mob>(target)->setDropChance(slot, 2);
dispensed->count--;
outcome = ACTIVATED_ITEM;
delete entities;
return dispensed;
}
else
{
delete entities;
return DefaultDispenseItemBehavior::execute(source, dispensed, outcome);
}
}
typedef ArmorItem::ArmorMaterial _ArmorMaterial;
const int _ArmorMaterial::clothArray[] = {1,3,2,1};
const int _ArmorMaterial::chainArray[] = {2, 5, 4, 1};
const int _ArmorMaterial::ironArray[] = {2, 6, 5, 2};
const int _ArmorMaterial::goldArray[] = {2, 5, 3, 1};
const int _ArmorMaterial::diamondArray[] = {3, 8, 6, 3};
const _ArmorMaterial *_ArmorMaterial::CLOTH = new _ArmorMaterial(5, _ArmorMaterial::clothArray, 15);
const _ArmorMaterial *_ArmorMaterial::CHAIN = new _ArmorMaterial(15, _ArmorMaterial::chainArray, 12);
const _ArmorMaterial *_ArmorMaterial::IRON = new _ArmorMaterial(15, _ArmorMaterial::ironArray, 9);
const _ArmorMaterial *_ArmorMaterial::GOLD = new _ArmorMaterial(7, _ArmorMaterial::goldArray, 25);
const _ArmorMaterial *_ArmorMaterial::DIAMOND = new _ArmorMaterial(33, _ArmorMaterial::diamondArray, 10);
_ArmorMaterial::ArmorMaterial(int durabilityMultiplier, const int slotProtections[], int enchantmentValue)
{
this->durabilityMultiplier = durabilityMultiplier;
this->slotProtections = (int *)slotProtections;
this->enchantmentValue = enchantmentValue;
}
_ArmorMaterial::~ArmorMaterial()
{
delete [] slotProtections;
}
int _ArmorMaterial::getHealthForSlot(int slot) const
{
return healthPerSlot[slot] * durabilityMultiplier;
}
int _ArmorMaterial::getDefenseForSlot(int slot) const
{
return slotProtections[slot];
}
int _ArmorMaterial::getEnchantmentValue() const
{
return enchantmentValue;
}
int _ArmorMaterial::getTierItemId() const
{
if (this == CLOTH)
{
return Item::leather_Id;
}
else if (this == CHAIN)
{
return Item::ironIngot_Id;
}
else if (this == GOLD)
{
return Item::goldIngot_Id;
}
else if (this == IRON)
{
return Item::ironIngot_Id;
}
else if (this == DIAMOND)
{
return Item::diamond_Id;
}
return 0;
}
ArmorItem::ArmorItem(int id, const ArmorMaterial *armorType, int icon, int slot) : Item( id ), armorType( armorType ), slot( slot ), modelIndex( icon ), defense( armorType->getDefenseForSlot(slot) )
{
setMaxDamage(armorType->getHealthForSlot(slot));
maxStackSize = 1;
DispenserTile::REGISTRY.add(this, new ArmorDispenseItemBehavior());
}
int ArmorItem::getColor(shared_ptr<ItemInstance> item, int spriteLayer)
{
if (spriteLayer > 0)
{
return 0xFFFFFF;
}
int color = getColor(item);
if (color < 0) color = 0xFFFFFF;
return color;
}
bool ArmorItem::hasMultipleSpriteLayers()
{
return armorType == ArmorMaterial::CLOTH;
}
int ArmorItem::getEnchantmentValue()
{
return armorType->getEnchantmentValue();
}
const _ArmorMaterial *ArmorItem::getMaterial()
{
return armorType;
}
bool ArmorItem::hasCustomColor(shared_ptr<ItemInstance> item)
{
if (armorType != ArmorMaterial::CLOTH) return false;
if (!item->hasTag()) return false;
if (!item->getTag()->contains(L"display")) return false;
if (!item->getTag()->getCompound(L"display")->contains(L"color")) return false;
return true;
}
int ArmorItem::getColor(shared_ptr<ItemInstance> item)
{
if (armorType != ArmorMaterial::CLOTH) return -1;
CompoundTag *tag = item->getTag();
if (tag == nullptr) return Minecraft::GetInstance()->getColourTable()->getColor( DEFAULT_LEATHER_COLOR );
CompoundTag *display = tag->getCompound(L"display");
if (display == nullptr) return Minecraft::GetInstance()->getColourTable()->getColor( DEFAULT_LEATHER_COLOR );
if (display->contains(L"color"))
{
return display->getInt(L"color");
}
else
{
return Minecraft::GetInstance()->getColourTable()->getColor( DEFAULT_LEATHER_COLOR );
}
}
Icon *ArmorItem::getLayerIcon(int auxValue, int spriteLayer)
{
if (spriteLayer == 1)
{
return overlayIcon;
}
return Item::getLayerIcon(auxValue, spriteLayer);
}
void ArmorItem::clearColor(shared_ptr<ItemInstance> item)
{
if (armorType != ArmorMaterial::CLOTH) return;
CompoundTag *tag = item->getTag();
if (tag == nullptr) return;
CompoundTag *display = tag->getCompound(L"display");
if (display->contains(L"color")) display->remove(L"color");
}
void ArmorItem::setColor(shared_ptr<ItemInstance> item, int color)
{
if (armorType != ArmorMaterial::CLOTH)
{
#ifndef _CONTENT_PACKAGE
printf("Can't dye non-leather!");
__debugbreak();
#endif
//throw new UnsupportedOperationException("Can't dye non-leather!");
}
CompoundTag *tag = item->getTag();
if (tag == nullptr)
{
tag = new CompoundTag();
item->setTag(tag);
}
CompoundTag *display = tag->getCompound(L"display");
if (!tag->contains(L"display")) tag->putCompound(L"display", display);
display->putInt(L"color", color);
}
bool ArmorItem::isValidRepairItem(shared_ptr<ItemInstance> source, shared_ptr<ItemInstance> repairItem)
{
if (armorType->getTierItemId() == repairItem->id)
{
return true;
}
return Item::isValidRepairItem(source, repairItem);
}
void ArmorItem::registerIcons(IconRegister *iconRegister)
{
Item::registerIcons(iconRegister);
if (armorType == ArmorMaterial::CLOTH)
{
overlayIcon = iconRegister->registerIcon(LEATHER_OVERLAYS[slot]);
}
iconEmpty = iconRegister->registerIcon(TEXTURE_EMPTY_SLOTS[slot]);
}
Icon *ArmorItem::getEmptyIcon(int slot)
{
switch (slot)
{
case 0:
return Item::helmet_diamond->iconEmpty;
case 1:
return Item::chestplate_diamond->iconEmpty;
case 2:
return Item::leggings_diamond->iconEmpty;
case 3:
return Item::boots_diamond->iconEmpty;
}
return nullptr;
}
|