From fec64bb91c03c5e872a8f6fbc1a253f341373072 Mon Sep 17 00:00:00 2001 From: Persson-dev <66266021+Persson-dev@users.noreply.github.com> Date: Wed, 29 Dec 2021 20:28:41 +0100 Subject: Improved farmer AI & Fixed entity loading functions (#5351) * Allow villagers to pickup items * Add farmer villager harvesting * Use of auto keyword * Using for loop to check adjacent crops * Show particules when farmer harvest * Fix area comment * Move constants to header file * Removing unnecessary semicolon * Initialization of CropBlockType variable * Apply 12xx12 suggestion * Fixing area constant size * Refactor bounding box calculation, use vectors. * Add Api documentation * Update lua docs * Rework farmer ai * Fixing lua docs notes * Add missing capitalisation * Add villagers inventory save * Fixing loading entities from disk inconsistencies * Add farmer harvest animation * Fix beetroots grow state Co-authored-by: Alexander Harkness --- src/WorldStorage/NBTChunkSerializer.cpp | 3 ++ src/WorldStorage/WSSAnvil.cpp | 52 ++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 23 deletions(-) (limited to 'src/WorldStorage') diff --git a/src/WorldStorage/NBTChunkSerializer.cpp b/src/WorldStorage/NBTChunkSerializer.cpp index e96acccef..dde6c299c 100644 --- a/src/WorldStorage/NBTChunkSerializer.cpp +++ b/src/WorldStorage/NBTChunkSerializer.cpp @@ -893,6 +893,9 @@ public: const cVillager *Villager = static_cast(a_Monster); mWriter.AddInt("Profession", Villager->GetVilType()); mWriter.AddInt("Age", Villager->GetAge()); + mWriter.BeginList("Inventory", TAG_Compound); + AddItemGrid(Villager->GetInventory()); + mWriter.EndList(); break; } case mtWither: diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp index dbbd03daf..dfefb74d3 100644 --- a/src/WorldStorage/WSSAnvil.cpp +++ b/src/WorldStorage/WSSAnvil.cpp @@ -1663,29 +1663,29 @@ void cWSSAnvil::LoadEntityFromNBT(cEntityList & a_Entities, const cParsedNBT & a case mtHoglin: return LoadHoglinFromNBT(a_Entities, a_NBT, a_EntityTagIdx); case mtHusk: return LoadHuskFromNBT(a_Entities, a_NBT, a_EntityTagIdx); case mtIllusioner: return LoadIllusionerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtIronGolem: return LoadVillagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtLlama: return LoadIronGolemFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtMagmaCube: return LoadLlamaFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtMooshroom: return LoadMagmaCubeFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtMule: return LoadMooshroomFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtOcelot: return LoadMuleFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPanda: return LoadOcelotFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtParrot: return LoadPandaFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPhantom: return LoadParrotFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPig: return LoadPhantomFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPiglin: return LoadPigFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPiglinBrute: return LoadPiglinFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPillager: return LoadPiglinBruteFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPolarBear: return LoadPillagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtPufferfish: return LoadPolarBearFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtRabbit: return LoadPufferfishFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtRavager: return LoadRabbitFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtSalmon: return LoadRavagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtSheep: return LoadSalmonFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtShulker: return LoadSheepFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtSilverfish: return LoadShulkerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtSkeleton: return LoadSilverfishFromNBT(a_Entities, a_NBT, a_EntityTagIdx); - case mtSkeletonHorse: return LoadSkeletonFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtIronGolem: return LoadIronGolemFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtLlama: return LoadLlamaFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtMagmaCube: return LoadMagmaCubeFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtMooshroom: return LoadMooshroomFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtMule: return LoadMuleFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtOcelot: return LoadOcelotFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPanda: return LoadPandaFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtParrot: return LoadParrotFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPhantom: return LoadPhantomFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPig: return LoadPigFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPiglin: return LoadPiglinFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPiglinBrute: return LoadPiglinBruteFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPillager: return LoadPillagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPolarBear: return LoadPolarBearFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtPufferfish: return LoadPufferfishFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtRabbit: return LoadRabbitFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtRavager: return LoadRavagerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtSalmon: return LoadSalmonFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtSheep: return LoadSheepFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtShulker: return LoadShulkerFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtSilverfish: return LoadSilverfishFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtSkeleton: return LoadSkeletonFromNBT(a_Entities, a_NBT, a_EntityTagIdx); + case mtSkeletonHorse: return LoadSkeletonHorseFromNBT(a_Entities, a_NBT, a_EntityTagIdx); case mtSlime: return LoadSlimeFromNBT(a_Entities, a_NBT, a_EntityTagIdx); case mtSnowGolem: return LoadSnowGolemFromNBT(a_Entities, a_NBT, a_EntityTagIdx); case mtSpider: return LoadSpiderFromNBT(a_Entities, a_NBT, a_EntityTagIdx); @@ -3270,6 +3270,12 @@ void cWSSAnvil::LoadVillagerFromNBT(cEntityList & a_Entities, const cParsedNBT & Monster->SetAge(Age); } + int InventoryIdx = a_NBT.FindChildByName(a_TagIdx, "Inventory"); + if (InventoryIdx > 0) + { + LoadItemGridFromNBT(Monster->GetInventory(), a_NBT, InventoryIdx); + } + a_Entities.emplace_back(std::move(Monster)); } -- cgit v1.2.3