mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 10:43:39 +00:00
# Conflicts: # Minecraft.Client/Network/PlayerChunkMap.cpp # Minecraft.Client/Network/PlayerList.cpp # Minecraft.Client/Network/ServerChunkCache.cpp # Minecraft.Client/Platform/Common/Consoles_App.cpp # Minecraft.Client/Platform/Common/DLC/DLCManager.cpp # Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp # Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp # Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp # Minecraft.Client/Platform/Common/Tutorial/TutorialTask.cpp # Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp # Minecraft.Client/Platform/Common/UI/UIComponent_Panorama.cpp # Minecraft.Client/Platform/Common/UI/UIController.cpp # Minecraft.Client/Platform/Common/UI/UIController.h # Minecraft.Client/Platform/Extrax64Stubs.cpp # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Input.h # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Storage.h # Minecraft.Client/Player/EntityTracker.cpp # Minecraft.Client/Player/ServerPlayer.cpp # Minecraft.Client/Rendering/EntityRenderers/PlayerRenderer.cpp # Minecraft.Client/Textures/Packs/DLCTexturePack.cpp # Minecraft.Client/Textures/Stitching/StitchedTexture.cpp # Minecraft.Client/Textures/Stitching/TextureMap.cpp # Minecraft.Client/Textures/Textures.cpp # Minecraft.World/Blocks/NotGateTile.cpp # Minecraft.World/Blocks/PressurePlateTile.cpp # Minecraft.World/Blocks/TileEntities/PotionBrewing.cpp # Minecraft.World/Enchantments/EnchantmentHelper.cpp # Minecraft.World/Entities/HangingEntity.cpp # Minecraft.World/Entities/LeashFenceKnotEntity.cpp # Minecraft.World/Entities/LivingEntity.cpp # Minecraft.World/Entities/Mobs/Boat.cpp # Minecraft.World/Entities/Mobs/Minecart.cpp # Minecraft.World/Entities/Mobs/Witch.cpp # Minecraft.World/Entities/SyncedEntityData.cpp # Minecraft.World/Items/LeashItem.cpp # Minecraft.World/Items/PotionItem.cpp # Minecraft.World/Level/BaseMobSpawner.cpp # Minecraft.World/Level/CustomLevelSource.cpp # Minecraft.World/Level/Level.cpp # Minecraft.World/Level/Storage/DirectoryLevelStorage.cpp # Minecraft.World/Level/Storage/McRegionLevelStorage.cpp # Minecraft.World/Level/Storage/RegionFileCache.cpp # Minecraft.World/Player/Player.cpp # Minecraft.World/WorldGen/Biomes/BiomeCache.cpp # Minecraft.World/WorldGen/Features/RandomScatteredLargeFeature.cpp # Minecraft.World/WorldGen/Layers/BiomeOverrideLayer.cpp
113 lines
4 KiB
C++
113 lines
4 KiB
C++
#include "../../Platform/stdafx.h"
|
|
#include "../../Headers/net.minecraft.world.entity.ai.attributes.h"
|
|
#include "SharedMonsterAttributes.h"
|
|
#include <limits>
|
|
|
|
Attribute* SharedMonsterAttributes::MAX_HEALTH =
|
|
(new RangedAttribute(eAttributeId_GENERIC_MAXHEALTH, 20, 0,
|
|
std::numeric_limits<double>::max()))
|
|
->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,
|
|
std::numeric_limits<double>::max()))
|
|
->setSyncable(true);
|
|
Attribute* SharedMonsterAttributes::ATTACK_DAMAGE =
|
|
new RangedAttribute(eAttributeId_GENERIC_ATTACKDAMAGE, 2, 0,
|
|
std::numeric_limits<double>::max());
|
|
|
|
ListTag<CompoundTag>* SharedMonsterAttributes::saveAttributes(
|
|
BaseAttributeMap* attributes) {
|
|
ListTag<CompoundTag>* list = new ListTag<CompoundTag>();
|
|
|
|
std::vector<AttributeInstance*> atts;
|
|
attributes->getAttributes(atts);
|
|
for (auto 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());
|
|
|
|
std::unordered_set<AttributeModifier*> modifiers;
|
|
instance->getModifiers(modifiers);
|
|
|
|
if (!modifiers.empty()) {
|
|
ListTag<CompoundTag>* list = new ListTag<CompoundTag>();
|
|
|
|
for (auto 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<CompoundTag>* list) {
|
|
for (int i = 0; i < list->size(); i++) {
|
|
CompoundTag* tag = list->get(i);
|
|
AttributeInstance* instance = attributes->getInstance(
|
|
static_cast<eATTRIBUTE_ID>(tag->getInt(L"ID")));
|
|
|
|
if (instance != nullptr) {
|
|
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<CompoundTag>* list =
|
|
(ListTag<CompoundTag>*)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 != nullptr) 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"));
|
|
}
|