the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 108 lines 3.4 kB view raw
1#include "stdafx.h" 2#include "net.minecraft.world.entity.ai.attributes.h" 3#include "BasicTypeContainers.h" 4#include "SharedMonsterAttributes.h" 5 6Attribute *SharedMonsterAttributes::MAX_HEALTH = (new RangedAttribute(eAttributeId_GENERIC_MAXHEALTH, 20, 0, Double::MAX_VALUE))->setSyncable(true); 7Attribute *SharedMonsterAttributes::FOLLOW_RANGE = (new RangedAttribute(eAttributeId_GENERIC_FOLLOWRANGE, 32, 0, 2048)); 8Attribute *SharedMonsterAttributes::KNOCKBACK_RESISTANCE = (new RangedAttribute(eAttributeId_GENERIC_KNOCKBACKRESISTANCE, 0, 0, 1)); 9Attribute *SharedMonsterAttributes::MOVEMENT_SPEED = (new RangedAttribute(eAttributeId_GENERIC_MOVEMENTSPEED, 0.7f, 0, Double::MAX_VALUE))->setSyncable(true); 10Attribute *SharedMonsterAttributes::ATTACK_DAMAGE = new RangedAttribute(eAttributeId_GENERIC_ATTACKDAMAGE, 2, 0, Double::MAX_VALUE); 11 12ListTag<CompoundTag> *SharedMonsterAttributes::saveAttributes(BaseAttributeMap *attributes) 13{ 14 ListTag<CompoundTag> *list = new ListTag<CompoundTag>(); 15 16 vector<AttributeInstance *> atts; 17 attributes->getAttributes(atts); 18 for (AUTO_VAR(it, atts.begin()); it != atts.end(); ++it) 19 { 20 AttributeInstance *attribute = *it; 21 list->add(saveAttribute(attribute)); 22 } 23 24 return list; 25} 26 27CompoundTag *SharedMonsterAttributes::saveAttribute(AttributeInstance *instance) 28{ 29 CompoundTag *tag = new CompoundTag(); 30 Attribute *attribute = instance->getAttribute(); 31 32 tag->putInt(L"ID", attribute->getId()); 33 tag->putDouble(L"Base", instance->getBaseValue()); 34 35 unordered_set<AttributeModifier *> modifiers; 36 instance->getModifiers(modifiers); 37 38 if (!modifiers.empty()) 39 { 40 ListTag<CompoundTag> *list = new ListTag<CompoundTag>(); 41 42 for (AUTO_VAR(it,modifiers.begin()); it != modifiers.end(); ++it) 43 { 44 AttributeModifier* modifier = *it; 45 if (modifier->isSerializable()) 46 { 47 list->add(saveAttributeModifier(modifier)); 48 } 49 } 50 51 tag->put(L"Modifiers", list); 52 } 53 54 return tag; 55} 56 57CompoundTag *SharedMonsterAttributes::saveAttributeModifier(AttributeModifier *modifier) 58{ 59 CompoundTag *tag = new CompoundTag(); 60 61 tag->putDouble(L"Amount", modifier->getAmount()); 62 tag->putInt(L"Operation", modifier->getOperation()); 63 tag->putInt(L"UUID", modifier->getId()); 64 65 return tag; 66} 67 68void SharedMonsterAttributes::loadAttributes(BaseAttributeMap *attributes, ListTag<CompoundTag> *list) 69{ 70 for (int i = 0; i < list->size(); i++) 71 { 72 CompoundTag *tag = list->get(i); 73 AttributeInstance *instance = attributes->getInstance(static_cast<eATTRIBUTE_ID>(tag->getInt(L"ID"))); 74 75 if (instance != NULL) 76 { 77 loadAttribute(instance, tag); 78 } 79 else 80 { 81 app.DebugPrintf("Ignoring unknown attribute '%d'", tag->getInt(L"ID") ); 82 } 83 } 84} 85 86void SharedMonsterAttributes::loadAttribute(AttributeInstance *instance, CompoundTag *tag) 87{ 88 instance->setBaseValue(tag->getDouble(L"Base")); 89 90 if (tag->contains(L"Modifiers")) 91 { 92 ListTag<CompoundTag> *list = (ListTag<CompoundTag> *) tag->getList(L"Modifiers"); 93 94 for (int i = 0; i < list->size(); i++) 95 { 96 AttributeModifier *modifier = loadAttributeModifier(list->get(i)); 97 AttributeModifier *old = instance->getModifier(modifier->getId()); 98 if (old != NULL) instance->removeModifier(old); 99 instance->addModifier(modifier); 100 } 101 } 102} 103 104AttributeModifier *SharedMonsterAttributes::loadAttributeModifier(CompoundTag *tag) 105{ 106 eMODIFIER_ID id = (eMODIFIER_ID)tag->getInt(L"UUID"); 107 return new AttributeModifier(id, tag->getDouble(L"Amount"), tag->getInt(L"Operation")); 108}