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