From b3feddfef372618c8a9d7a0abcaf18cfad866c18 Mon Sep 17 00:00:00 2001 From: daoge <3523206925@qq.com> Date: Tue, 3 Mar 2026 03:04:10 +0800 Subject: feat: TU19 (Dec 2014) Features & Content (#155) * try to resolve merge conflict * feat: TU19 (Dec 2014) Features & Content (#32) * December 2014 files * Working release build * Fix compilation issues * Add sound to Windows64Media * Add DLC content and force Tutorial DLC * Revert "Add DLC content and force Tutorial DLC" This reverts commit 97a43994725008e35fceb984d5549df9c8cea470. * Disable broken light packing * Disable breakpoint during DLC texture map load Allows DLC loading but the DLC textures are still broken * Fix post build not working * ... * fix vs2022 build * fix cmake build --------- Co-authored-by: Loki --- Minecraft.World/SharedMonsterAttributes.cpp | 108 ++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 Minecraft.World/SharedMonsterAttributes.cpp (limited to 'Minecraft.World/SharedMonsterAttributes.cpp') diff --git a/Minecraft.World/SharedMonsterAttributes.cpp b/Minecraft.World/SharedMonsterAttributes.cpp new file mode 100644 index 00000000..f434f1e7 --- /dev/null +++ b/Minecraft.World/SharedMonsterAttributes.cpp @@ -0,0 +1,108 @@ +#include "stdafx.h" +#include "net.minecraft.world.entity.ai.attributes.h" +#include "BasicTypeContainers.h" +#include "SharedMonsterAttributes.h" + +Attribute *SharedMonsterAttributes::MAX_HEALTH = (new RangedAttribute(eAttributeId_GENERIC_MAXHEALTH, 20, 0, Double::MAX_VALUE))->setSyncable(true); +Attribute *SharedMonsterAttributes::FOLLOW_RANGE = (new RangedAttribute(eAttributeId_GENERIC_FOLLOWRANGE, 32, 0, 2048)); +Attribute *SharedMonsterAttributes::KNOCKBACK_RESISTANCE = (new RangedAttribute(eAttributeId_GENERIC_KNOCKBACKRESISTANCE, 0, 0, 1)); +Attribute *SharedMonsterAttributes::MOVEMENT_SPEED = (new RangedAttribute(eAttributeId_GENERIC_MOVEMENTSPEED, 0.7f, 0, Double::MAX_VALUE))->setSyncable(true); +Attribute *SharedMonsterAttributes::ATTACK_DAMAGE = new RangedAttribute(eAttributeId_GENERIC_ATTACKDAMAGE, 2, 0, Double::MAX_VALUE); + +ListTag *SharedMonsterAttributes::saveAttributes(BaseAttributeMap *attributes) +{ + ListTag *list = new ListTag(); + + vector atts; + attributes->getAttributes(atts); + for (AUTO_VAR(it, atts.begin()); it != atts.end(); ++it) + { + AttributeInstance *attribute = *it; + list->add(saveAttribute(attribute)); + } + + return list; +} + +CompoundTag *SharedMonsterAttributes::saveAttribute(AttributeInstance *instance) +{ + CompoundTag *tag = new CompoundTag(); + Attribute *attribute = instance->getAttribute(); + + tag->putInt(L"ID", attribute->getId()); + tag->putDouble(L"Base", instance->getBaseValue()); + + unordered_set modifiers; + instance->getModifiers(modifiers); + + if (!modifiers.empty()) + { + ListTag *list = new ListTag(); + + for (AUTO_VAR(it,modifiers.begin()); it != modifiers.end(); ++it) + { + AttributeModifier* modifier = *it; + if (modifier->isSerializable()) + { + list->add(saveAttributeModifier(modifier)); + } + } + + tag->put(L"Modifiers", list); + } + + return tag; +} + +CompoundTag *SharedMonsterAttributes::saveAttributeModifier(AttributeModifier *modifier) +{ + CompoundTag *tag = new CompoundTag(); + + tag->putDouble(L"Amount", modifier->getAmount()); + tag->putInt(L"Operation", modifier->getOperation()); + tag->putInt(L"UUID", modifier->getId()); + + return tag; +} + +void SharedMonsterAttributes::loadAttributes(BaseAttributeMap *attributes, ListTag *list) +{ + for (int i = 0; i < list->size(); i++) + { + CompoundTag *tag = list->get(i); + AttributeInstance *instance = attributes->getInstance(static_cast(tag->getInt(L"ID"))); + + if (instance != NULL) + { + loadAttribute(instance, tag); + } + else + { + app.DebugPrintf("Ignoring unknown attribute '%d'", tag->getInt(L"ID") ); + } + } +} + +void SharedMonsterAttributes::loadAttribute(AttributeInstance *instance, CompoundTag *tag) +{ + instance->setBaseValue(tag->getDouble(L"Base")); + + if (tag->contains(L"Modifiers")) + { + ListTag *list = (ListTag *) tag->getList(L"Modifiers"); + + for (int i = 0; i < list->size(); i++) + { + AttributeModifier *modifier = loadAttributeModifier(list->get(i)); + AttributeModifier *old = instance->getModifier(modifier->getId()); + if (old != NULL) instance->removeModifier(old); + instance->addModifier(modifier); + } + } +} + +AttributeModifier *SharedMonsterAttributes::loadAttributeModifier(CompoundTag *tag) +{ + eMODIFIER_ID id = (eMODIFIER_ID)tag->getInt(L"UUID"); + return new AttributeModifier(id, tag->getDouble(L"Amount"), tag->getInt(L"Operation")); +} \ No newline at end of file -- cgit v1.2.3