From 87b4af678bf7caff4d9e71dda15c817a3c8fe7cc Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Sun, 22 Mar 2026 01:15:44 -0500 Subject: [PATCH] format .Client/Common/GameRules --- .../AddEnchantmentRuleDefinition.cpp | 105 +- .../GameRules/AddEnchantmentRuleDefinition.h | 20 +- .../GameRules/AddItemRuleDefinition.cpp | 186 +- .../Common/GameRules/AddItemRuleDefinition.h | 33 +- .../ApplySchematicRuleDefinition.cpp | 405 ++-- .../GameRules/ApplySchematicRuleDefinition.h | 65 +- .../Common/GameRules/BiomeOverride.cpp | 82 +- .../Platform/Common/GameRules/BiomeOverride.h | 28 +- .../GameRules/CollectItemRuleDefinition.cpp | 191 +- .../GameRules/CollectItemRuleDefinition.h | 45 +- .../GameRules/CompleteAllRuleDefinition.cpp | 102 +- .../GameRules/CompleteAllRuleDefinition.h | 28 +- .../GameRules/CompoundGameRuleDefinition.cpp | 176 +- .../GameRules/CompoundGameRuleDefinition.h | 28 +- .../GameRules/ConsoleGameRulesConstants.h | 170 +- .../GameRules/ConsoleGenerateStructure.cpp | 282 ++- .../GameRules/ConsoleGenerateStructure.h | 45 +- .../ConsoleGenerateStructureAction.h | 9 +- .../Common/GameRules/ConsoleSchematicFile.cpp | 1786 +++++++++-------- .../Common/GameRules/ConsoleSchematicFile.h | 132 +- .../Platform/Common/GameRules/GameRule.cpp | 130 +- .../Platform/Common/GameRules/GameRule.h | 79 +- .../Common/GameRules/GameRuleDefinition.cpp | 210 +- .../Common/GameRules/GameRuleDefinition.h | 84 +- .../Common/GameRules/GameRuleManager.cpp | 1256 ++++++------ .../Common/GameRules/GameRuleManager.h | 80 +- .../Common/GameRules/GameRulesInstance.h | 28 +- .../GameRules/LevelGenerationOptions.cpp | 880 ++++---- .../Common/GameRules/LevelGenerationOptions.h | 301 +-- .../Common/GameRules/LevelGenerators.cpp | 29 +- .../Common/GameRules/LevelGenerators.h | 18 +- .../Platform/Common/GameRules/LevelRules.cpp | 20 +- .../Platform/Common/GameRules/LevelRules.h | 12 +- .../Common/GameRules/LevelRuleset.cpp | 91 +- .../Platform/Common/GameRules/LevelRuleset.h | 29 +- .../GameRules/NamedAreaRuleDefinition.cpp | 132 +- .../GameRules/NamedAreaRuleDefinition.h | 27 +- .../Common/GameRules/StartFeature.cpp | 75 +- .../Platform/Common/GameRules/StartFeature.h | 25 +- .../GameRules/UpdatePlayerRuleDefinition.cpp | 262 ++- .../GameRules/UpdatePlayerRuleDefinition.h | 40 +- .../GameRules/UseTileRuleDefinition.cpp | 124 +- .../Common/GameRules/UseTileRuleDefinition.h | 29 +- .../XboxStructureActionGenerateBox.cpp | 171 +- .../XboxStructureActionGenerateBox.h | 28 +- .../XboxStructureActionPlaceBlock.cpp | 111 +- .../GameRules/XboxStructureActionPlaceBlock.h | 26 +- .../XboxStructureActionPlaceContainer.cpp | 145 +- .../XboxStructureActionPlaceContainer.h | 36 +- .../XboxStructureActionPlaceSpawner.cpp | 95 +- .../XboxStructureActionPlaceSpawner.h | 24 +- 51 files changed, 4286 insertions(+), 4229 deletions(-) diff --git a/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.cpp index 4bd79aa8e..7183d4e29 100644 --- a/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.cpp @@ -4,67 +4,64 @@ #include "../../Minecraft.World/Headers/net.minecraft.world.item.enchantment.h" #include "AddEnchantmentRuleDefinition.h" -AddEnchantmentRuleDefinition::AddEnchantmentRuleDefinition() -{ - m_enchantmentId = m_enchantmentLevel = 0; +AddEnchantmentRuleDefinition::AddEnchantmentRuleDefinition() { + m_enchantmentId = m_enchantmentLevel = 0; } -void AddEnchantmentRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) -{ - GameRuleDefinition::writeAttributes(dos, numAttributes + 2); +void AddEnchantmentRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttributes) { + GameRuleDefinition::writeAttributes(dos, numAttributes + 2); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentId); - dos->writeUTF( _toString( m_enchantmentId ) ); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentId); + dos->writeUTF(_toString(m_enchantmentId)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_enchantmentLevel); - dos->writeUTF( _toString( m_enchantmentLevel ) ); + ConsoleGameRules::write(dos, + ConsoleGameRules::eGameRuleAttr_enchantmentLevel); + dos->writeUTF(_toString(m_enchantmentLevel)); } -void AddEnchantmentRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"enchantmentId") == 0) - { - int value = _fromString(attributeValue); - if(value < 0) value = 0; - if(value >= 256) value = 255; - m_enchantmentId = value; - app.DebugPrintf("AddEnchantmentRuleDefinition: Adding parameter enchantmentId=%d\n",m_enchantmentId); - } - else if(attributeName.compare(L"enchantmentLevel") == 0) - { - int value = _fromString(attributeValue); - if(value < 0) value = 0; - m_enchantmentLevel = value; - app.DebugPrintf("AddEnchantmentRuleDefinition: Adding parameter enchantmentLevel=%d\n",m_enchantmentLevel); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void AddEnchantmentRuleDefinition::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"enchantmentId") == 0) { + int value = _fromString(attributeValue); + if (value < 0) value = 0; + if (value >= 256) value = 255; + m_enchantmentId = value; + app.DebugPrintf( + "AddEnchantmentRuleDefinition: Adding parameter enchantmentId=%d\n", + m_enchantmentId); + } else if (attributeName.compare(L"enchantmentLevel") == 0) { + int value = _fromString(attributeValue); + if (value < 0) value = 0; + m_enchantmentLevel = value; + app.DebugPrintf( + "AddEnchantmentRuleDefinition: Adding parameter " + "enchantmentLevel=%d\n", + m_enchantmentLevel); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -bool AddEnchantmentRuleDefinition::enchantItem(std::shared_ptr item) -{ - bool enchanted = false; - if (item != NULL) - { - // 4J-JEV: Ripped code from enchantmenthelpers - // Maybe we want to add an addEnchantment method to EnchantmentHelpers - if (item->id == Item::enchantedBook_Id) - { - Item::enchantedBook->addEnchantment( item, new EnchantmentInstance(m_enchantmentId, m_enchantmentLevel) ); - } - else if (item->isEnchantable()) - { - Enchantment *e = Enchantment::enchantments[m_enchantmentId]; +bool AddEnchantmentRuleDefinition::enchantItem( + std::shared_ptr item) { + bool enchanted = false; + if (item != NULL) { + // 4J-JEV: Ripped code from enchantmenthelpers + // Maybe we want to add an addEnchantment method to EnchantmentHelpers + if (item->id == Item::enchantedBook_Id) { + Item::enchantedBook->addEnchantment( + item, + new EnchantmentInstance(m_enchantmentId, m_enchantmentLevel)); + } else if (item->isEnchantable()) { + Enchantment* e = Enchantment::enchantments[m_enchantmentId]; - if(e != NULL && e->category->canEnchant(item->getItem())) - { - int level = std::min(e->getMaxLevel(), m_enchantmentLevel); - item->enchant(e, m_enchantmentLevel); - enchanted = true; - } - } - } - return enchanted; + if (e != NULL && e->category->canEnchant(item->getItem())) { + int level = std::min(e->getMaxLevel(), m_enchantmentLevel); + item->enchant(e, m_enchantmentLevel); + enchanted = true; + } + } + } + return enchanted; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.h index d939c0f96..64bdb86c0 100644 --- a/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/AddEnchantmentRuleDefinition.h @@ -4,20 +4,22 @@ class ItemInstance; -class AddEnchantmentRuleDefinition : public GameRuleDefinition -{ +class AddEnchantmentRuleDefinition : public GameRuleDefinition { private: - int m_enchantmentId; - int m_enchantmentLevel; + int m_enchantmentId; + int m_enchantmentLevel; public: - AddEnchantmentRuleDefinition(); + AddEnchantmentRuleDefinition(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_AddEnchantment; } + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_AddEnchantment; + } - virtual void writeAttributes(DataOutputStream *, unsigned int numAttrs); + virtual void writeAttributes(DataOutputStream*, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - bool enchantItem(std::shared_ptr item); + bool enchantItem(std::shared_ptr item); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.cpp index 7ae0aecf9..94e5ee596 100644 --- a/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.cpp @@ -6,122 +6,110 @@ #include "AddItemRuleDefinition.h" #include "AddEnchantmentRuleDefinition.h" -AddItemRuleDefinition::AddItemRuleDefinition() -{ - m_itemId = m_quantity = m_auxValue = m_dataTag = 0; - m_slot = -1; +AddItemRuleDefinition::AddItemRuleDefinition() { + m_itemId = m_quantity = m_auxValue = m_dataTag = 0; + m_slot = -1; } -void AddItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - GameRuleDefinition::writeAttributes(dos, numAttrs + 5); +void AddItemRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + GameRuleDefinition::writeAttributes(dos, numAttrs + 5); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); - dos->writeUTF( _toString( m_itemId ) ); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); + dos->writeUTF(_toString(m_itemId)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); - dos->writeUTF( _toString( m_quantity ) ); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); + dos->writeUTF(_toString(m_quantity)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); - dos->writeUTF( _toString( m_auxValue ) ); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); + dos->writeUTF(_toString(m_auxValue)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag); - dos->writeUTF( _toString( m_dataTag ) ); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag); + dos->writeUTF(_toString(m_dataTag)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_slot); - dos->writeUTF( _toString( m_slot ) ); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_slot); + dos->writeUTF(_toString(m_slot)); } -void AddItemRuleDefinition::getChildren(std::vector *children) -{ - GameRuleDefinition::getChildren( children ); - for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); it++) - children->push_back( *it ); +void AddItemRuleDefinition::getChildren( + std::vector* children) { + GameRuleDefinition::getChildren(children); + for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); it++) + children->push_back(*it); } -GameRuleDefinition *AddItemRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ - GameRuleDefinition *rule = NULL; - if(ruleType == ConsoleGameRules::eGameRuleType_AddEnchantment) - { - rule = new AddEnchantmentRuleDefinition(); - m_enchantments.push_back((AddEnchantmentRuleDefinition *)rule); - } - else - { +GameRuleDefinition* AddItemRuleDefinition::addChild( + ConsoleGameRules::EGameRuleType ruleType) { + GameRuleDefinition* rule = NULL; + if (ruleType == ConsoleGameRules::eGameRuleType_AddEnchantment) { + rule = new AddEnchantmentRuleDefinition(); + m_enchantments.push_back((AddEnchantmentRuleDefinition*)rule); + } else { #ifndef _CONTENT_PACKAGE - //wprintf(L"AddItemRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); + // wprintf(L"AddItemRuleDefinition: Attempted to add invalid child rule + // - %d\n", ruleType ); #endif - } - return rule; + } + return rule; } -void AddItemRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"itemId") == 0) - { - int value = _fromString(attributeValue); - m_itemId = value; - //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter itemId=%d\n",m_itemId); - } - else if(attributeName.compare(L"quantity") == 0) - { - int value = _fromString(attributeValue); - m_quantity = value; - //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter quantity=%d\n",m_quantity); - } - else if(attributeName.compare(L"auxValue") == 0) - { - int value = _fromString(attributeValue); - m_auxValue = value; - //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter auxValue=%d\n",m_auxValue); - } - else if(attributeName.compare(L"dataTag") == 0) - { - int value = _fromString(attributeValue); - m_dataTag = value; - //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter dataTag=%d\n",m_dataTag); - } - else if(attributeName.compare(L"slot") == 0) - { - int value = _fromString(attributeValue); - m_slot = value; - //app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter slot=%d\n",m_slot); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void AddItemRuleDefinition::addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue) { + if (attributeName.compare(L"itemId") == 0) { + int value = _fromString(attributeValue); + m_itemId = value; + // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter + // itemId=%d\n",m_itemId); + } else if (attributeName.compare(L"quantity") == 0) { + int value = _fromString(attributeValue); + m_quantity = value; + // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter + // quantity=%d\n",m_quantity); + } else if (attributeName.compare(L"auxValue") == 0) { + int value = _fromString(attributeValue); + m_auxValue = value; + // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter + // auxValue=%d\n",m_auxValue); + } else if (attributeName.compare(L"dataTag") == 0) { + int value = _fromString(attributeValue); + m_dataTag = value; + // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter + // dataTag=%d\n",m_dataTag); + } else if (attributeName.compare(L"slot") == 0) { + int value = _fromString(attributeValue); + m_slot = value; + // app.DebugPrintf(2,"AddItemRuleDefinition: Adding parameter + // slot=%d\n",m_slot); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -bool AddItemRuleDefinition::addItemToContainer(std::shared_ptr container, int slotId) -{ - bool added = false; - if(Item::items[m_itemId] != NULL) - { - int quantity = std::min(m_quantity, Item::items[m_itemId]->getMaxStackSize()); - std::shared_ptr newItem = std::shared_ptr(new ItemInstance(m_itemId,quantity,m_auxValue) ); - newItem->set4JData(m_dataTag); +bool AddItemRuleDefinition::addItemToContainer( + std::shared_ptr container, int slotId) { + bool added = false; + if (Item::items[m_itemId] != NULL) { + int quantity = + std::min(m_quantity, Item::items[m_itemId]->getMaxStackSize()); + std::shared_ptr newItem = std::shared_ptr( + new ItemInstance(m_itemId, quantity, m_auxValue)); + newItem->set4JData(m_dataTag); - for(AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); ++it) - { - (*it)->enchantItem(newItem); - } + for (AUTO_VAR(it, m_enchantments.begin()); it != m_enchantments.end(); + ++it) { + (*it)->enchantItem(newItem); + } - if(m_slot >= 0 && m_slot < container->getContainerSize() ) - { - container->setItem( m_slot, newItem ); - added = true; - } - else if(slotId >= 0 && slotId < container->getContainerSize() ) - { - container->setItem( slotId, newItem ); - added = true; - } - else if(std::dynamic_pointer_cast(container) != NULL) - { - added = std::dynamic_pointer_cast(container)->add(newItem); - } - } - return added; + if (m_slot >= 0 && m_slot < container->getContainerSize()) { + container->setItem(m_slot, newItem); + added = true; + } else if (slotId >= 0 && slotId < container->getContainerSize()) { + container->setItem(slotId, newItem); + added = true; + } else if (std::dynamic_pointer_cast(container) != NULL) { + added = + std::dynamic_pointer_cast(container)->add(newItem); + } + } + return added; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.h index d4863ec9b..adbaabf62 100644 --- a/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/AddItemRuleDefinition.h @@ -5,26 +5,29 @@ class Container; class AddEnchantmentRuleDefinition; -class AddItemRuleDefinition : public GameRuleDefinition -{ +class AddItemRuleDefinition : public GameRuleDefinition { private: - int m_itemId; - int m_quantity; - int m_auxValue; - int m_dataTag; - int m_slot; - std::vector m_enchantments; + int m_itemId; + int m_quantity; + int m_auxValue; + int m_dataTag; + int m_slot; + std::vector m_enchantments; public: - AddItemRuleDefinition(); + AddItemRuleDefinition(); - virtual void writeAttributes(DataOutputStream *, unsigned int numAttributes); - virtual void getChildren(std::vector *children); + virtual void writeAttributes(DataOutputStream*, unsigned int numAttributes); + virtual void getChildren(std::vector* children); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_AddItem; } + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_AddItem; + } - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - bool addItemToContainer(std::shared_ptr container, int slotId); + bool addItemToContainer(std::shared_ptr container, int slotId); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp index 02e8ecc63..e7f25cf69 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.cpp @@ -9,241 +9,246 @@ #include "LevelGenerationOptions.h" #include "ConsoleSchematicFile.h" -ApplySchematicRuleDefinition::ApplySchematicRuleDefinition(LevelGenerationOptions *levelGenOptions) -{ - m_levelGenOptions = levelGenOptions; - m_location = Vec3::newPermanent(0,0,0); - m_locationBox = NULL; - m_totalBlocksChanged = 0; - m_totalBlocksChangedLighting = 0; - m_rotation = ConsoleSchematicFile::eSchematicRot_0; - m_completed = false; - m_dimension = 0; - m_schematic = NULL; +ApplySchematicRuleDefinition::ApplySchematicRuleDefinition( + LevelGenerationOptions* levelGenOptions) { + m_levelGenOptions = levelGenOptions; + m_location = Vec3::newPermanent(0, 0, 0); + m_locationBox = NULL; + m_totalBlocksChanged = 0; + m_totalBlocksChangedLighting = 0; + m_rotation = ConsoleSchematicFile::eSchematicRot_0; + m_completed = false; + m_dimension = 0; + m_schematic = NULL; } -ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() -{ - app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n"); - if(!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName); - m_schematic = NULL; - delete m_location; +ApplySchematicRuleDefinition::~ApplySchematicRuleDefinition() { + app.DebugPrintf("Deleting ApplySchematicRuleDefinition.\n"); + if (!m_completed) m_levelGenOptions->releaseSchematicFile(m_schematicName); + m_schematic = NULL; + delete m_location; } -void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - GameRuleDefinition::writeAttributes(dos, numAttrs + 5); +void ApplySchematicRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + GameRuleDefinition::writeAttributes(dos, numAttrs + 5); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename); - dos->writeUTF(m_schematicName); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); - dos->writeUTF(_toString(m_location->x)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); - dos->writeUTF(_toString(m_location->y)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); - dos->writeUTF(_toString(m_location->z)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_filename); + dos->writeUTF(m_schematicName); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); + dos->writeUTF(_toString(m_location->x)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); + dos->writeUTF(_toString(m_location->y)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); + dos->writeUTF(_toString(m_location->z)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_rot); - switch (m_rotation) - { - case ConsoleSchematicFile::eSchematicRot_0: dos->writeUTF(_toString( 0 )); break; - case ConsoleSchematicFile::eSchematicRot_90: dos->writeUTF(_toString( 90 )); break; - case ConsoleSchematicFile::eSchematicRot_180: dos->writeUTF(_toString( 180 )); break; - case ConsoleSchematicFile::eSchematicRot_270: dos->writeUTF(_toString( 270 )); break; - } + switch (m_rotation) { + case ConsoleSchematicFile::eSchematicRot_0: + dos->writeUTF(_toString(0)); + break; + case ConsoleSchematicFile::eSchematicRot_90: + dos->writeUTF(_toString(90)); + break; + case ConsoleSchematicFile::eSchematicRot_180: + dos->writeUTF(_toString(180)); + break; + case ConsoleSchematicFile::eSchematicRot_270: + dos->writeUTF(_toString(270)); + break; + } } -void ApplySchematicRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"filename") == 0) - { - m_schematicName = attributeValue; - //app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter filename=%s\n",m_schematicName.c_str()); +void ApplySchematicRuleDefinition::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"filename") == 0) { + m_schematicName = attributeValue; + // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter + // filename=%s\n",m_schematicName.c_str()); - if(!m_schematicName.empty()) - { - if(m_schematicName.substr( m_schematicName.length() - 4, m_schematicName.length()).compare(L".sch") != 0) - { - m_schematicName.append(L".sch"); - } - m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); - } - } - else if(attributeName.compare(L"x") == 0) - { - m_location->x = _fromString(attributeValue); - if( ((int)abs(m_location->x))%2 != 0) m_location->x -=1; - //app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter x=%f\n",m_location->x); - } - else if(attributeName.compare(L"y") == 0) - { - m_location->y = _fromString(attributeValue); - if( ((int)abs(m_location->y))%2 != 0) m_location->y -= 1; - if(m_location->y < 0) m_location->y = 0; - //app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter y=%f\n",m_location->y); - } - else if(attributeName.compare(L"z") == 0) - { - m_location->z = _fromString(attributeValue); - if(((int)abs(m_location->z))%2 != 0) m_location->z -= 1; - //app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter z=%f\n",m_location->z); - } - else if(attributeName.compare(L"rot") == 0) - { - int degrees = _fromString(attributeValue); + if (!m_schematicName.empty()) { + if (m_schematicName + .substr(m_schematicName.length() - 4, + m_schematicName.length()) + .compare(L".sch") != 0) { + m_schematicName.append(L".sch"); + } + m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); + } + } else if (attributeName.compare(L"x") == 0) { + m_location->x = _fromString(attributeValue); + if (((int)abs(m_location->x)) % 2 != 0) m_location->x -= 1; + // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter + // x=%f\n",m_location->x); + } else if (attributeName.compare(L"y") == 0) { + m_location->y = _fromString(attributeValue); + if (((int)abs(m_location->y)) % 2 != 0) m_location->y -= 1; + if (m_location->y < 0) m_location->y = 0; + // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter + // y=%f\n",m_location->y); + } else if (attributeName.compare(L"z") == 0) { + m_location->z = _fromString(attributeValue); + if (((int)abs(m_location->z)) % 2 != 0) m_location->z -= 1; + // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter + // z=%f\n",m_location->z); + } else if (attributeName.compare(L"rot") == 0) { + int degrees = _fromString(attributeValue); - while(degrees < 0) degrees += 360; - while(degrees >= 360) degrees -= 360; - float quad = degrees/90; - degrees = (int)(quad + 0.5f); - switch(degrees) - { - case 1: - m_rotation = ConsoleSchematicFile::eSchematicRot_90; - break; - case 2: - m_rotation = ConsoleSchematicFile::eSchematicRot_180; - break; - case 3: - case 4: - m_rotation = ConsoleSchematicFile::eSchematicRot_270; - break; - case 0: - default: - m_rotation = ConsoleSchematicFile::eSchematicRot_0; - break; - }; - - //app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter rot=%d\n",m_rotation); - } - else if(attributeName.compare(L"dim") == 0) - { - m_dimension = _fromString(attributeValue); - if(m_dimension > 1 || m_dimension < -1) m_dimension = 0; - //app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",m_dimension); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } + while (degrees < 0) degrees += 360; + while (degrees >= 360) degrees -= 360; + float quad = degrees / 90; + degrees = (int)(quad + 0.5f); + switch (degrees) { + case 1: + m_rotation = ConsoleSchematicFile::eSchematicRot_90; + break; + case 2: + m_rotation = ConsoleSchematicFile::eSchematicRot_180; + break; + case 3: + case 4: + m_rotation = ConsoleSchematicFile::eSchematicRot_270; + break; + case 0: + default: + m_rotation = ConsoleSchematicFile::eSchematicRot_0; + break; + }; + + // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter + // rot=%d\n",m_rotation); + } else if (attributeName.compare(L"dim") == 0) { + m_dimension = _fromString(attributeValue); + if (m_dimension > 1 || m_dimension < -1) m_dimension = 0; + // app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter + // dimension=%d\n",m_dimension); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -void ApplySchematicRuleDefinition::updateLocationBox() -{ - if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); +void ApplySchematicRuleDefinition::updateLocationBox() { + if (m_schematic == NULL) + m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); - m_locationBox = AABB::newPermanent(0,0,0,0,0,0); + m_locationBox = AABB::newPermanent(0, 0, 0, 0, 0, 0); - m_locationBox->x0 = m_location->x; - m_locationBox->y0 = m_location->y; - m_locationBox->z0 = m_location->z; + m_locationBox->x0 = m_location->x; + m_locationBox->y0 = m_location->y; + m_locationBox->z0 = m_location->z; - m_locationBox->y1 = m_location->y + m_schematic->getYSize(); + m_locationBox->y1 = m_location->y + m_schematic->getYSize(); - switch(m_rotation) - { - case ConsoleSchematicFile::eSchematicRot_90: - case ConsoleSchematicFile::eSchematicRot_270: - m_locationBox->x1 = m_location->x + m_schematic->getZSize(); - m_locationBox->z1 = m_location->z + m_schematic->getXSize(); - break; - case ConsoleSchematicFile::eSchematicRot_0: - case ConsoleSchematicFile::eSchematicRot_180: - default: - m_locationBox->x1 = m_location->x + m_schematic->getXSize(); - m_locationBox->z1 = m_location->z + m_schematic->getZSize(); - break; - }; + switch (m_rotation) { + case ConsoleSchematicFile::eSchematicRot_90: + case ConsoleSchematicFile::eSchematicRot_270: + m_locationBox->x1 = m_location->x + m_schematic->getZSize(); + m_locationBox->z1 = m_location->z + m_schematic->getXSize(); + break; + case ConsoleSchematicFile::eSchematicRot_0: + case ConsoleSchematicFile::eSchematicRot_180: + default: + m_locationBox->x1 = m_location->x + m_schematic->getXSize(); + m_locationBox->z1 = m_location->z + m_schematic->getZSize(); + break; + }; } -void ApplySchematicRuleDefinition::processSchematic(AABB *chunkBox, LevelChunk *chunk) -{ - if( m_completed ) return; - if(chunk->level->dimension->id != m_dimension) return; - - PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition"); - if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); +void ApplySchematicRuleDefinition::processSchematic(AABB* chunkBox, + LevelChunk* chunk) { + if (m_completed) return; + if (chunk->level->dimension->id != m_dimension) return; - if(m_locationBox == NULL) updateLocationBox(); - if(chunkBox->intersects( m_locationBox )) - { - m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1 ); + PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition"); + if (m_schematic == NULL) + m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); + + if (m_locationBox == NULL) updateLocationBox(); + if (chunkBox->intersects(m_locationBox)) { + m_locationBox->y1 = + std::min((double)Level::maxBuildHeight, m_locationBox->y1); #ifdef _DEBUG - app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",m_schematicName.c_str(),chunk->x, chunk->z); + app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n", + m_schematicName.c_str(), chunk->x, chunk->z); #endif - PIXBeginNamedEvent(0,"Applying blocks and data"); - m_totalBlocksChanged += m_schematic->applyBlocksAndData(chunk, chunkBox, m_locationBox, m_rotation); - PIXEndNamedEvent(); + PIXBeginNamedEvent(0, "Applying blocks and data"); + m_totalBlocksChanged += m_schematic->applyBlocksAndData( + chunk, chunkBox, m_locationBox, m_rotation); + PIXEndNamedEvent(); - // Add the tileEntities - PIXBeginNamedEvent(0,"Applying tile entities"); - m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox, m_rotation); - PIXEndNamedEvent(); + // Add the tileEntities + PIXBeginNamedEvent(0, "Applying tile entities"); + m_schematic->applyTileEntities(chunk, chunkBox, m_locationBox, + m_rotation); + PIXEndNamedEvent(); - // TODO This does not take into account things that go outside the bounds of the world - int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) - * (m_locationBox->y1 - m_locationBox->y0) - * (m_locationBox->z1 - m_locationBox->z0); - if( (m_totalBlocksChanged == targetBlocks) && (m_totalBlocksChangedLighting == targetBlocks) ) - { - m_completed = true; - //m_levelGenOptions->releaseSchematicFile(m_schematicName); - //m_schematic = NULL; - } - } - PIXEndNamedEvent(); + // TODO This does not take into account things that go outside the + // bounds of the world + int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) * + (m_locationBox->y1 - m_locationBox->y0) * + (m_locationBox->z1 - m_locationBox->z0); + if ((m_totalBlocksChanged == targetBlocks) && + (m_totalBlocksChangedLighting == targetBlocks)) { + m_completed = true; + // m_levelGenOptions->releaseSchematicFile(m_schematicName); + // m_schematic = NULL; + } + } + PIXEndNamedEvent(); } -void ApplySchematicRuleDefinition::processSchematicLighting(AABB *chunkBox, LevelChunk *chunk) -{ - if( m_completed ) return; - if(chunk->level->dimension->id != m_dimension) return; - - PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition (lighting)"); - if(m_schematic == NULL) m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); +void ApplySchematicRuleDefinition::processSchematicLighting(AABB* chunkBox, + LevelChunk* chunk) { + if (m_completed) return; + if (chunk->level->dimension->id != m_dimension) return; - if(m_locationBox == NULL) updateLocationBox(); - if(chunkBox->intersects( m_locationBox )) - { - m_locationBox->y1 = std::min((double)Level::maxBuildHeight, m_locationBox->y1 ); + PIXBeginNamedEvent(0, "Processing ApplySchematicRuleDefinition (lighting)"); + if (m_schematic == NULL) + m_schematic = m_levelGenOptions->getSchematicFile(m_schematicName); + + if (m_locationBox == NULL) updateLocationBox(); + if (chunkBox->intersects(m_locationBox)) { + m_locationBox->y1 = + std::min((double)Level::maxBuildHeight, m_locationBox->y1); #ifdef _DEBUG - app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n",m_schematicName.c_str(),chunk->x, chunk->z); + app.DebugPrintf("Applying schematic %ls to chunk (%d,%d)\n", + m_schematicName.c_str(), chunk->x, chunk->z); #endif - PIXBeginNamedEvent(0,"Patching lighting"); - m_totalBlocksChangedLighting += m_schematic->applyLighting(chunk, chunkBox, m_locationBox, m_rotation); - PIXEndNamedEvent(); + PIXBeginNamedEvent(0, "Patching lighting"); + m_totalBlocksChangedLighting += m_schematic->applyLighting( + chunk, chunkBox, m_locationBox, m_rotation); + PIXEndNamedEvent(); - // TODO This does not take into account things that go outside the bounds of the world - int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) - * (m_locationBox->y1 - m_locationBox->y0) - * (m_locationBox->z1 - m_locationBox->z0); - if( (m_totalBlocksChanged == targetBlocks) && (m_totalBlocksChangedLighting == targetBlocks) ) - { - m_completed = true; - //m_levelGenOptions->releaseSchematicFile(m_schematicName); - //m_schematic = NULL; - } - } - PIXEndNamedEvent(); + // TODO This does not take into account things that go outside the + // bounds of the world + int targetBlocks = (m_locationBox->x1 - m_locationBox->x0) * + (m_locationBox->y1 - m_locationBox->y0) * + (m_locationBox->z1 - m_locationBox->z0); + if ((m_totalBlocksChanged == targetBlocks) && + (m_totalBlocksChangedLighting == targetBlocks)) { + m_completed = true; + // m_levelGenOptions->releaseSchematicFile(m_schematicName); + // m_schematic = NULL; + } + } + PIXEndNamedEvent(); } -bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1) -{ - if( m_locationBox == NULL ) updateLocationBox(); - return m_locationBox->intersects(x0,y0,z0,x1,y1,z1); +bool ApplySchematicRuleDefinition::checkIntersects(int x0, int y0, int z0, + int x1, int y1, int z1) { + if (m_locationBox == NULL) updateLocationBox(); + return m_locationBox->intersects(x0, y0, z0, x1, y1, z1); } -int ApplySchematicRuleDefinition::getMinY() -{ - if( m_locationBox == NULL ) updateLocationBox(); - return m_locationBox->y0; +int ApplySchematicRuleDefinition::getMinY() { + if (m_locationBox == NULL) updateLocationBox(); + return m_locationBox->y0; } -void ApplySchematicRuleDefinition::reset() -{ - m_totalBlocksChanged = 0; - m_totalBlocksChangedLighting = 0; - m_completed = false; +void ApplySchematicRuleDefinition::reset() { + m_totalBlocksChanged = 0; + m_totalBlocksChangedLighting = 0; + m_completed = false; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h index a7495c841..e3c5b425f 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/ApplySchematicRuleDefinition.h @@ -8,44 +8,47 @@ class LevelChunk; class LevelGenerationOptions; class GRFObject; -class ApplySchematicRuleDefinition : public GameRuleDefinition -{ +class ApplySchematicRuleDefinition : public GameRuleDefinition { private: - LevelGenerationOptions *m_levelGenOptions; - std::wstring m_schematicName; - ConsoleSchematicFile *m_schematic; - Vec3 *m_location; - AABB *m_locationBox; - ConsoleSchematicFile::ESchematicRotation m_rotation; - int m_dimension; + LevelGenerationOptions* m_levelGenOptions; + std::wstring m_schematicName; + ConsoleSchematicFile* m_schematic; + Vec3* m_location; + AABB* m_locationBox; + ConsoleSchematicFile::ESchematicRotation m_rotation; + int m_dimension; - __int64 m_totalBlocksChanged; - __int64 m_totalBlocksChangedLighting; - bool m_completed; + __int64 m_totalBlocksChanged; + __int64 m_totalBlocksChangedLighting; + bool m_completed; - void updateLocationBox(); -public: - ApplySchematicRuleDefinition(LevelGenerationOptions *levelGenOptions); - ~ApplySchematicRuleDefinition(); + void updateLocationBox(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_ApplySchematic; } - - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); +public: + ApplySchematicRuleDefinition(LevelGenerationOptions* levelGenOptions); + ~ApplySchematicRuleDefinition(); - void processSchematic(AABB *chunkBox, LevelChunk *chunk); - void processSchematicLighting(AABB *chunkBox, LevelChunk *chunk); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_ApplySchematic; + } - bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); - int getMinY(); + virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - bool isComplete() { return m_completed; } + void processSchematic(AABB* chunkBox, LevelChunk* chunk); + void processSchematicLighting(AABB* chunkBox, LevelChunk* chunk); - std::wstring getSchematicName() { return m_schematicName; } + bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); + int getMinY(); - /** 4J-JEV: - * This GameRuleDefinition contains limited game state. - * Reset any state to how it should be before a new game. - */ - void reset(); + bool isComplete() { return m_completed; } + + std::wstring getSchematicName() { return m_schematicName; } + + /** 4J-JEV: + * This GameRuleDefinition contains limited game state. + * Reset any state to how it should be before a new game. + */ + void reset(); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.cpp b/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.cpp index eb8809555..9ee41e272 100644 --- a/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.cpp @@ -2,58 +2,48 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "BiomeOverride.h" -BiomeOverride::BiomeOverride() -{ - m_tile = 0; - m_topTile = 0; - m_biomeId = 0; +BiomeOverride::BiomeOverride() { + m_tile = 0; + m_topTile = 0; + m_biomeId = 0; } -void BiomeOverride::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - GameRuleDefinition::writeAttributes(dos, numAttrs + 3); +void BiomeOverride::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + GameRuleDefinition::writeAttributes(dos, numAttrs + 3); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_biomeId); - dos->writeUTF(_toString(m_biomeId)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId); - dos->writeUTF(_toString(m_tile)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_topTileId); - dos->writeUTF(_toString(m_topTile)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_biomeId); + dos->writeUTF(_toString(m_biomeId)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId); + dos->writeUTF(_toString(m_tile)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_topTileId); + dos->writeUTF(_toString(m_topTile)); } -void BiomeOverride::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"tileId") == 0) - { - int value = _fromString(attributeValue); - m_tile = value; - app.DebugPrintf("BiomeOverride: Adding parameter tileId=%d\n",m_tile); - } - else if(attributeName.compare(L"topTileId") == 0) - { - int value = _fromString(attributeValue); - m_topTile = value; - app.DebugPrintf("BiomeOverride: Adding parameter topTileId=%d\n",m_topTile); - } - else if(attributeName.compare(L"biomeId") == 0) - { - int value = _fromString(attributeValue); - m_biomeId = value; - app.DebugPrintf("BiomeOverride: Adding parameter biomeId=%d\n",m_biomeId); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void BiomeOverride::addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue) { + if (attributeName.compare(L"tileId") == 0) { + int value = _fromString(attributeValue); + m_tile = value; + app.DebugPrintf("BiomeOverride: Adding parameter tileId=%d\n", m_tile); + } else if (attributeName.compare(L"topTileId") == 0) { + int value = _fromString(attributeValue); + m_topTile = value; + app.DebugPrintf("BiomeOverride: Adding parameter topTileId=%d\n", + m_topTile); + } else if (attributeName.compare(L"biomeId") == 0) { + int value = _fromString(attributeValue); + m_biomeId = value; + app.DebugPrintf("BiomeOverride: Adding parameter biomeId=%d\n", + m_biomeId); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -bool BiomeOverride::isBiome(int id) -{ - return m_biomeId == id; -} +bool BiomeOverride::isBiome(int id) { return m_biomeId == id; } -void BiomeOverride::getTileValues(std::uint8_t &tile, std::uint8_t &topTile) -{ - if(m_tile != 0) tile = m_tile; - if(m_topTile != 0) topTile = m_topTile; +void BiomeOverride::getTileValues(std::uint8_t& tile, std::uint8_t& topTile) { + if (m_tile != 0) tile = m_tile; + if (m_topTile != 0) topTile = m_topTile; } diff --git a/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.h b/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.h index 29cd64f5b..191cbff33 100644 --- a/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.h +++ b/Minecraft.Client/Platform/Common/GameRules/BiomeOverride.h @@ -1,23 +1,25 @@ #pragma once -//using namespace std; +// using namespace std; #include "GameRuleDefinition.h" -class BiomeOverride : public GameRuleDefinition -{ +class BiomeOverride : public GameRuleDefinition { private: - std::uint8_t m_topTile; - std::uint8_t m_tile; - int m_biomeId; + std::uint8_t m_topTile; + std::uint8_t m_tile; + int m_biomeId; public: - BiomeOverride(); + BiomeOverride(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_BiomeOverride; } - - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_BiomeOverride; + } - bool isBiome(int id); - void getTileValues(std::uint8_t &tile, std::uint8_t &topTile); + virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); + + bool isBiome(int id); + void getTileValues(std::uint8_t& tile, std::uint8_t& topTile); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.cpp index a97b585e0..f3f601ab6 100644 --- a/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.cpp @@ -6,112 +6,111 @@ #include "../../Minecraft.World/Network/Connection.h" #include "../../Minecraft.World/Headers/net.minecraft.network.packet.h" -CollectItemRuleDefinition::CollectItemRuleDefinition() -{ - m_itemId = 0; - m_auxValue = 0; - m_quantity = 0; +CollectItemRuleDefinition::CollectItemRuleDefinition() { + m_itemId = 0; + m_auxValue = 0; + m_quantity = 0; } -CollectItemRuleDefinition::~CollectItemRuleDefinition() -{ +CollectItemRuleDefinition::~CollectItemRuleDefinition() {} + +void CollectItemRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttributes) { + GameRuleDefinition::writeAttributes(dos, numAttributes + 3); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); + dos->writeUTF(_toString(m_itemId)); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); + dos->writeUTF(_toString(m_auxValue)); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); + dos->writeUTF(_toString(m_quantity)); } -void CollectItemRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) -{ - GameRuleDefinition::writeAttributes(dos, numAttributes + 3); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_itemId); - dos->writeUTF( _toString( m_itemId ) ); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_auxValue); - dos->writeUTF( _toString( m_auxValue ) ); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_quantity); - dos->writeUTF( _toString( m_quantity ) ); +void CollectItemRuleDefinition::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"itemId") == 0) { + m_itemId = _fromString(attributeValue); + app.DebugPrintf("CollectItemRule: Adding parameter itemId=%d\n", + m_itemId); + } else if (attributeName.compare(L"auxValue") == 0) { + m_auxValue = _fromString(attributeValue); + app.DebugPrintf("CollectItemRule: Adding parameter m_auxValue=%d\n", + m_auxValue); + } else if (attributeName.compare(L"quantity") == 0) { + m_quantity = _fromString(attributeValue); + app.DebugPrintf("CollectItemRule: Adding parameter m_quantity=%d\n", + m_quantity); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -void CollectItemRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"itemId") == 0) - { - m_itemId = _fromString(attributeValue); - app.DebugPrintf("CollectItemRule: Adding parameter itemId=%d\n",m_itemId); - } - else if(attributeName.compare(L"auxValue") == 0) - { - m_auxValue = _fromString(attributeValue); - app.DebugPrintf("CollectItemRule: Adding parameter m_auxValue=%d\n",m_auxValue); - } - else if(attributeName.compare(L"quantity") == 0) - { - m_quantity = _fromString(attributeValue); - app.DebugPrintf("CollectItemRule: Adding parameter m_quantity=%d\n",m_quantity); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +int CollectItemRuleDefinition::getGoal() { return m_quantity; } + +int CollectItemRuleDefinition::getProgress(GameRule* rule) { + GameRule::ValueType value = rule->getParameter(L"iQuantity"); + return value.i; } -int CollectItemRuleDefinition::getGoal() -{ - return m_quantity; +void CollectItemRuleDefinition::populateGameRule( + GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) { + GameRule::ValueType value; + value.i = 0; + rule->setParameter(L"iQuantity", value); + + GameRuleDefinition::populateGameRule(type, rule); } -int CollectItemRuleDefinition::getProgress(GameRule *rule) -{ - GameRule::ValueType value = rule->getParameter(L"iQuantity"); - return value.i; +bool CollectItemRuleDefinition::onCollectItem( + GameRule* rule, std::shared_ptr item) { + bool statusChanged = false; + if (item != NULL && item->id == m_itemId && + item->getAuxValue() == m_auxValue && + item->get4JData() == m_4JDataValue) { + if (!getComplete(rule)) { + GameRule::ValueType value = rule->getParameter(L"iQuantity"); + int quantityCollected = (value.i += item->count); + rule->setParameter(L"iQuantity", value); + + statusChanged = true; + + if (quantityCollected >= m_quantity) { + setComplete(rule, true); + app.DebugPrintf( + "Completed CollectItemRule with info - itemId:%d, " + "auxValue:%d, quantity:%d, dataTag:%d\n", + m_itemId, m_auxValue, m_quantity, m_4JDataValue); + + if (rule->getConnection() != NULL) { + rule->getConnection()->send( + std::shared_ptr( + new UpdateGameRuleProgressPacket( + getActionType(), this->m_descriptionId, + m_itemId, m_auxValue, this->m_4JDataValue, NULL, + 0))); + } + } + } + } + return statusChanged; } -void CollectItemRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule) -{ - GameRule::ValueType value; - value.i = 0; - rule->setParameter(L"iQuantity",value); - - GameRuleDefinition::populateGameRule(type, rule); -} - -bool CollectItemRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr item) -{ - bool statusChanged = false; - if(item != NULL && item->id == m_itemId && item->getAuxValue() == m_auxValue && item->get4JData() == m_4JDataValue) - { - if(!getComplete(rule)) - { - GameRule::ValueType value = rule->getParameter(L"iQuantity"); - int quantityCollected = (value.i += item->count); - rule->setParameter(L"iQuantity",value); - - statusChanged = true; - - if(quantityCollected >= m_quantity) - { - setComplete(rule, true); - app.DebugPrintf("Completed CollectItemRule with info - itemId:%d, auxValue:%d, quantity:%d, dataTag:%d\n", m_itemId,m_auxValue,m_quantity,m_4JDataValue); - - if(rule->getConnection() != NULL) - { - rule->getConnection()->send( std::shared_ptr( new UpdateGameRuleProgressPacket(getActionType(), this->m_descriptionId, m_itemId, m_auxValue, this->m_4JDataValue,NULL,0))); - } - } - } - } - return statusChanged; -} - -std::wstring CollectItemRuleDefinition::generateXml(std::shared_ptr item) -{ - // 4J Stu - This should be kept in sync with the GameRulesDefinition.xsd - std::wstring xml = L""; - if(item != NULL) - { - xml = L"(item->id) + L"\" quantity=\"SET\" descriptionName=\"OPTIONAL\" promptName=\"OPTIONAL\""; - if(item->getAuxValue() != 0) xml += L" auxValue=\"" + _toString(item->getAuxValue()) + L"\""; - if(item->get4JData() != 0) xml += L" dataTag=\"" + _toString(item->get4JData()) + L"\""; - xml += L"/>\n"; - } - return xml; +std::wstring CollectItemRuleDefinition::generateXml( + std::shared_ptr item) { + // 4J Stu - This should be kept in sync with the GameRulesDefinition.xsd + std::wstring xml = L""; + if (item != NULL) { + xml = L"(item->id) + + L"\" quantity=\"SET\" descriptionName=\"OPTIONAL\" " + L"promptName=\"OPTIONAL\""; + if (item->getAuxValue() != 0) + xml += + L" auxValue=\"" + _toString(item->getAuxValue()) + L"\""; + if (item->get4JData() != 0) + xml += L" dataTag=\"" + _toString(item->get4JData()) + L"\""; + xml += L"/>\n"; + } + return xml; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.h index d9bc6b7e3..5b0e4283b 100644 --- a/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/CollectItemRuleDefinition.h @@ -6,35 +6,38 @@ class Pos; class UseTileRuleDefinition; class ItemInstance; -class CollectItemRuleDefinition : public GameRuleDefinition -{ +class CollectItemRuleDefinition : public GameRuleDefinition { private: - // These values should map directly to the xsd definition for this Rule - int m_itemId; - unsigned char m_auxValue; - int m_quantity; + // These values should map directly to the xsd definition for this Rule + int m_itemId; + unsigned char m_auxValue; + int m_quantity; public: - CollectItemRuleDefinition(); - ~CollectItemRuleDefinition(); + CollectItemRuleDefinition(); + ~CollectItemRuleDefinition(); - ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_CollectItemRule; } + ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_CollectItemRule; + } - virtual void writeAttributes(DataOutputStream *, unsigned int numAttributes); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual void writeAttributes(DataOutputStream*, unsigned int numAttributes); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - virtual int getGoal(); - virtual int getProgress(GameRule *rule); - - virtual int getIcon() { return m_itemId; } - virtual int getAuxValue() { return m_auxValue; } + virtual int getGoal(); + virtual int getProgress(GameRule* rule); - void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule); + virtual int getIcon() { return m_itemId; } + virtual int getAuxValue() { return m_auxValue; } - bool onCollectItem(GameRule *rule, std::shared_ptr item); + void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, + GameRule* rule); - static std::wstring generateXml(std::shared_ptr item); + bool onCollectItem(GameRule* rule, std::shared_ptr item); -private: - //static std::wstring generateXml(CollectItemRuleDefinition *ruleDef); + static std::wstring generateXml(std::shared_ptr item); + +private: + // static std::wstring generateXml(CollectItemRuleDefinition *ruleDef); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.cpp index 31b0ec051..82d8fb5dd 100644 --- a/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.cpp @@ -5,62 +5,66 @@ #include "../../Minecraft.World/Network/Connection.h" #include "../../Minecraft.World/Headers/net.minecraft.network.packet.h" -void CompleteAllRuleDefinition::getChildren(std::vector *children) -{ - CompoundGameRuleDefinition::getChildren(children); +void CompleteAllRuleDefinition::getChildren( + std::vector* children) { + CompoundGameRuleDefinition::getChildren(children); } -bool CompleteAllRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z) -{ - bool statusChanged = CompoundGameRuleDefinition::onUseTile(rule,tileId,x,y,z); - if(statusChanged) updateStatus(rule); - return statusChanged; +bool CompleteAllRuleDefinition::onUseTile(GameRule* rule, int tileId, int x, + int y, int z) { + bool statusChanged = + CompoundGameRuleDefinition::onUseTile(rule, tileId, x, y, z); + if (statusChanged) updateStatus(rule); + return statusChanged; } -bool CompleteAllRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr item) -{ - bool statusChanged = CompoundGameRuleDefinition::onCollectItem(rule,item); - if(statusChanged) updateStatus(rule); - return statusChanged; +bool CompleteAllRuleDefinition::onCollectItem( + GameRule* rule, std::shared_ptr item) { + bool statusChanged = CompoundGameRuleDefinition::onCollectItem(rule, item); + if (statusChanged) updateStatus(rule); + return statusChanged; } -void CompleteAllRuleDefinition::updateStatus(GameRule *rule) -{ - int goal = 0; - int progress = 0; - for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it) - { - if(it->second.isPointer) - { - goal += it->second.gr->getGameRuleDefinition()->getGoal(); - progress += it->second.gr->getGameRuleDefinition()->getProgress(it->second.gr); - } - } - if(rule->getConnection() != NULL) - { - PacketData data; - data.goal = goal; - data.progress = progress; +void CompleteAllRuleDefinition::updateStatus(GameRule* rule) { + int goal = 0; + int progress = 0; + for (AUTO_VAR(it, rule->m_parameters.begin()); + it != rule->m_parameters.end(); ++it) { + if (it->second.isPointer) { + goal += it->second.gr->getGameRuleDefinition()->getGoal(); + progress += it->second.gr->getGameRuleDefinition()->getProgress( + it->second.gr); + } + } + if (rule->getConnection() != NULL) { + PacketData data; + data.goal = goal; + data.progress = progress; - int icon = -1; - int auxValue = 0; - - if(m_lastRuleStatusChanged != NULL) - { - icon = m_lastRuleStatusChanged->getIcon(); - auxValue = m_lastRuleStatusChanged->getAuxValue(); - m_lastRuleStatusChanged = NULL; - } - rule->getConnection()->send( std::shared_ptr( new UpdateGameRuleProgressPacket(getActionType(), this->m_descriptionId,icon, auxValue, 0,&data,sizeof(PacketData)))); - } - app.DebugPrintf("Updated CompleteAllRule - Completed %d of %d\n", progress, goal); + int icon = -1; + int auxValue = 0; + + if (m_lastRuleStatusChanged != NULL) { + icon = m_lastRuleStatusChanged->getIcon(); + auxValue = m_lastRuleStatusChanged->getAuxValue(); + m_lastRuleStatusChanged = NULL; + } + rule->getConnection()->send( + std::shared_ptr( + new UpdateGameRuleProgressPacket( + getActionType(), this->m_descriptionId, icon, auxValue, 0, + &data, sizeof(PacketData)))); + } + app.DebugPrintf("Updated CompleteAllRule - Completed %d of %d\n", progress, + goal); } -std::wstring CompleteAllRuleDefinition::generateDescriptionString(const std::wstring &description, void *data, int dataLength) -{ - PacketData *values = (PacketData *)data; - std::wstring newDesc = description; - newDesc = replaceAll(newDesc,L"{*progress*}",_toString(values->progress)); - newDesc = replaceAll(newDesc,L"{*goal*}",_toString(values->goal)); - return newDesc; +std::wstring CompleteAllRuleDefinition::generateDescriptionString( + const std::wstring& description, void* data, int dataLength) { + PacketData* values = (PacketData*)data; + std::wstring newDesc = description; + newDesc = + replaceAll(newDesc, L"{*progress*}", _toString(values->progress)); + newDesc = replaceAll(newDesc, L"{*goal*}", _toString(values->goal)); + return newDesc; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.h index dbf9365b8..5f90abc34 100644 --- a/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/CompleteAllRuleDefinition.h @@ -2,25 +2,27 @@ #include "CompoundGameRuleDefinition.h" -class CompleteAllRuleDefinition : public CompoundGameRuleDefinition -{ +class CompleteAllRuleDefinition : public CompoundGameRuleDefinition { private: - typedef struct _packetData - { - int goal; - int progress; - } PacketData; + typedef struct _packetData { + int goal; + int progress; + } PacketData; public: - ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_CompleteAllRule; } + ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_CompleteAllRule; + } - virtual void getChildren(std::vector *children); + virtual void getChildren(std::vector* children); - virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z); - virtual bool onCollectItem(GameRule *rule, std::shared_ptr item); + virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z); + virtual bool onCollectItem(GameRule* rule, + std::shared_ptr item); - static std::wstring generateDescriptionString(const std::wstring &description, void *data, int dataLength); + static std::wstring generateDescriptionString( + const std::wstring& description, void* data, int dataLength); private: - void updateStatus(GameRule *rule); + void updateStatus(GameRule* rule); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.cpp index 4fca395a8..cd21388e4 100644 --- a/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.cpp @@ -4,115 +4,105 @@ #include "CompoundGameRuleDefinition.h" #include "ConsoleGameRules.h" -CompoundGameRuleDefinition::CompoundGameRuleDefinition() -{ - m_lastRuleStatusChanged = NULL; +CompoundGameRuleDefinition::CompoundGameRuleDefinition() { + m_lastRuleStatusChanged = NULL; } -CompoundGameRuleDefinition::~CompoundGameRuleDefinition() -{ - for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) - { - delete (*it); - } +CompoundGameRuleDefinition::~CompoundGameRuleDefinition() { + for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) { + delete (*it); + } } -void CompoundGameRuleDefinition::getChildren(std::vector *children) -{ - GameRuleDefinition::getChildren(children); - for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); it++) - children->push_back(*it); +void CompoundGameRuleDefinition::getChildren( + std::vector* children) { + GameRuleDefinition::getChildren(children); + for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); it++) + children->push_back(*it); } -GameRuleDefinition *CompoundGameRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ - GameRuleDefinition *rule = NULL; - if(ruleType == ConsoleGameRules::eGameRuleType_CompleteAllRule) - { - rule = new CompleteAllRuleDefinition(); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_CollectItemRule) - { - rule = new CollectItemRuleDefinition(); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_UseTileRule) - { - rule = new UseTileRuleDefinition(); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_UpdatePlayerRule) - { - rule = new UpdatePlayerRuleDefinition(); - } - else - { +GameRuleDefinition* CompoundGameRuleDefinition::addChild( + ConsoleGameRules::EGameRuleType ruleType) { + GameRuleDefinition* rule = NULL; + if (ruleType == ConsoleGameRules::eGameRuleType_CompleteAllRule) { + rule = new CompleteAllRuleDefinition(); + } else if (ruleType == ConsoleGameRules::eGameRuleType_CollectItemRule) { + rule = new CollectItemRuleDefinition(); + } else if (ruleType == ConsoleGameRules::eGameRuleType_UseTileRule) { + rule = new UseTileRuleDefinition(); + } else if (ruleType == ConsoleGameRules::eGameRuleType_UpdatePlayerRule) { + rule = new UpdatePlayerRuleDefinition(); + } else { #ifndef _CONTENT_PACKAGE - wprintf(L"CompoundGameRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); + wprintf( + L"CompoundGameRuleDefinition: Attempted to add invalid child rule " + L"- %d\n", + ruleType); #endif - } - if(rule != NULL) m_children.push_back(rule); - return rule; + } + if (rule != NULL) m_children.push_back(rule); + return rule; } -void CompoundGameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule) -{ - GameRule *newRule = NULL; - int i = 0; - for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) - { - newRule = new GameRule(*it, rule->getConnection() ); - (*it)->populateGameRule(type,newRule); +void CompoundGameRuleDefinition::populateGameRule( + GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) { + GameRule* newRule = NULL; + int i = 0; + for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) { + newRule = new GameRule(*it, rule->getConnection()); + (*it)->populateGameRule(type, newRule); - GameRule::ValueType value; - value.gr = newRule; - value.isPointer = true; + GameRule::ValueType value; + value.gr = newRule; + value.isPointer = true; - // Somehow add the newRule to the current rule - rule->setParameter(L"rule" + _toString(i),value); - ++i; - } - GameRuleDefinition::populateGameRule(type, rule); + // Somehow add the newRule to the current rule + rule->setParameter(L"rule" + _toString(i), value); + ++i; + } + GameRuleDefinition::populateGameRule(type, rule); } -bool CompoundGameRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z) -{ - bool statusChanged = false; - for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it) - { - if(it->second.isPointer) - { - bool changed = it->second.gr->getGameRuleDefinition()->onUseTile(it->second.gr,tileId,x,y,z); - if(!statusChanged && changed) - { - m_lastRuleStatusChanged = it->second.gr->getGameRuleDefinition(); - statusChanged = true; - } - } - } - return statusChanged; +bool CompoundGameRuleDefinition::onUseTile(GameRule* rule, int tileId, int x, + int y, int z) { + bool statusChanged = false; + for (AUTO_VAR(it, rule->m_parameters.begin()); + it != rule->m_parameters.end(); ++it) { + if (it->second.isPointer) { + bool changed = it->second.gr->getGameRuleDefinition()->onUseTile( + it->second.gr, tileId, x, y, z); + if (!statusChanged && changed) { + m_lastRuleStatusChanged = + it->second.gr->getGameRuleDefinition(); + statusChanged = true; + } + } + } + return statusChanged; } -bool CompoundGameRuleDefinition::onCollectItem(GameRule *rule, std::shared_ptr item) -{ - bool statusChanged = false; - for(AUTO_VAR(it, rule->m_parameters.begin()); it != rule->m_parameters.end(); ++it) - { - if(it->second.isPointer) - { - bool changed = it->second.gr->getGameRuleDefinition()->onCollectItem(it->second.gr,item); - if(!statusChanged && changed) - { - m_lastRuleStatusChanged = it->second.gr->getGameRuleDefinition(); - statusChanged = true; - } - } - } - return statusChanged; +bool CompoundGameRuleDefinition::onCollectItem( + GameRule* rule, std::shared_ptr item) { + bool statusChanged = false; + for (AUTO_VAR(it, rule->m_parameters.begin()); + it != rule->m_parameters.end(); ++it) { + if (it->second.isPointer) { + bool changed = + it->second.gr->getGameRuleDefinition()->onCollectItem( + it->second.gr, item); + if (!statusChanged && changed) { + m_lastRuleStatusChanged = + it->second.gr->getGameRuleDefinition(); + statusChanged = true; + } + } + } + return statusChanged; } -void CompoundGameRuleDefinition::postProcessPlayer(std::shared_ptr player) -{ - for(AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) - { - (*it)->postProcessPlayer(player); - } +void CompoundGameRuleDefinition::postProcessPlayer( + std::shared_ptr player) { + for (AUTO_VAR(it, m_children.begin()); it != m_children.end(); ++it) { + (*it)->postProcessPlayer(player); + } } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.h index ad13f67b9..fa1b04ce0 100644 --- a/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/CompoundGameRuleDefinition.h @@ -2,22 +2,26 @@ #include "GameRuleDefinition.h" -class CompoundGameRuleDefinition : public GameRuleDefinition -{ +class CompoundGameRuleDefinition : public GameRuleDefinition { protected: - std::vector m_children; + std::vector m_children; + protected: - GameRuleDefinition *m_lastRuleStatusChanged; + GameRuleDefinition* m_lastRuleStatusChanged; + public: - CompoundGameRuleDefinition(); - virtual ~CompoundGameRuleDefinition(); + CompoundGameRuleDefinition(); + virtual ~CompoundGameRuleDefinition(); - virtual void getChildren(std::vector *children); - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); + virtual void getChildren(std::vector* children); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); - virtual void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule); + virtual void populateGameRule( + GameRulesInstance::EGameRulesInstanceType type, GameRule* rule); - virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z); - virtual bool onCollectItem(GameRule *rule, std::shared_ptr item); - virtual void postProcessPlayer(std::shared_ptr player); + virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z); + virtual bool onCollectItem(GameRule* rule, + std::shared_ptr item); + virtual void postProcessPlayer(std::shared_ptr player); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleGameRulesConstants.h b/Minecraft.Client/Platform/Common/GameRules/ConsoleGameRulesConstants.h index 93c012ac2..fb5766eb6 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleGameRulesConstants.h +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleGameRulesConstants.h @@ -1,120 +1,118 @@ #pragma once -//#include " +// #include " -class ConsoleGameRules -{ +class ConsoleGameRules { public: - enum EGameRuleType - { - eGameRuleType_Invalid = -1, - eGameRuleType_Root = 0, // This is the top level rule that defines a game mode, this is used to generate data for new players + enum EGameRuleType { + eGameRuleType_Invalid = -1, + eGameRuleType_Root = + 0, // This is the top level rule that defines a game mode, this is + // used to generate data for new players - eGameRuleType_LevelGenerationOptions, - eGameRuleType_ApplySchematic, - eGameRuleType_GenerateStructure, - eGameRuleType_GenerateBox, - eGameRuleType_PlaceBlock, - eGameRuleType_PlaceContainer, - eGameRuleType_PlaceSpawner, - eGameRuleType_BiomeOverride, - eGameRuleType_StartFeature, + eGameRuleType_LevelGenerationOptions, + eGameRuleType_ApplySchematic, + eGameRuleType_GenerateStructure, + eGameRuleType_GenerateBox, + eGameRuleType_PlaceBlock, + eGameRuleType_PlaceContainer, + eGameRuleType_PlaceSpawner, + eGameRuleType_BiomeOverride, + eGameRuleType_StartFeature, - eGameRuleType_AddItem, - eGameRuleType_AddEnchantment, + eGameRuleType_AddItem, + eGameRuleType_AddEnchantment, - eGameRuleType_LevelRules, - eGameRuleType_NamedArea, + eGameRuleType_LevelRules, + eGameRuleType_NamedArea, - eGameRuleType_UseTileRule, - eGameRuleType_CollectItemRule, - eGameRuleType_CompleteAllRule, - eGameRuleType_UpdatePlayerRule, + eGameRuleType_UseTileRule, + eGameRuleType_CollectItemRule, + eGameRuleType_CompleteAllRule, + eGameRuleType_UpdatePlayerRule, - eGameRuleType_Count - }; + eGameRuleType_Count + }; - enum EGameRuleAttr - { - eGameRuleAttr_Invalid = -1, + enum EGameRuleAttr { + eGameRuleAttr_Invalid = -1, - eGameRuleAttr_descriptionName = 0, - eGameRuleAttr_promptName, - eGameRuleAttr_dataTag, + eGameRuleAttr_descriptionName = 0, + eGameRuleAttr_promptName, + eGameRuleAttr_dataTag, - eGameRuleAttr_enchantmentId, - eGameRuleAttr_enchantmentLevel, + eGameRuleAttr_enchantmentId, + eGameRuleAttr_enchantmentLevel, - eGameRuleAttr_itemId, - eGameRuleAttr_quantity, - eGameRuleAttr_auxValue, - eGameRuleAttr_slot, + eGameRuleAttr_itemId, + eGameRuleAttr_quantity, + eGameRuleAttr_auxValue, + eGameRuleAttr_slot, - eGameRuleAttr_name, + eGameRuleAttr_name, - eGameRuleAttr_food, - eGameRuleAttr_health, + eGameRuleAttr_food, + eGameRuleAttr_health, - eGameRuleAttr_tileId, - eGameRuleAttr_useCoords, + eGameRuleAttr_tileId, + eGameRuleAttr_useCoords, - eGameRuleAttr_seed, - eGameRuleAttr_flatworld, + eGameRuleAttr_seed, + eGameRuleAttr_flatworld, - eGameRuleAttr_filename, - eGameRuleAttr_rot, + eGameRuleAttr_filename, + eGameRuleAttr_rot, - eGameRuleAttr_data, - eGameRuleAttr_block, - eGameRuleAttr_entity, + eGameRuleAttr_data, + eGameRuleAttr_block, + eGameRuleAttr_entity, - eGameRuleAttr_facing, + eGameRuleAttr_facing, - eGameRuleAttr_edgeTile, - eGameRuleAttr_fillTile, - eGameRuleAttr_skipAir, + eGameRuleAttr_edgeTile, + eGameRuleAttr_fillTile, + eGameRuleAttr_skipAir, - eGameRuleAttr_x, - eGameRuleAttr_x0, - eGameRuleAttr_x1, - - eGameRuleAttr_y, - eGameRuleAttr_y0, - eGameRuleAttr_y1, + eGameRuleAttr_x, + eGameRuleAttr_x0, + eGameRuleAttr_x1, - eGameRuleAttr_z, - eGameRuleAttr_z0, - eGameRuleAttr_z1, + eGameRuleAttr_y, + eGameRuleAttr_y0, + eGameRuleAttr_y1, - eGameRuleAttr_chunkX, - eGameRuleAttr_chunkZ, + eGameRuleAttr_z, + eGameRuleAttr_z0, + eGameRuleAttr_z1, - eGameRuleAttr_yRot, + eGameRuleAttr_chunkX, + eGameRuleAttr_chunkZ, - eGameRuleAttr_spawnX, - eGameRuleAttr_spawnY, - eGameRuleAttr_spawnZ, + eGameRuleAttr_yRot, - eGameRuleAttr_orientation, - eGameRuleAttr_dimension, + eGameRuleAttr_spawnX, + eGameRuleAttr_spawnY, + eGameRuleAttr_spawnZ, - eGameRuleAttr_topTileId, - eGameRuleAttr_biomeId, + eGameRuleAttr_orientation, + eGameRuleAttr_dimension, - eGameRuleAttr_feature, + eGameRuleAttr_topTileId, + eGameRuleAttr_biomeId, - eGameRuleAttr_Count - }; + eGameRuleAttr_feature, - static void write(DataOutputStream *dos, ConsoleGameRules::EGameRuleType eType) - { - dos->writeInt(eType); - } + eGameRuleAttr_Count + }; - static void write(DataOutputStream *dos, ConsoleGameRules::EGameRuleAttr eAttr) - { - dos->writeInt(static_cast(eGameRuleType_Count) + - static_cast(eAttr)); - } + static void write(DataOutputStream* dos, + ConsoleGameRules::EGameRuleType eType) { + dos->writeInt(eType); + } + static void write(DataOutputStream* dos, + ConsoleGameRules::EGameRuleAttr eAttr) { + dos->writeInt(static_cast(eGameRuleType_Count) + + static_cast(eAttr)); + } }; diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.cpp index 858d6cbce..cec5b1214 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.cpp @@ -7,177 +7,155 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Headers/net.minecraft.h" -ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0) -{ - m_x = m_y = m_z = 0; - boundingBox = NULL; - orientation = Direction::NORTH; - m_dimension = 0; +ConsoleGenerateStructure::ConsoleGenerateStructure() : StructurePiece(0) { + m_x = m_y = m_z = 0; + boundingBox = NULL; + orientation = Direction::NORTH; + m_dimension = 0; } -void ConsoleGenerateStructure::getChildren(std::vector *children) -{ - GameRuleDefinition::getChildren(children); - - for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); it++) - children->push_back( *it ); +void ConsoleGenerateStructure::getChildren( + std::vector* children) { + GameRuleDefinition::getChildren(children); + + for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); it++) + children->push_back(*it); } -GameRuleDefinition *ConsoleGenerateStructure::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ - GameRuleDefinition *rule = NULL; - if(ruleType == ConsoleGameRules::eGameRuleType_GenerateBox) - { - rule = new XboxStructureActionGenerateBox(); - m_actions.push_back((XboxStructureActionGenerateBox *)rule); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock) - { - rule = new XboxStructureActionPlaceBlock(); - m_actions.push_back((XboxStructureActionPlaceBlock *)rule); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer) - { - rule = new XboxStructureActionPlaceContainer(); - m_actions.push_back((XboxStructureActionPlaceContainer *)rule); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner) - { - rule = new XboxStructureActionPlaceSpawner(); - m_actions.push_back((XboxStructureActionPlaceSpawner *)rule); - } - else - { +GameRuleDefinition* ConsoleGenerateStructure::addChild( + ConsoleGameRules::EGameRuleType ruleType) { + GameRuleDefinition* rule = NULL; + if (ruleType == ConsoleGameRules::eGameRuleType_GenerateBox) { + rule = new XboxStructureActionGenerateBox(); + m_actions.push_back((XboxStructureActionGenerateBox*)rule); + } else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceBlock) { + rule = new XboxStructureActionPlaceBlock(); + m_actions.push_back((XboxStructureActionPlaceBlock*)rule); + } else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceContainer) { + rule = new XboxStructureActionPlaceContainer(); + m_actions.push_back((XboxStructureActionPlaceContainer*)rule); + } else if (ruleType == ConsoleGameRules::eGameRuleType_PlaceSpawner) { + rule = new XboxStructureActionPlaceSpawner(); + m_actions.push_back((XboxStructureActionPlaceSpawner*)rule); + } else { #ifndef _CONTENT_PACKAGE - wprintf(L"ConsoleGenerateStructure: Attempted to add invalid child rule - %d\n", ruleType ); + wprintf( + L"ConsoleGenerateStructure: Attempted to add invalid child rule - " + L"%d\n", + ruleType); #endif - } - return rule; + } + return rule; } -void ConsoleGenerateStructure::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - GameRuleDefinition::writeAttributes(dos, numAttrs + 5); +void ConsoleGenerateStructure::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + GameRuleDefinition::writeAttributes(dos, numAttrs + 5); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); - dos->writeUTF(_toString(m_x)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); - dos->writeUTF(_toString(m_y)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); - dos->writeUTF(_toString(m_z)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); + dos->writeUTF(_toString(m_x)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); + dos->writeUTF(_toString(m_y)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); + dos->writeUTF(_toString(m_z)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_orientation); - dos->writeUTF(_toString(orientation)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dimension); - dos->writeUTF(_toString(m_dimension)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_orientation); + dos->writeUTF(_toString(orientation)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dimension); + dos->writeUTF(_toString(m_dimension)); } -void ConsoleGenerateStructure::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"x") == 0) - { - int value = _fromString(attributeValue); - m_x = value; - app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n",m_x); - } - else if(attributeName.compare(L"y") == 0) - { - int value = _fromString(attributeValue); - m_y = value; - app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n",m_y); - } - else if(attributeName.compare(L"z") == 0) - { - int value = _fromString(attributeValue); - m_z = value; - app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n",m_z); - } - else if(attributeName.compare(L"orientation") == 0) - { - int value = _fromString(attributeValue); - orientation = value; - app.DebugPrintf("ConsoleGenerateStructure: Adding parameter orientation=%d\n",orientation); - } - else if(attributeName.compare(L"dim") == 0) - { - m_dimension = _fromString(attributeValue); - if(m_dimension > 1 || m_dimension < -1) m_dimension = 0; - app.DebugPrintf("ApplySchematicRuleDefinition: Adding parameter dimension=%d\n",m_dimension); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void ConsoleGenerateStructure::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"x") == 0) { + int value = _fromString(attributeValue); + m_x = value; + app.DebugPrintf("ConsoleGenerateStructure: Adding parameter x=%d\n", + m_x); + } else if (attributeName.compare(L"y") == 0) { + int value = _fromString(attributeValue); + m_y = value; + app.DebugPrintf("ConsoleGenerateStructure: Adding parameter y=%d\n", + m_y); + } else if (attributeName.compare(L"z") == 0) { + int value = _fromString(attributeValue); + m_z = value; + app.DebugPrintf("ConsoleGenerateStructure: Adding parameter z=%d\n", + m_z); + } else if (attributeName.compare(L"orientation") == 0) { + int value = _fromString(attributeValue); + orientation = value; + app.DebugPrintf( + "ConsoleGenerateStructure: Adding parameter orientation=%d\n", + orientation); + } else if (attributeName.compare(L"dim") == 0) { + m_dimension = _fromString(attributeValue); + if (m_dimension > 1 || m_dimension < -1) m_dimension = 0; + app.DebugPrintf( + "ApplySchematicRuleDefinition: Adding parameter dimension=%d\n", + m_dimension); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -BoundingBox* ConsoleGenerateStructure::getBoundingBox() -{ - if(boundingBox == NULL) - { - // Find the max bounds - int maxX, maxY, maxZ; - maxX = maxY = maxZ = 1; - for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) - { - ConsoleGenerateStructureAction *action = *it; - maxX = std::max(maxX,action->getEndX()); - maxY = std::max(maxY,action->getEndY()); - maxZ = std::max(maxZ,action->getEndZ()); - } - - boundingBox = new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ); - } - return boundingBox; +BoundingBox* ConsoleGenerateStructure::getBoundingBox() { + if (boundingBox == NULL) { + // Find the max bounds + int maxX, maxY, maxZ; + maxX = maxY = maxZ = 1; + for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) { + ConsoleGenerateStructureAction* action = *it; + maxX = std::max(maxX, action->getEndX()); + maxY = std::max(maxY, action->getEndY()); + maxZ = std::max(maxZ, action->getEndZ()); + } + + boundingBox = + new BoundingBox(m_x, m_y, m_z, m_x + maxX, m_y + maxY, m_z + maxZ); + } + return boundingBox; } -bool ConsoleGenerateStructure::postProcess(Level *level, Random *random, BoundingBox *chunkBB) -{ - if(level->dimension->id != m_dimension) return false; +bool ConsoleGenerateStructure::postProcess(Level* level, Random* random, + BoundingBox* chunkBB) { + if (level->dimension->id != m_dimension) return false; - for(AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) - { - ConsoleGenerateStructureAction *action = *it; - - switch(action->getActionType()) - { - case ConsoleGameRules::eGameRuleType_GenerateBox: - { - XboxStructureActionGenerateBox *genBox = (XboxStructureActionGenerateBox *)action; - genBox->generateBoxInLevel(this,level,chunkBB); - } - break; - case ConsoleGameRules::eGameRuleType_PlaceBlock: - { - XboxStructureActionPlaceBlock *pPlaceBlock = (XboxStructureActionPlaceBlock *)action; - pPlaceBlock->placeBlockInLevel(this,level,chunkBB); - } - break; - case ConsoleGameRules::eGameRuleType_PlaceContainer: - { - XboxStructureActionPlaceContainer *pPlaceContainer = (XboxStructureActionPlaceContainer *)action; - pPlaceContainer->placeContainerInLevel(this,level,chunkBB); - } - break; - case ConsoleGameRules::eGameRuleType_PlaceSpawner: - { - XboxStructureActionPlaceSpawner *pPlaceSpawner = (XboxStructureActionPlaceSpawner *)action; - pPlaceSpawner->placeSpawnerInLevel(this,level,chunkBB); - } - break; - default: - break; - }; - } + for (AUTO_VAR(it, m_actions.begin()); it != m_actions.end(); ++it) { + ConsoleGenerateStructureAction* action = *it; - return false; + switch (action->getActionType()) { + case ConsoleGameRules::eGameRuleType_GenerateBox: { + XboxStructureActionGenerateBox* genBox = + (XboxStructureActionGenerateBox*)action; + genBox->generateBoxInLevel(this, level, chunkBB); + } break; + case ConsoleGameRules::eGameRuleType_PlaceBlock: { + XboxStructureActionPlaceBlock* pPlaceBlock = + (XboxStructureActionPlaceBlock*)action; + pPlaceBlock->placeBlockInLevel(this, level, chunkBB); + } break; + case ConsoleGameRules::eGameRuleType_PlaceContainer: { + XboxStructureActionPlaceContainer* pPlaceContainer = + (XboxStructureActionPlaceContainer*)action; + pPlaceContainer->placeContainerInLevel(this, level, chunkBB); + } break; + case ConsoleGameRules::eGameRuleType_PlaceSpawner: { + XboxStructureActionPlaceSpawner* pPlaceSpawner = + (XboxStructureActionPlaceSpawner*)action; + pPlaceSpawner->placeSpawnerInLevel(this, level, chunkBB); + } break; + default: + break; + }; + } + + return false; } -bool ConsoleGenerateStructure::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1) -{ - return getBoundingBox()->intersects(x0,y0,z0,x1,y1,z1); +bool ConsoleGenerateStructure::checkIntersects(int x0, int y0, int z0, int x1, + int y1, int z1) { + return getBoundingBox()->intersects(x0, y0, z0, x1, y1, z1); } -int ConsoleGenerateStructure::getMinY() -{ - return getBoundingBox()->y0; -} +int ConsoleGenerateStructure::getMinY() { return getBoundingBox()->y0; } diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.h b/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.h index e9aaaface..d65be8049 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.h +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructure.h @@ -9,30 +9,37 @@ class ConsoleGenerateStructureAction; class XboxStructureActionPlaceContainer; class GRFObject; -class ConsoleGenerateStructure : public GameRuleDefinition, public StructurePiece -{ +class ConsoleGenerateStructure : public GameRuleDefinition, + public StructurePiece { private: - int m_x, m_y, m_z; - std::vector m_actions; - int m_dimension; -public: - ConsoleGenerateStructure(); + int m_x, m_y, m_z; + std::vector m_actions; + int m_dimension; - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_GenerateStructure; } +public: + ConsoleGenerateStructure(); - virtual void getChildren(std::vector *children); - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); - - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_GenerateStructure; + } - // StructurePiece - virtual BoundingBox *getBoundingBox(); - virtual bool postProcess(Level *level, Random *random, BoundingBox *chunkBB); + virtual void getChildren(std::vector* children); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); - void createContainer(XboxStructureActionPlaceContainer *action, Level *level, BoundingBox *chunkBB); + virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); + // StructurePiece + virtual BoundingBox* getBoundingBox(); + virtual bool postProcess(Level* level, Random* random, + BoundingBox* chunkBB); - virtual int getMinY(); + void createContainer(XboxStructureActionPlaceContainer* action, + Level* level, BoundingBox* chunkBB); + + bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); + + virtual int getMinY(); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructureAction.h b/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructureAction.h index 14eb2fd86..937b70c34 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructureAction.h +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleGenerateStructureAction.h @@ -2,10 +2,9 @@ #include "GameRuleDefinition.h" -class ConsoleGenerateStructureAction : public GameRuleDefinition -{ +class ConsoleGenerateStructureAction : public GameRuleDefinition { public: - virtual int getEndX() = 0; - virtual int getEndY() = 0; - virtual int getEndZ() = 0; + virtual int getEndX() = 0; + virtual int getEndY() = 0; + virtual int getEndZ() = 0; }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp index 1253db9e8..e4ec51441 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.cpp @@ -12,1018 +12,1068 @@ #include "../../Minecraft.World/Headers/net.minecraft.world.phys.h" #include "../../Minecraft.World/IO/Streams/Compression.h" -ConsoleSchematicFile::ConsoleSchematicFile() -{ - m_xSize = m_ySize = m_zSize = 0; - m_refCount = 1; - m_data.data = NULL; +ConsoleSchematicFile::ConsoleSchematicFile() { + m_xSize = m_ySize = m_zSize = 0; + m_refCount = 1; + m_data.data = NULL; } -ConsoleSchematicFile::~ConsoleSchematicFile() -{ - app.DebugPrintf("Deleting schematic file\n"); - if(m_data.data != NULL) delete [] m_data.data; +ConsoleSchematicFile::~ConsoleSchematicFile() { + app.DebugPrintf("Deleting schematic file\n"); + if (m_data.data != NULL) delete[] m_data.data; } -void ConsoleSchematicFile::save(DataOutputStream *dos) -{ - if(dos != NULL) - { - dos->writeInt(XBOX_SCHEMATIC_CURRENT_VERSION); +void ConsoleSchematicFile::save(DataOutputStream* dos) { + if (dos != NULL) { + dos->writeInt(XBOX_SCHEMATIC_CURRENT_VERSION); - dos->writeByte(APPROPRIATE_COMPRESSION_TYPE); + dos->writeByte(APPROPRIATE_COMPRESSION_TYPE); - dos->writeInt(m_xSize); - dos->writeInt(m_ySize); - dos->writeInt(m_zSize); + dos->writeInt(m_xSize); + dos->writeInt(m_ySize); + dos->writeInt(m_zSize); - byteArray ba(new std::uint8_t[ m_data.length ], m_data.length); - Compression::getCompression()->CompressLZXRLE( ba.data, &ba.length, - m_data.data, m_data.length); + byteArray ba(new std::uint8_t[m_data.length], m_data.length); + Compression::getCompression()->CompressLZXRLE( + ba.data, &ba.length, m_data.data, m_data.length); - dos->writeInt(ba.length); - dos->write(ba); + dos->writeInt(ba.length); + dos->write(ba); - save_tags(dos); + save_tags(dos); - delete [] ba.data; - } + delete[] ba.data; + } } -void ConsoleSchematicFile::load(DataInputStream *dis) -{ - if(dis != NULL) - { - // VERSION CHECK // - int version = dis->readInt(); +void ConsoleSchematicFile::load(DataInputStream* dis) { + if (dis != NULL) { + // VERSION CHECK // + int version = dis->readInt(); - Compression::ECompressionTypes compressionType = Compression::eCompressionType_LZXRLE; + Compression::ECompressionTypes compressionType = + Compression::eCompressionType_LZXRLE; - if (version > XBOX_SCHEMATIC_ORIGINAL_VERSION) // Or later versions - { - compressionType = (Compression::ECompressionTypes)dis->readByte(); - } + if (version > XBOX_SCHEMATIC_ORIGINAL_VERSION) // Or later versions + { + compressionType = (Compression::ECompressionTypes)dis->readByte(); + } - if (version > XBOX_SCHEMATIC_CURRENT_VERSION) - assert(false && "Unrecognised schematic version!!"); + if (version > XBOX_SCHEMATIC_CURRENT_VERSION) + assert(false && "Unrecognised schematic version!!"); - m_xSize = dis->readInt(); - m_ySize = dis->readInt(); - m_zSize = dis->readInt(); + m_xSize = dis->readInt(); + m_ySize = dis->readInt(); + m_zSize = dis->readInt(); - int compressedSize = dis->readInt(); - byteArray compressedBuffer(compressedSize); - dis->readFully(compressedBuffer); + int compressedSize = dis->readInt(); + byteArray compressedBuffer(compressedSize); + dis->readFully(compressedBuffer); - if(m_data.data != NULL) - { - delete [] m_data.data; - m_data.data = NULL; - } + if (m_data.data != NULL) { + delete[] m_data.data; + m_data.data = NULL; + } - if(compressionType == Compression::eCompressionType_None) - { - m_data = compressedBuffer; - } - else - { - unsigned int outputSize = m_xSize * m_ySize * m_zSize * 3/2; - m_data = byteArray(outputSize); + if (compressionType == Compression::eCompressionType_None) { + m_data = compressedBuffer; + } else { + unsigned int outputSize = m_xSize * m_ySize * m_zSize * 3 / 2; + m_data = byteArray(outputSize); - switch(compressionType) - { - case Compression::eCompressionType_RLE: - Compression::getCompression()->DecompressRLE( m_data.data, &m_data.length, compressedBuffer.data, compressedSize); - break; - case APPROPRIATE_COMPRESSION_TYPE: - Compression::getCompression()->DecompressLZXRLE( m_data.data, &m_data.length, compressedBuffer.data, compressedSize); - break; - default: - app.DebugPrintf("Unrecognized compression type for Schematic file (%d)\n", (int)compressionType); - Compression::getCompression()->SetDecompressionType( (Compression::ECompressionTypes)compressionType ); - Compression::getCompression()->DecompressLZXRLE( m_data.data, &m_data.length, compressedBuffer.data, compressedSize); - Compression::getCompression()->SetDecompressionType( APPROPRIATE_COMPRESSION_TYPE ); - }; + switch (compressionType) { + case Compression::eCompressionType_RLE: + Compression::getCompression()->DecompressRLE( + m_data.data, &m_data.length, compressedBuffer.data, + compressedSize); + break; + case APPROPRIATE_COMPRESSION_TYPE: + Compression::getCompression()->DecompressLZXRLE( + m_data.data, &m_data.length, compressedBuffer.data, + compressedSize); + break; + default: + app.DebugPrintf( + "Unrecognized compression type for Schematic file " + "(%d)\n", + (int)compressionType); + Compression::getCompression()->SetDecompressionType( + (Compression::ECompressionTypes)compressionType); + Compression::getCompression()->DecompressLZXRLE( + m_data.data, &m_data.length, compressedBuffer.data, + compressedSize); + Compression::getCompression()->SetDecompressionType( + APPROPRIATE_COMPRESSION_TYPE); + }; - delete [] compressedBuffer.data; - } + delete[] compressedBuffer.data; + } - // READ TAGS // - // 4jcraft, fixed cast of templated List to get the tag list - // and cast it to CompoundTag inside the loop - CompoundTag *tag = NbtIo::read(dis); - ListTag *tileEntityTags = tag->getList(L"TileEntities"); - if (tileEntityTags != NULL) - { - for (int i = 0; i < tileEntityTags->size(); i++) - { - CompoundTag *teTag = (CompoundTag*) tileEntityTags->get(i); - std::shared_ptr te = TileEntity::loadStatic(teTag); + // READ TAGS // + // 4jcraft, fixed cast of templated List to get the tag list + // and cast it to CompoundTag inside the loop + CompoundTag* tag = NbtIo::read(dis); + ListTag* tileEntityTags = tag->getList(L"TileEntities"); + if (tileEntityTags != NULL) { + for (int i = 0; i < tileEntityTags->size(); i++) { + CompoundTag* teTag = (CompoundTag*)tileEntityTags->get(i); + std::shared_ptr te = TileEntity::loadStatic(teTag); - if(te == NULL) - { + if (te == NULL) { #ifndef _CONTENT_PACKAGE - app.DebugPrintf("ConsoleSchematicFile has read a NULL tile entity\n"); - __debugbreak(); + app.DebugPrintf( + "ConsoleSchematicFile has read a NULL tile entity\n"); + __debugbreak(); #endif - } - else - { - m_tileEntities.push_back(te); - } - } - } + } else { + m_tileEntities.push_back(te); + } + } + } - // 4jcraft, fixed cast of templated List to get the tag list - // and cast it to CompoundTag inside the loop - ListTag *entityTags = tag->getList(L"Entities"); - if (entityTags != NULL) - { - for (int i = 0; i < entityTags->size(); i++) - { - CompoundTag *eTag = (CompoundTag*) entityTags->get(i); - eINSTANCEOF type = EntityIO::getType(eTag->getString(L"id")); + // 4jcraft, fixed cast of templated List to get the tag list + // and cast it to CompoundTag inside the loop + ListTag* entityTags = tag->getList(L"Entities"); + if (entityTags != NULL) { + for (int i = 0; i < entityTags->size(); i++) { + CompoundTag* eTag = (CompoundTag*)entityTags->get(i); + eINSTANCEOF type = EntityIO::getType(eTag->getString(L"id")); - // 4jcraft, same here - ListTag *pos = eTag->getList(L"Pos"); + // 4jcraft, same here + ListTag* pos = eTag->getList(L"Pos"); - double x = ((DoubleTag*) pos->get(0))->data; - double y = ((DoubleTag*) pos->get(1))->data; - double z = ((DoubleTag*) pos->get(2))->data; + double x = ((DoubleTag*)pos->get(0))->data; + double y = ((DoubleTag*)pos->get(1))->data; + double z = ((DoubleTag*)pos->get(2))->data; - if( type == eTYPE_PAINTING || type == eTYPE_ITEM_FRAME ) - { - x = ((IntTag *) eTag->get(L"TileX") )->data; - y = ((IntTag *) eTag->get(L"TileY") )->data; - z = ((IntTag *) eTag->get(L"TileZ") )->data; - } + if (type == eTYPE_PAINTING || type == eTYPE_ITEM_FRAME) { + x = ((IntTag*)eTag->get(L"TileX"))->data; + y = ((IntTag*)eTag->get(L"TileY"))->data; + z = ((IntTag*)eTag->get(L"TileZ"))->data; + } #ifdef _DEBUG - //app.DebugPrintf(1,"Loaded entity type %d at (%f,%f,%f)\n",(int)type,x,y,z); + // app.DebugPrintf(1,"Loaded entity type %d at + // (%f,%f,%f)\n",(int)type,x,y,z); #endif - m_entities.push_back( std::pair(Vec3::newPermanent(x,y,z),(CompoundTag *)eTag->copy())); - } - } - delete tag; - } + m_entities.push_back(std::pair( + Vec3::newPermanent(x, y, z), (CompoundTag*)eTag->copy())); + } + } + delete tag; + } } -void ConsoleSchematicFile::save_tags(DataOutputStream *dos) -{ - CompoundTag *tag = new CompoundTag(); +void ConsoleSchematicFile::save_tags(DataOutputStream* dos) { + CompoundTag* tag = new CompoundTag(); - ListTag *tileEntityTags = new ListTag(); - tag->put(L"TileEntities", tileEntityTags); + ListTag* tileEntityTags = new ListTag(); + tag->put(L"TileEntities", tileEntityTags); - for (AUTO_VAR(it, m_tileEntities.begin()); it != m_tileEntities.end(); it++) - { - CompoundTag *cTag = new CompoundTag(); - (*it)->save(cTag); - tileEntityTags->add(cTag); - } + for (AUTO_VAR(it, m_tileEntities.begin()); it != m_tileEntities.end(); + it++) { + CompoundTag* cTag = new CompoundTag(); + (*it)->save(cTag); + tileEntityTags->add(cTag); + } - ListTag *entityTags = new ListTag(); - tag->put(L"Entities", entityTags); + ListTag* entityTags = new ListTag(); + tag->put(L"Entities", entityTags); - for (AUTO_VAR(it, m_entities.begin()); it != m_entities.end(); it++) - entityTags->add( (CompoundTag *)(*it).second->copy() ); + for (AUTO_VAR(it, m_entities.begin()); it != m_entities.end(); it++) + entityTags->add((CompoundTag*)(*it).second->copy()); - NbtIo::write(tag,dos); - delete tag; + NbtIo::write(tag, dos); + delete tag; } -__int64 ConsoleSchematicFile::applyBlocksAndData(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot) -{ - int xStart = std::max(destinationBox->x0, (double)chunk->x*16); - // 4jcraft changed from (xStart>>4)<<4 to (xStart & ~15) - int xEnd = std::min(destinationBox->x1, (double)((xStart & ~15) + 16)); +__int64 ConsoleSchematicFile::applyBlocksAndData(LevelChunk* chunk, + AABB* chunkBox, + AABB* destinationBox, + ESchematicRotation rot) { + int xStart = std::max(destinationBox->x0, (double)chunk->x * 16); + // 4jcraft changed from (xStart>>4)<<4 to (xStart & ~15) + int xEnd = std::min(destinationBox->x1, (double)((xStart & ~15) + 16)); - int yStart = destinationBox->y0; - int yEnd = destinationBox->y1; - if(yEnd > Level::maxBuildHeight) yEnd = Level::maxBuildHeight; + int yStart = destinationBox->y0; + int yEnd = destinationBox->y1; + if (yEnd > Level::maxBuildHeight) yEnd = Level::maxBuildHeight; - int zStart = std::max(destinationBox->z0, (double)chunk->z*16); - int zEnd = std::min(destinationBox->z1, (double)(zStart & ~15) + 16); + int zStart = std::max(destinationBox->z0, (double)chunk->z * 16); + int zEnd = std::min(destinationBox->z1, (double)(zStart & ~15) + 16); #ifdef _DEBUG - app.DebugPrintf("Range is (%d,%d,%d) to (%d,%d,%d)\n",xStart,yStart,zStart,xEnd-1,yEnd-1,zEnd-1); + app.DebugPrintf("Range is (%d,%d,%d) to (%d,%d,%d)\n", xStart, yStart, + zStart, xEnd - 1, yEnd - 1, zEnd - 1); #endif - int rowBlocksIncluded = (yEnd-yStart)*(zEnd-zStart); - int blocksIncluded = (xEnd-xStart)*rowBlocksIncluded; + int rowBlocksIncluded = (yEnd - yStart) * (zEnd - zStart); + int blocksIncluded = (xEnd - xStart) * rowBlocksIncluded; - int rowBlockCount = getYSize() * getZSize(); - int totalBlockCount = getXSize() * rowBlockCount; + int rowBlockCount = getYSize() * getZSize(); + int totalBlockCount = getXSize() * rowBlockCount; - byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); - PIXBeginNamedEvent(0,"Getting block data"); - chunk->getBlockData(blockData); - PIXEndNamedEvent(); - byteArray dataData = byteArray(Level::HALF_CHUNK_TILE_COUNT); - PIXBeginNamedEvent(0,"Getting Data data"); - chunk->getDataData(dataData); - PIXEndNamedEvent(); + byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); + PIXBeginNamedEvent(0, "Getting block data"); + chunk->getBlockData(blockData); + PIXEndNamedEvent(); + byteArray dataData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + PIXBeginNamedEvent(0, "Getting Data data"); + chunk->getDataData(dataData); + PIXEndNamedEvent(); - // Ignore light data - int blockLightP = -1; - int skyLightP = -1; - if( rot == eSchematicRot_90 || rot == eSchematicRot_180 || rot == eSchematicRot_270 ) - { - int schematicXRow = 0; - int schematicZRow = 0; - int blocksP = 0; - int dataP = 0; + // Ignore light data + int blockLightP = -1; + int skyLightP = -1; + if (rot == eSchematicRot_90 || rot == eSchematicRot_180 || + rot == eSchematicRot_270) { + int schematicXRow = 0; + int schematicZRow = 0; + int blocksP = 0; + int dataP = 0; - for(int x = xStart; x < xEnd; ++x) - { - int x0 = x - chunk->x*16; - int x1 = x0 + 1; + for (int x = xStart; x < xEnd; ++x) { + int x0 = x - chunk->x * 16; + int x1 = x0 + 1; - for(int z = zStart; z < zEnd; ++z) - { - int z0 = z - chunk->z*16; - int z1 = z0 + 1; + for (int z = zStart; z < zEnd; ++z) { + int z0 = z - chunk->z * 16; + int z1 = z0 + 1; - chunkCoordToSchematicCoord(destinationBox, x, z, rot, schematicXRow, schematicZRow); - blocksP = (schematicXRow*rowBlockCount) + (schematicZRow*getYSize()); - dataP = totalBlockCount + (blocksP)/2; + chunkCoordToSchematicCoord(destinationBox, x, z, rot, + schematicXRow, schematicZRow); + blocksP = (schematicXRow * rowBlockCount) + + (schematicZRow * getYSize()); + dataP = totalBlockCount + (blocksP) / 2; - ConsoleSchematicFile::setBlocksAndData(chunk,blockData,dataData,m_data, x0, yStart, z0, x1, yEnd, z1, blocksP, dataP, blockLightP, skyLightP); - } - } - } - else if( rot == eSchematicRot_0 ) - { - // The initial pointer offsets for the different data types - int schematicXRow = xStart - destinationBox->x0; - int schematicZRow = zStart - destinationBox->z0; - int blocksP = (schematicXRow*rowBlockCount) + (schematicZRow*getYSize()); - int dataP = totalBlockCount + (schematicXRow*rowBlockCount + (schematicZRow*getYSize()))/2; + ConsoleSchematicFile::setBlocksAndData( + chunk, blockData, dataData, m_data, x0, yStart, z0, x1, + yEnd, z1, blocksP, dataP, blockLightP, skyLightP); + } + } + } else if (rot == eSchematicRot_0) { + // The initial pointer offsets for the different data types + int schematicXRow = xStart - destinationBox->x0; + int schematicZRow = zStart - destinationBox->z0; + int blocksP = + (schematicXRow * rowBlockCount) + (schematicZRow * getYSize()); + int dataP = + totalBlockCount + + (schematicXRow * rowBlockCount + (schematicZRow * getYSize())) / 2; - for(int x = xStart; x < xEnd; ++x) - { - int x0 = x - chunk->x*16; - int x1 = x0 + 1; + for (int x = xStart; x < xEnd; ++x) { + int x0 = x - chunk->x * 16; + int x1 = x0 + 1; - int z0 = zStart - chunk->z*16; - int z1 = zEnd - chunk->z*16; + int z0 = zStart - chunk->z * 16; + int z1 = zEnd - chunk->z * 16; - ConsoleSchematicFile::setBlocksAndData(chunk,blockData,dataData,m_data, x0, yStart, z0, x1, yEnd, z1, blocksP, dataP, blockLightP, skyLightP); - // update all pointer positions - // For z start to z end - // Set blocks and data - // increment z by the right amount - blocksP += (rowBlockCount-rowBlocksIncluded); - dataP += (rowBlockCount-rowBlocksIncluded)/2; - } - } - else - { - app.DebugPrintf("ERROR: Rotation of block and data not implemented!!\n"); - } + ConsoleSchematicFile::setBlocksAndData( + chunk, blockData, dataData, m_data, x0, yStart, z0, x1, yEnd, + z1, blocksP, dataP, blockLightP, skyLightP); + // update all pointer positions + // For z start to z end + // Set blocks and data + // increment z by the right amount + blocksP += (rowBlockCount - rowBlocksIncluded); + dataP += (rowBlockCount - rowBlocksIncluded) / 2; + } + } else { + app.DebugPrintf( + "ERROR: Rotation of block and data not implemented!!\n"); + } - // 4J Stu - Hack for ME pack to replace sand with end stone in schematics - //for(int i = 0; i < blockData.length; ++i) - //{ - // if(blockData[i] == Tile::sand_Id || blockData[i] == Tile::sandStone_Id) - // { - // blockData[i] = Tile::whiteStone_Id; - // } - //} - - PIXBeginNamedEvent(0,"Setting Block data"); - chunk->setBlockData(blockData); - PIXEndNamedEvent(); - delete[] blockData.data; //4jcraft changed to array delete - chunk->recalcHeightmapOnly(); - PIXBeginNamedEvent(0,"Setting Data data"); - chunk->setDataData(dataData); - PIXEndNamedEvent(); - delete[] dataData.data; //4jcraft, same here + // 4J Stu - Hack for ME pack to replace sand with end stone in schematics + // for(int i = 0; i < blockData.length; ++i) + //{ + // if(blockData[i] == Tile::sand_Id || blockData[i] == Tile::sandStone_Id) + // { + // blockData[i] = Tile::whiteStone_Id; + // } + //} - // A basic pass through to roughly do the lighting. At this point of post-processing, we don't have all the neighbouring chunks loaded in, - // so any lighting here should be things that won't propagate out of this chunk. - for( int xx = xStart ; xx < xEnd; xx++ ) - for( int y = yStart ; y < yEnd; y++ ) - for( int zz = zStart ; zz < zEnd; zz++ ) - { - int x = xx - chunk->x * 16; - int z = zz - chunk->z * 16; - chunk->setBrightness(LightLayer::Block,x,y,z,0); - if( chunk->getTile(x,y,z) ) - { - chunk->setBrightness(LightLayer::Sky,x,y,z,0); - } - else - { - if( chunk->isSkyLit(x,y,z) ) - { - chunk->setBrightness(LightLayer::Sky,x,y,z,15); - } - else - { - chunk->setBrightness(LightLayer::Sky,x,y,z,0); - } - } - } + PIXBeginNamedEvent(0, "Setting Block data"); + chunk->setBlockData(blockData); + PIXEndNamedEvent(); + delete[] blockData.data; // 4jcraft changed to array delete + chunk->recalcHeightmapOnly(); + PIXBeginNamedEvent(0, "Setting Data data"); + chunk->setDataData(dataData); + PIXEndNamedEvent(); + delete[] dataData.data; // 4jcraft, same here - return blocksIncluded; + // A basic pass through to roughly do the lighting. At this point of + // post-processing, we don't have all the neighbouring chunks loaded in, so + // any lighting here should be things that won't propagate out of this + // chunk. + for (int xx = xStart; xx < xEnd; xx++) + for (int y = yStart; y < yEnd; y++) + for (int zz = zStart; zz < zEnd; zz++) { + int x = xx - chunk->x * 16; + int z = zz - chunk->z * 16; + chunk->setBrightness(LightLayer::Block, x, y, z, 0); + if (chunk->getTile(x, y, z)) { + chunk->setBrightness(LightLayer::Sky, x, y, z, 0); + } else { + if (chunk->isSkyLit(x, y, z)) { + chunk->setBrightness(LightLayer::Sky, x, y, z, 15); + } else { + chunk->setBrightness(LightLayer::Sky, x, y, z, 0); + } + } + } + + return blocksIncluded; } -// At the point that this is called, we have all the neighbouring chunks loaded in (and generally post-processed, apart from this lighting pass), so -// we can do the sort of lighting that might propagate out of the chunk. -__int64 ConsoleSchematicFile::applyLighting(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot) -{ - int xStart = std::max(destinationBox->x0, (double)chunk->x*16); - // 4jcraft changed >>4<<4 to & ~15 - int xEnd = std::min(destinationBox->x1, (double)(xStart & ~15) + 16); +// At the point that this is called, we have all the neighbouring chunks loaded +// in (and generally post-processed, apart from this lighting pass), so we can +// do the sort of lighting that might propagate out of the chunk. +__int64 ConsoleSchematicFile::applyLighting(LevelChunk* chunk, AABB* chunkBox, + AABB* destinationBox, + ESchematicRotation rot) { + int xStart = std::max(destinationBox->x0, (double)chunk->x * 16); + // 4jcraft changed >>4<<4 to & ~15 + int xEnd = std::min(destinationBox->x1, (double)(xStart & ~15) + 16); - int yStart = destinationBox->y0; - int yEnd = destinationBox->y1; - if(yEnd > Level::maxBuildHeight) yEnd = Level::maxBuildHeight; + int yStart = destinationBox->y0; + int yEnd = destinationBox->y1; + if (yEnd > Level::maxBuildHeight) yEnd = Level::maxBuildHeight; - int zStart = std::max(destinationBox->z0, (double)chunk->z*16); - int zEnd = std::min(destinationBox->z1, (double)(zStart & ~15) + 16); + int zStart = std::max(destinationBox->z0, (double)chunk->z * 16); + int zEnd = std::min(destinationBox->z1, (double)(zStart & ~15) + 16); - int rowBlocksIncluded = (yEnd-yStart)*(zEnd-zStart); - int blocksIncluded = (xEnd-xStart)*rowBlocksIncluded; + int rowBlocksIncluded = (yEnd - yStart) * (zEnd - zStart); + int blocksIncluded = (xEnd - xStart) * rowBlocksIncluded; - // Now actually do a checkLight on blocks that might need it, which should more accurately put everything in place - for( int xx = xStart ; xx < xEnd; xx++ ) - for( int y = yStart ; y < yEnd; y++ ) - for( int zz = zStart ; zz < zEnd; zz++ ) - { - int x = xx - chunk->x * 16; - int z = zz - chunk->z * 16; + // Now actually do a checkLight on blocks that might need it, which should + // more accurately put everything in place + for (int xx = xStart; xx < xEnd; xx++) + for (int y = yStart; y < yEnd; y++) + for (int zz = zStart; zz < zEnd; zz++) { + int x = xx - chunk->x * 16; + int z = zz - chunk->z * 16; - if( y <= chunk->getHeightmap( x, z ) ) - { - chunk->level->checkLight(LightLayer::Sky, xx, y, zz, true); - } - if( Tile::lightEmission[chunk->getTile(x,y,z)] ) - { - // Note that this lighting passes a rootOnlyEmissive flag of true, which means that only the location xx/y/zz is considered - // as possibly being a source of emissive light, not other tiles that we might encounter whilst propagating the light from - // the start location. If we don't do this, and Do encounter another emissive source in the radius of influence that the first - // light source had, then we'll start also lighting from that tile but won't actually be able to progatate that second light - // fully since checkLight only has a finite radius of 17 from the start position that it can light. Then when we do a checkLight - // on the second light later, it won't bother doing anything because the light level at the location of the tile itself will be correct. - chunk->level->checkLight(LightLayer::Block, xx, y, zz, true, true); - } - } + if (y <= chunk->getHeightmap(x, z)) { + chunk->level->checkLight(LightLayer::Sky, xx, y, zz, true); + } + if (Tile::lightEmission[chunk->getTile(x, y, z)]) { + // Note that this lighting passes a rootOnlyEmissive flag of + // true, which means that only the location xx/y/zz is + // considered as possibly being a source of emissive light, + // not other tiles that we might encounter whilst + // propagating the light from the start location. If we + // don't do this, and Do encounter another emissive source + // in the radius of influence that the first light source + // had, then we'll start also lighting from that tile but + // won't actually be able to progatate that second light + // fully since checkLight only has a finite radius of 17 + // from the start position that it can light. Then when we + // do a checkLight on the second light later, it won't + // bother doing anything because the light level at the + // location of the tile itself will be correct. + chunk->level->checkLight(LightLayer::Block, xx, y, zz, true, + true); + } + } - return blocksIncluded; + return blocksIncluded; } -void ConsoleSchematicFile::chunkCoordToSchematicCoord(AABB *destinationBox, int chunkX, int chunkZ, ESchematicRotation rot, int &schematicX, int &schematicZ) -{ - switch(rot) - { - case eSchematicRot_90: - // schematicX decreases as chunkZ increases - // schematicZ increases as chunkX increases - schematicX = chunkZ - destinationBox->z0; - schematicZ = (destinationBox->x1 - 1 - destinationBox->x0) - (chunkX - destinationBox->x0); - break; - case eSchematicRot_180: - // schematicX decreases as chunkX increases - // schematicZ decreases as chunkZ increases - schematicX = (destinationBox->x1 - 1 - destinationBox->x0) - (chunkX - destinationBox->x0); - schematicZ = (destinationBox->z1 - 1 - destinationBox->z0) - (chunkZ - destinationBox->z0); - break; - case eSchematicRot_270: - // schematicX increases as chunkZ increases - // shcematicZ decreases as chunkX increases - schematicX = (destinationBox->z1 - 1 - destinationBox->z0) - (chunkZ - destinationBox->z0); - schematicZ = chunkX - destinationBox->x0; - break; - case eSchematicRot_0: - default: - // schematicX increases as chunkX increases - // schematicZ increases as chunkZ increases - schematicX = chunkX - destinationBox->x0; - schematicZ = chunkZ - destinationBox->z0; - break; - }; +void ConsoleSchematicFile::chunkCoordToSchematicCoord(AABB* destinationBox, + int chunkX, int chunkZ, + ESchematicRotation rot, + int& schematicX, + int& schematicZ) { + switch (rot) { + case eSchematicRot_90: + // schematicX decreases as chunkZ increases + // schematicZ increases as chunkX increases + schematicX = chunkZ - destinationBox->z0; + schematicZ = (destinationBox->x1 - 1 - destinationBox->x0) - + (chunkX - destinationBox->x0); + break; + case eSchematicRot_180: + // schematicX decreases as chunkX increases + // schematicZ decreases as chunkZ increases + schematicX = (destinationBox->x1 - 1 - destinationBox->x0) - + (chunkX - destinationBox->x0); + schematicZ = (destinationBox->z1 - 1 - destinationBox->z0) - + (chunkZ - destinationBox->z0); + break; + case eSchematicRot_270: + // schematicX increases as chunkZ increases + // shcematicZ decreases as chunkX increases + schematicX = (destinationBox->z1 - 1 - destinationBox->z0) - + (chunkZ - destinationBox->z0); + schematicZ = chunkX - destinationBox->x0; + break; + case eSchematicRot_0: + default: + // schematicX increases as chunkX increases + // schematicZ increases as chunkZ increases + schematicX = chunkX - destinationBox->x0; + schematicZ = chunkZ - destinationBox->z0; + break; + }; } -void ConsoleSchematicFile::schematicCoordToChunkCoord(AABB *destinationBox, double schematicX, double schematicZ, ESchematicRotation rot, double &chunkX, double &chunkZ) -{ - switch(rot) - { - case eSchematicRot_90: - // schematicX decreases as chunkZ increases - // schematicZ increases as chunkX increases - chunkX = (destinationBox->x1 - 1 - schematicZ); - chunkZ = schematicX + destinationBox->z0; - break; - case eSchematicRot_180: - // schematicX decreases as chunkX increases - // schematicZ decreases as chunkZ increases - chunkX = (destinationBox->x1 - 1 - schematicX); - chunkZ = (destinationBox->z1 - 1 - schematicZ); - break; - case eSchematicRot_270: - // schematicX increases as chunkZ increases - // shcematicZ decreases as chunkX increases - chunkX = schematicZ + destinationBox->x0; - chunkZ = (destinationBox->z1 - 1 - schematicX); - break; - case eSchematicRot_0: - default: - // schematicX increases as chunkX increases - // schematicZ increases as chunkZ increases - chunkX = schematicX + destinationBox->x0; - chunkZ = schematicZ + destinationBox->z0; - break; - }; +void ConsoleSchematicFile::schematicCoordToChunkCoord( + AABB* destinationBox, double schematicX, double schematicZ, + ESchematicRotation rot, double& chunkX, double& chunkZ) { + switch (rot) { + case eSchematicRot_90: + // schematicX decreases as chunkZ increases + // schematicZ increases as chunkX increases + chunkX = (destinationBox->x1 - 1 - schematicZ); + chunkZ = schematicX + destinationBox->z0; + break; + case eSchematicRot_180: + // schematicX decreases as chunkX increases + // schematicZ decreases as chunkZ increases + chunkX = (destinationBox->x1 - 1 - schematicX); + chunkZ = (destinationBox->z1 - 1 - schematicZ); + break; + case eSchematicRot_270: + // schematicX increases as chunkZ increases + // shcematicZ decreases as chunkX increases + chunkX = schematicZ + destinationBox->x0; + chunkZ = (destinationBox->z1 - 1 - schematicX); + break; + case eSchematicRot_0: + default: + // schematicX increases as chunkX increases + // schematicZ increases as chunkZ increases + chunkX = schematicX + destinationBox->x0; + chunkZ = schematicZ + destinationBox->z0; + break; + }; } -void ConsoleSchematicFile::applyTileEntities(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot) -{ - for(AUTO_VAR(it, m_tileEntities.begin()); it != m_tileEntities.end();++it) - { - std::shared_ptr te = *it; +void ConsoleSchematicFile::applyTileEntities(LevelChunk* chunk, AABB* chunkBox, + AABB* destinationBox, + ESchematicRotation rot) { + for (AUTO_VAR(it, m_tileEntities.begin()); it != m_tileEntities.end(); + ++it) { + std::shared_ptr te = *it; - double targetX = te->x; - double targetY = te->y + destinationBox->y0; - double targetZ = te->z; + double targetX = te->x; + double targetY = te->y + destinationBox->y0; + double targetZ = te->z; - schematicCoordToChunkCoord(destinationBox, te->x, te->z, rot, targetX, targetZ); + schematicCoordToChunkCoord(destinationBox, te->x, te->z, rot, targetX, + targetZ); - Vec3 *pos = Vec3::newTemp(targetX,targetY,targetZ); - if( chunkBox->containsIncludingLowerBound(pos) ) - { - std::shared_ptr teCopy = chunk->getTileEntity( (int)targetX & 15, (int)targetY & 15, (int)targetZ & 15 ); + Vec3* pos = Vec3::newTemp(targetX, targetY, targetZ); + if (chunkBox->containsIncludingLowerBound(pos)) { + std::shared_ptr teCopy = chunk->getTileEntity( + (int)targetX & 15, (int)targetY & 15, (int)targetZ & 15); - if ( teCopy != NULL ) - { - CompoundTag *teData = new CompoundTag(); - te->save(teData); + if (teCopy != NULL) { + CompoundTag* teData = new CompoundTag(); + te->save(teData); - teCopy->load(teData); + teCopy->load(teData); - delete teData; + delete teData; - // Adjust the tileEntity position to world coords from schematic co-ords - teCopy->x = targetX; - teCopy->y = targetY; - teCopy->z = targetZ; + // Adjust the tileEntity position to world coords from schematic + // co-ords + teCopy->x = targetX; + teCopy->y = targetY; + teCopy->z = targetZ; - // Remove the current tile entity - //chunk->removeTileEntity( (int)targetX & 15, (int)targetY & 15, (int)targetZ & 15 ); - } - else - { - teCopy = te->clone(); + // Remove the current tile entity + // chunk->removeTileEntity( (int)targetX & 15, (int)targetY & + // 15, (int)targetZ & 15 ); + } else { + teCopy = te->clone(); - // Adjust the tileEntity position to world coords from schematic co-ords - teCopy->x = targetX; - teCopy->y = targetY; - teCopy->z = targetZ; - chunk->addTileEntity(teCopy); - } + // Adjust the tileEntity position to world coords from schematic + // co-ords + teCopy->x = targetX; + teCopy->y = targetY; + teCopy->z = targetZ; + chunk->addTileEntity(teCopy); + } - teCopy->setChanged(); - } - } - for(AUTO_VAR(it, m_entities.begin()); it != m_entities.end();) - { - Vec3 *source = it->first; - - double targetX = source->x; - double targetY = source->y + destinationBox->y0; - double targetZ = source->z; - schematicCoordToChunkCoord(destinationBox, source->x, source->z, rot, targetX, targetZ); + teCopy->setChanged(); + } + } + for (AUTO_VAR(it, m_entities.begin()); it != m_entities.end();) { + Vec3* source = it->first; - // Add 0.01 as the AABB::contains function returns false if a value is <= the lower bound - Vec3 *pos = Vec3::newTemp(targetX+0.01,targetY+0.01,targetZ+0.01); - if( !chunkBox->containsIncludingLowerBound(pos) ) - { - ++it; - continue; - } + double targetX = source->x; + double targetY = source->y + destinationBox->y0; + double targetZ = source->z; + schematicCoordToChunkCoord(destinationBox, source->x, source->z, rot, + targetX, targetZ); - CompoundTag *eTag = it->second; - std::shared_ptr e = EntityIO::loadStatic(eTag, NULL); + // Add 0.01 as the AABB::contains function returns false if a value is + // <= the lower bound + Vec3* pos = + Vec3::newTemp(targetX + 0.01, targetY + 0.01, targetZ + 0.01); + if (!chunkBox->containsIncludingLowerBound(pos)) { + ++it; + continue; + } - if( e->GetType() == eTYPE_PAINTING ) - { - std::shared_ptr painting = std::dynamic_pointer_cast(e); - - double tileX = painting->xTile; - double tileZ = painting->zTile; - schematicCoordToChunkCoord(destinationBox, painting->xTile, painting->zTile, rot, tileX, tileZ); + CompoundTag* eTag = it->second; + std::shared_ptr e = EntityIO::loadStatic(eTag, NULL); - painting->yTile += destinationBox->y0; - painting->xTile = tileX; - painting->zTile = tileZ; - painting->setDir(painting->dir); - } - else if( e->GetType() == eTYPE_ITEM_FRAME ) - { - std::shared_ptr frame = std::dynamic_pointer_cast(e); - - double tileX = frame->xTile; - double tileZ = frame->zTile; - schematicCoordToChunkCoord(destinationBox, frame->xTile, frame->zTile, rot, tileX, tileZ); + if (e->GetType() == eTYPE_PAINTING) { + std::shared_ptr painting = + std::dynamic_pointer_cast(e); - frame->yTile += destinationBox->y0; - frame->xTile = tileX; - frame->zTile = tileZ; - frame->setDir(frame->dir); - } - else - { - e->absMoveTo(targetX, targetY, targetZ,e->yRot,e->xRot); - } + double tileX = painting->xTile; + double tileZ = painting->zTile; + schematicCoordToChunkCoord(destinationBox, painting->xTile, + painting->zTile, rot, tileX, tileZ); + + painting->yTile += destinationBox->y0; + painting->xTile = tileX; + painting->zTile = tileZ; + painting->setDir(painting->dir); + } else if (e->GetType() == eTYPE_ITEM_FRAME) { + std::shared_ptr frame = + std::dynamic_pointer_cast(e); + + double tileX = frame->xTile; + double tileZ = frame->zTile; + schematicCoordToChunkCoord(destinationBox, frame->xTile, + frame->zTile, rot, tileX, tileZ); + + frame->yTile += destinationBox->y0; + frame->xTile = tileX; + frame->zTile = tileZ; + frame->setDir(frame->dir); + } else { + e->absMoveTo(targetX, targetY, targetZ, e->yRot, e->xRot); + } #ifdef _DEBUG - app.DebugPrintf("Adding entity type %d at (%f,%f,%f)\n",e->GetType(),e->x,e->y,e->z); + app.DebugPrintf("Adding entity type %d at (%f,%f,%f)\n", e->GetType(), + e->x, e->y, e->z); #endif - e->setLevel(chunk->level); - e->resetSmallId(); - e->setDespawnProtected(); // default to being protected against despawning - chunk->level->addEntity(e); + e->setLevel(chunk->level); + e->resetSmallId(); + e->setDespawnProtected(); // default to being protected against + // despawning + chunk->level->addEntity(e); - // 4J Stu - Until we can copy every type of entity, remove them from this vector - // This means that the entities will only exist in the first use of the schematic that is processed - //it = m_entities.erase(it); - ++it; - } + // 4J Stu - Until we can copy every type of entity, remove them from + // this vector This means that the entities will only exist in the first + // use of the schematic that is processed + // it = m_entities.erase(it); + ++it; + } } -void ConsoleSchematicFile::generateSchematicFile(DataOutputStream *dos, Level *level, int xStart, int yStart, int zStart, int xEnd, int yEnd, int zEnd, bool bSaveMobs, Compression::ECompressionTypes compressionType) -{ - assert(xEnd > xStart); - assert(yEnd > yStart); - assert(zEnd > zStart); - // 4J Stu - Enforce even numbered positions to start with to avoid problems with half-bytes in data +void ConsoleSchematicFile::generateSchematicFile( + DataOutputStream* dos, Level* level, int xStart, int yStart, int zStart, + int xEnd, int yEnd, int zEnd, bool bSaveMobs, + Compression::ECompressionTypes compressionType) { + assert(xEnd > xStart); + assert(yEnd > yStart); + assert(zEnd > zStart); + // 4J Stu - Enforce even numbered positions to start with to avoid problems + // with half-bytes in data - // We want the start to be even - if(xStart > 0 && xStart%2 != 0) - xStart-=1; - else if(xStart < 0 && xStart%2 !=0) - xStart-=1; - if(yStart < 0) yStart = 0; - else if(yStart > 0 && yStart%2 != 0) - yStart-=1; - if(zStart > 0 && zStart%2 != 0) - zStart-=1; - else if(zStart < 0 && zStart%2 !=0) - zStart-=1; - - // We want the end to be odd to have a total size that is even - if(xEnd > 0 && xEnd%2 == 0) - xEnd+=1; - else if(xEnd < 0 && xEnd%2 ==0) - xEnd+=1; - if(yEnd > Level::maxBuildHeight) - yEnd = Level::maxBuildHeight; - else if(yEnd > 0 && yEnd%2 == 0) - yEnd+=1; - else if(yEnd < 0 && yEnd%2 ==0) - yEnd+=1; - if(zEnd > 0 && zEnd%2 == 0) - zEnd+=1; - else if(zEnd < 0 && zEnd%2 ==0) - zEnd+=1; + // We want the start to be even + if (xStart > 0 && xStart % 2 != 0) + xStart -= 1; + else if (xStart < 0 && xStart % 2 != 0) + xStart -= 1; + if (yStart < 0) + yStart = 0; + else if (yStart > 0 && yStart % 2 != 0) + yStart -= 1; + if (zStart > 0 && zStart % 2 != 0) + zStart -= 1; + else if (zStart < 0 && zStart % 2 != 0) + zStart -= 1; - int xSize = xEnd - xStart + 1; - int ySize = yEnd - yStart + 1; - int zSize = zEnd - zStart + 1; + // We want the end to be odd to have a total size that is even + if (xEnd > 0 && xEnd % 2 == 0) + xEnd += 1; + else if (xEnd < 0 && xEnd % 2 == 0) + xEnd += 1; + if (yEnd > Level::maxBuildHeight) + yEnd = Level::maxBuildHeight; + else if (yEnd > 0 && yEnd % 2 == 0) + yEnd += 1; + else if (yEnd < 0 && yEnd % 2 == 0) + yEnd += 1; + if (zEnd > 0 && zEnd % 2 == 0) + zEnd += 1; + else if (zEnd < 0 && zEnd % 2 == 0) + zEnd += 1; - app.DebugPrintf("Generating schematic file for area (%d,%d,%d) to (%d,%d,%d), %dx%dx%d\n",xStart,yStart,zStart,xEnd,yEnd,zEnd,xSize,ySize,zSize); + int xSize = xEnd - xStart + 1; + int ySize = yEnd - yStart + 1; + int zSize = zEnd - zStart + 1; - if(dos != NULL) dos->writeInt(XBOX_SCHEMATIC_CURRENT_VERSION); + app.DebugPrintf( + "Generating schematic file for area (%d,%d,%d) to (%d,%d,%d), " + "%dx%dx%d\n", + xStart, yStart, zStart, xEnd, yEnd, zEnd, xSize, ySize, zSize); - if(dos != NULL) dos->writeByte(compressionType); + if (dos != NULL) dos->writeInt(XBOX_SCHEMATIC_CURRENT_VERSION); - //Write xSize - if(dos != NULL) dos->writeInt(xSize); + if (dos != NULL) dos->writeByte(compressionType); - //Write ySize - if(dos != NULL) dos->writeInt(ySize); + // Write xSize + if (dos != NULL) dos->writeInt(xSize); - //Write zSize - if(dos != NULL) dos->writeInt(zSize); + // Write ySize + if (dos != NULL) dos->writeInt(ySize); - //byteArray rawBuffer = level->getBlocksAndData(xStart, yStart, zStart, xSize, ySize, zSize, false); - int xRowSize = ySize * zSize; - int blockCount = xSize * xRowSize; - byteArray result( blockCount * 3 / 2 ); + // Write zSize + if (dos != NULL) dos->writeInt(zSize); - // Position pointers into the data when not ordered by chunk - int p = 0; - int dataP = blockCount; - int blockLightP = -1; - int skyLightP = -1; + // byteArray rawBuffer = level->getBlocksAndData(xStart, yStart, zStart, + // xSize, ySize, zSize, false); + int xRowSize = ySize * zSize; + int blockCount = xSize * xRowSize; + byteArray result(blockCount * 3 / 2); - int y0 = yStart; - int y1 = yStart + ySize; - if (y0 < 0) y0 = 0; - if (y1 > Level::maxBuildHeight) y1 = Level::maxBuildHeight; + // Position pointers into the data when not ordered by chunk + int p = 0; + int dataP = blockCount; + int blockLightP = -1; + int skyLightP = -1; - // Every x is a whole row - for(int xPos = xStart; xPos < xStart + xSize; ++xPos) - { - int xc = xPos >> 4; + int y0 = yStart; + int y1 = yStart + ySize; + if (y0 < 0) y0 = 0; + if (y1 > Level::maxBuildHeight) y1 = Level::maxBuildHeight; - int x0 = xPos - xc * 16; - if (x0 < 0) x0 = 0; - int x1 = x0 + 1; - if (x1 > 16) x1 = 16; + // Every x is a whole row + for (int xPos = xStart; xPos < xStart + xSize; ++xPos) { + int xc = xPos >> 4; - for(int zPos = zStart; zPos < zStart + zSize;) - { - int zc = zPos >> 4; + int x0 = xPos - xc * 16; + if (x0 < 0) x0 = 0; + int x1 = x0 + 1; + if (x1 > 16) x1 = 16; - int z0 = zStart - zc * 16; - int z1 = zStart + zSize - zc * 16; - if (z0 < 0) z0 = 0; - if (z1 > 16) z1 = 16; - getBlocksAndData(level->getChunk(xc, zc), &result, x0, y0, z0, x1, y1, z1, p, dataP, blockLightP, skyLightP); - zPos += (z1-z0); - } - } + for (int zPos = zStart; zPos < zStart + zSize;) { + int zc = zPos >> 4; + + int z0 = zStart - zc * 16; + int z1 = zStart + zSize - zc * 16; + if (z0 < 0) z0 = 0; + if (z1 > 16) z1 = 16; + getBlocksAndData(level->getChunk(xc, zc), &result, x0, y0, z0, x1, + y1, z1, p, dataP, blockLightP, skyLightP); + zPos += (z1 - z0); + } + } #ifndef _CONTENT_PACKAGE - if(p!=blockCount) __debugbreak(); + if (p != blockCount) __debugbreak(); #endif - // We don't know how this will compress - just make a fixed length buffer to initially decompress into - // Some small sets of blocks can end up compressing into something bigger than their source - unsigned int inputSize = blockCount * 3 / 2; - unsigned char *ucTemp = new unsigned char[inputSize]; + // We don't know how this will compress - just make a fixed length buffer to + // initially decompress into Some small sets of blocks can end up + // compressing into something bigger than their source + unsigned int inputSize = blockCount * 3 / 2; + unsigned char* ucTemp = new unsigned char[inputSize]; - switch(compressionType) - { - case Compression::eCompressionType_LZXRLE: - Compression::getCompression()->CompressLZXRLE( ucTemp, &inputSize, result.data, (unsigned int) result.length ); - break; - case Compression::eCompressionType_RLE: - Compression::getCompression()->CompressRLE( ucTemp, &inputSize, result.data, (unsigned int) result.length ); - break; - case Compression::eCompressionType_None: - default: - memcpy( ucTemp, result.data, inputSize ); - break; - }; + switch (compressionType) { + case Compression::eCompressionType_LZXRLE: + Compression::getCompression()->CompressLZXRLE( + ucTemp, &inputSize, result.data, (unsigned int)result.length); + break; + case Compression::eCompressionType_RLE: + Compression::getCompression()->CompressRLE( + ucTemp, &inputSize, result.data, (unsigned int)result.length); + break; + case Compression::eCompressionType_None: + default: + memcpy(ucTemp, result.data, inputSize); + break; + }; - delete [] result.data; - byteArray buffer = byteArray(ucTemp,inputSize); + delete[] result.data; + byteArray buffer = byteArray(ucTemp, inputSize); - if(dos != NULL) dos->writeInt(inputSize); - if(dos != NULL) dos->write(buffer); - delete [] buffer.data; + if (dos != NULL) dos->writeInt(inputSize); + if (dos != NULL) dos->write(buffer); + delete[] buffer.data; - CompoundTag tag; - ListTag *tileEntitiesTag = new ListTag(L"tileEntities"); + CompoundTag tag; + ListTag* tileEntitiesTag = + new ListTag(L"tileEntities"); - int xc0 = xStart >> 4; - int zc0 = zStart >> 4; - int xc1 = (xStart + xSize - 1) >> 4; - int zc1 = (zStart + zSize - 1) >> 4; + int xc0 = xStart >> 4; + int zc0 = zStart >> 4; + int xc1 = (xStart + xSize - 1) >> 4; + int zc1 = (zStart + zSize - 1) >> 4; - for (int xc = xc0; xc <= xc1; xc++) - { - for (int zc = zc0; zc <= zc1; zc++) - { - std::vector > *tileEntities = getTileEntitiesInRegion(level->getChunk(xc, zc), xStart, yStart, zStart, xStart + xSize, yStart + ySize, zStart + zSize); - for(AUTO_VAR(it, tileEntities->begin()); it != tileEntities->end(); ++it) - { - std::shared_ptr te = *it; - CompoundTag *teTag = new CompoundTag(); - std::shared_ptr teCopy = te->clone(); + for (int xc = xc0; xc <= xc1; xc++) { + for (int zc = zc0; zc <= zc1; zc++) { + std::vector >* tileEntities = + getTileEntitiesInRegion(level->getChunk(xc, zc), xStart, yStart, + zStart, xStart + xSize, yStart + ySize, + zStart + zSize); + for (AUTO_VAR(it, tileEntities->begin()); it != tileEntities->end(); + ++it) { + std::shared_ptr te = *it; + CompoundTag* teTag = new CompoundTag(); + std::shared_ptr teCopy = te->clone(); - // Adjust the tileEntity position to schematic coords from world co-ords - teCopy->x -= xStart; - teCopy->y -= yStart; - teCopy->z -= zStart; - teCopy->save(teTag); - tileEntitiesTag->add(teTag); - } - delete tileEntities; - } - } - tag.put(L"TileEntities", tileEntitiesTag); + // Adjust the tileEntity position to schematic coords from world + // co-ords + teCopy->x -= xStart; + teCopy->y -= yStart; + teCopy->z -= zStart; + teCopy->save(teTag); + tileEntitiesTag->add(teTag); + } + delete tileEntities; + } + } + tag.put(L"TileEntities", tileEntitiesTag); - AABB *bb = AABB::newTemp(xStart,yStart,zStart,xEnd,yEnd,zEnd); - std::vector > *entities = level->getEntities(nullptr, bb); - ListTag *entitiesTag = new ListTag(L"entities"); + AABB* bb = AABB::newTemp(xStart, yStart, zStart, xEnd, yEnd, zEnd); + std::vector >* entities = + level->getEntities(nullptr, bb); + ListTag* entitiesTag = new ListTag(L"entities"); - for(AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) - { - std::shared_ptr e = *it; + for (AUTO_VAR(it, entities->begin()); it != entities->end(); ++it) { + std::shared_ptr e = *it; - bool mobCanBeSaved = false; - if(bSaveMobs) - { - if( ( e->GetType() & eTYPE_MONSTER ) || ( e->GetType() & eTYPE_WATERANIMAL ) || ( e->GetType() & eTYPE_ANIMAL ) || - ( e->GetType() == eTYPE_CHICKEN ) || ( e->GetType() == eTYPE_WOLF ) || ( e->GetType() == eTYPE_VILLAGER) || ( e->GetType() == eTYPE_MUSHROOMCOW ) ) - { - mobCanBeSaved = true; - } - } - if(mobCanBeSaved || e->GetType() == eTYPE_MINECART || e->GetType() == eTYPE_BOAT || e->GetType() == eTYPE_PAINTING || e->GetType() == eTYPE_ITEM_FRAME) - { - CompoundTag *eTag = new CompoundTag(); - if( e->save(eTag) ) - { - ListTag *pos = (ListTag *) eTag->getList(L"Pos"); + bool mobCanBeSaved = false; + if (bSaveMobs) { + if ((e->GetType() & eTYPE_MONSTER) || + (e->GetType() & eTYPE_WATERANIMAL) || + (e->GetType() & eTYPE_ANIMAL) || + (e->GetType() == eTYPE_CHICKEN) || + (e->GetType() == eTYPE_WOLF) || + (e->GetType() == eTYPE_VILLAGER) || + (e->GetType() == eTYPE_MUSHROOMCOW)) { + mobCanBeSaved = true; + } + } + if (mobCanBeSaved || e->GetType() == eTYPE_MINECART || + e->GetType() == eTYPE_BOAT || e->GetType() == eTYPE_PAINTING || + e->GetType() == eTYPE_ITEM_FRAME) { + CompoundTag* eTag = new CompoundTag(); + if (e->save(eTag)) { + ListTag* pos = + (ListTag*)eTag->getList(L"Pos"); - pos->get(0)->data -= xStart; - pos->get(1)->data -= yStart; - pos->get(2)->data -= zStart; + pos->get(0)->data -= xStart; + pos->get(1)->data -= yStart; + pos->get(2)->data -= zStart; - if( e->GetType() == eTYPE_PAINTING || e->GetType() == eTYPE_ITEM_FRAME ) - { - ((IntTag *) eTag->get(L"TileX") )->data -= xStart; - ((IntTag *) eTag->get(L"TileY") )->data -= yStart; - ((IntTag *) eTag->get(L"TileZ") )->data -= zStart; - } + if (e->GetType() == eTYPE_PAINTING || + e->GetType() == eTYPE_ITEM_FRAME) { + ((IntTag*)eTag->get(L"TileX"))->data -= xStart; + ((IntTag*)eTag->get(L"TileY"))->data -= yStart; + ((IntTag*)eTag->get(L"TileZ"))->data -= zStart; + } - entitiesTag->add(eTag); - } - } - } + entitiesTag->add(eTag); + } + } + } - tag.put(L"Entities", entitiesTag); + tag.put(L"Entities", entitiesTag); - if(dos != NULL) NbtIo::write(&tag,dos); + if (dos != NULL) NbtIo::write(&tag, dos); } -void ConsoleSchematicFile::getBlocksAndData(LevelChunk *chunk, byteArray *data, int x0, int y0, int z0, int x1, int y1, int z1, int &blocksP, int &dataP, int &blockLightP, int &skyLightP) -{ - // 4J Stu - Needs updated to work with higher worlds, should still work with non-optimised version below - //int xs = x1 - x0; - //int ys = y1 - y0; - //int zs = z1 - z0; - //if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH) - //{ - // byteArray blockData = byteArray(data->data + blocksP, Level::CHUNK_TILE_COUNT); - // chunk->getBlockData(blockData); - // blocksP += blockData.length; +void ConsoleSchematicFile::getBlocksAndData(LevelChunk* chunk, byteArray* data, + int x0, int y0, int z0, int x1, + int y1, int z1, int& blocksP, + int& dataP, int& blockLightP, + int& skyLightP) { + // 4J Stu - Needs updated to work with higher worlds, should still work with + // non-optimised version below + // int xs = x1 - x0; + // int ys = y1 - y0; + // int zs = z1 - z0; + // if (xs * ys * zs == LevelChunk::BLOCKS_LENGTH) + //{ + // byteArray blockData = byteArray(data->data + blocksP, + //Level::CHUNK_TILE_COUNT); chunk->getBlockData(blockData); blocksP += + //blockData.length; - // byteArray dataData = byteArray(data->data + dataP, 16384); - // chunk->getBlockLightData(dataData); - // dataP += dataData.length; + // byteArray dataData = byteArray(data->data + dataP, 16384); + // chunk->getBlockLightData(dataData); + // dataP += dataData.length; - // byteArray blockLightData = byteArray(data->data + blockLightP, 16384); - // chunk->getBlockLightData(blockLightData); - // blockLightP += blockLightData.length; + // byteArray blockLightData = byteArray(data->data + blockLightP, 16384); + // chunk->getBlockLightData(blockLightData); + // blockLightP += blockLightData.length; - // byteArray skyLightData = byteArray(data->data + skyLightP, 16384); - // chunk->getSkyLightData(skyLightData); - // skyLightP += skyLightData.length; - // return; - //} - - bool bHasLower, bHasUpper; - bHasLower = bHasUpper = false; - int lowerY0, lowerY1, upperY0, upperY1; - lowerY0 = upperY0 = y0; - lowerY1 = upperY1 = y1; + // byteArray skyLightData = byteArray(data->data + skyLightP, 16384); + // chunk->getSkyLightData(skyLightData); + // skyLightP += skyLightData.length; + // return; + //} - int compressedHeight = Level::COMPRESSED_CHUNK_SECTION_HEIGHT; - if(y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) - { - lowerY0 = y0; - lowerY1 = std::min(y1, compressedHeight); - bHasLower = true; - } - if(y1 >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT) - { - upperY0 = std::max(y0, compressedHeight) - Level::COMPRESSED_CHUNK_SECTION_HEIGHT; - upperY1 = y1 - Level::COMPRESSED_CHUNK_SECTION_HEIGHT; - bHasUpper = true; - } + bool bHasLower, bHasUpper; + bHasLower = bHasUpper = false; + int lowerY0, lowerY1, upperY0, upperY1; + lowerY0 = upperY0 = y0; + lowerY1 = upperY1 = y1; - byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); - chunk->getBlockData(blockData); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0; - int len = lowerY1 - lowerY0; - System::arraycopy(blockData, slot, data, blocksP, len); - blocksP += len; - } - if(bHasUpper) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) + Level::COMPRESSED_CHUNK_SECTION_TILES; - int len = upperY1 - upperY0; - System::arraycopy(blockData, slot, data, blocksP, len); - blocksP += len; - } - } - delete blockData.data; + int compressedHeight = Level::COMPRESSED_CHUNK_SECTION_HEIGHT; + if (y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) { + lowerY0 = y0; + lowerY1 = std::min(y1, compressedHeight); + bHasLower = true; + } + if (y1 >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT) { + upperY0 = std::max(y0, compressedHeight) - + Level::COMPRESSED_CHUNK_SECTION_HEIGHT; + upperY1 = y1 - Level::COMPRESSED_CHUNK_SECTION_HEIGHT; + bHasUpper = true; + } - byteArray dataData = byteArray(Level::CHUNK_TILE_COUNT); - chunk->getDataData(dataData); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0) >> 1; - int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(dataData, slot, data, dataP, len); - dataP += len; - } - if(bHasUpper) - { - int slot = ((x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) + Level::COMPRESSED_CHUNK_SECTION_TILES) >> 1; - int len = (upperY1 - upperY0) / 2; - System::arraycopy(dataData, slot, data, dataP, len); - dataP += len; - } - } - delete dataData.data; + byteArray blockData = byteArray(Level::CHUNK_TILE_COUNT); + chunk->getBlockData(blockData); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0; + int len = lowerY1 - lowerY0; + System::arraycopy(blockData, slot, data, blocksP, len); + blocksP += len; + } + if (bHasUpper) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) + + Level::COMPRESSED_CHUNK_SECTION_TILES; + int len = upperY1 - upperY0; + System::arraycopy(blockData, slot, data, blocksP, len); + blocksP += len; + } + } + delete blockData.data; - // 4J Stu - Allow ignoring light data - if(blockLightP > -1) - { - byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); - chunk->getBlockLightData(blockLightData); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0) >> 1; - int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(blockLightData, slot, data, blockLightP, len); - blockLightP += len; - } - if(bHasUpper) - { - int slot = ((x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) >> 1) + (Level::COMPRESSED_CHUNK_SECTION_TILES/2); - int len = (upperY1 - upperY0) / 2; - System::arraycopy(blockLightData, slot, data, blockLightP, len); - blockLightP += len; - } - } - delete blockLightData.data; - } + byteArray dataData = byteArray(Level::CHUNK_TILE_COUNT); + chunk->getDataData(dataData); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0) >> + 1; + int len = (lowerY1 - lowerY0) / 2; + System::arraycopy(dataData, slot, data, dataP, len); + dataP += len; + } + if (bHasUpper) { + int slot = ((x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) + + Level::COMPRESSED_CHUNK_SECTION_TILES) >> + 1; + int len = (upperY1 - upperY0) / 2; + System::arraycopy(dataData, slot, data, dataP, len); + dataP += len; + } + } + delete dataData.data; + // 4J Stu - Allow ignoring light data + if (blockLightP > -1) { + byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + chunk->getBlockLightData(blockLightData); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0) >> + 1; + int len = (lowerY1 - lowerY0) / 2; + System::arraycopy(blockLightData, slot, data, blockLightP, + len); + blockLightP += len; + } + if (bHasUpper) { + int slot = ((x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) >> + 1) + + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); + int len = (upperY1 - upperY0) / 2; + System::arraycopy(blockLightData, slot, data, blockLightP, + len); + blockLightP += len; + } + } + delete blockLightData.data; + } - // 4J Stu - Allow ignoring light data - if(skyLightP > -1) - { - byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); - chunk->getSkyLightData(skyLightData); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0) >> 1; - int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(skyLightData, slot, data, skyLightP, len); - skyLightP += len; - } - if(bHasUpper) - { - int slot = ((x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) >> 1) + (Level::COMPRESSED_CHUNK_SECTION_TILES/2); - int len = (upperY1 - upperY0) / 2; - System::arraycopy(skyLightData, slot, data, skyLightP, len); - skyLightP += len; - } - } - delete skyLightData.data; - } + // 4J Stu - Allow ignoring light data + if (skyLightP > -1) { + byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + chunk->getSkyLightData(skyLightData); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0) >> + 1; + int len = (lowerY1 - lowerY0) / 2; + System::arraycopy(skyLightData, slot, data, skyLightP, len); + skyLightP += len; + } + if (bHasUpper) { + int slot = ((x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) >> + 1) + + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); + int len = (upperY1 - upperY0) / 2; + System::arraycopy(skyLightData, slot, data, skyLightP, len); + skyLightP += len; + } + } + delete skyLightData.data; + } - return; + return; } -void ConsoleSchematicFile::setBlocksAndData(LevelChunk *chunk, byteArray blockData, byteArray dataData, byteArray inputData, int x0, int y0, int z0, int x1, int y1, int z1, int &blocksP, int &dataP, int &blockLightP, int &skyLightP) -{ - bool bHasLower, bHasUpper; - bHasLower = bHasUpper = false; - int lowerY0, lowerY1, upperY0, upperY1; - lowerY0 = upperY0 = y0; - lowerY1 = upperY1 = y1; +void ConsoleSchematicFile::setBlocksAndData( + LevelChunk* chunk, byteArray blockData, byteArray dataData, + byteArray inputData, int x0, int y0, int z0, int x1, int y1, int z1, + int& blocksP, int& dataP, int& blockLightP, int& skyLightP) { + bool bHasLower, bHasUpper; + bHasLower = bHasUpper = false; + int lowerY0, lowerY1, upperY0, upperY1; + lowerY0 = upperY0 = y0; + lowerY1 = upperY1 = y1; - int compressedHeight = Level::COMPRESSED_CHUNK_SECTION_HEIGHT; - if(y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) - { - lowerY0 = y0; - lowerY1 = std::min(y1, compressedHeight); - bHasLower = true; - } - if(y1 >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT) - { - upperY0 = std::max(y0, compressedHeight) - Level::COMPRESSED_CHUNK_SECTION_HEIGHT; - upperY1 = y1 - Level::COMPRESSED_CHUNK_SECTION_HEIGHT; - bHasUpper = true; - } - PIXBeginNamedEvent(0,"Applying block data"); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0; - int len = lowerY1 - lowerY0; - System::arraycopy(inputData, blocksP, &blockData, slot, len); - blocksP += len; - } - if(bHasUpper) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) + Level::COMPRESSED_CHUNK_SECTION_TILES; - int len = upperY1 - upperY0; - System::arraycopy(inputData, blocksP, &blockData, slot, len); - blocksP += len; - } - } - PIXEndNamedEvent(); + int compressedHeight = Level::COMPRESSED_CHUNK_SECTION_HEIGHT; + if (y0 < Level::COMPRESSED_CHUNK_SECTION_HEIGHT) { + lowerY0 = y0; + lowerY1 = std::min(y1, compressedHeight); + bHasLower = true; + } + if (y1 >= Level::COMPRESSED_CHUNK_SECTION_HEIGHT) { + upperY0 = std::max(y0, compressedHeight) - + Level::COMPRESSED_CHUNK_SECTION_HEIGHT; + upperY1 = y1 - Level::COMPRESSED_CHUNK_SECTION_HEIGHT; + bHasUpper = true; + } + PIXBeginNamedEvent(0, "Applying block data"); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0; + int len = lowerY1 - lowerY0; + System::arraycopy(inputData, blocksP, &blockData, slot, len); + blocksP += len; + } + if (bHasUpper) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) + + Level::COMPRESSED_CHUNK_SECTION_TILES; + int len = upperY1 - upperY0; + System::arraycopy(inputData, blocksP, &blockData, slot, len); + blocksP += len; + } + } + PIXEndNamedEvent(); - PIXBeginNamedEvent(0,"Applying Data data"); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0) >> 1; - int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(inputData, dataP, &dataData, slot, len); - dataP += len; - } - if(bHasUpper) - { - int slot = ((x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) + Level::COMPRESSED_CHUNK_SECTION_TILES) >> 1; - int len = (upperY1 - upperY0) / 2; - System::arraycopy(inputData, dataP, &dataData, slot, len); - dataP += len; - } - } - PIXEndNamedEvent(); - // 4J Stu - Allow ignoring light data - if(blockLightP > -1) - { - byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); - chunk->getBlockLightData(blockLightData); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0) >> 1; - int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(inputData, blockLightP, &blockLightData, slot, len); - blockLightP += len; - } - if(bHasUpper) - { - int slot = ( (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) >> 1) + (Level::COMPRESSED_CHUNK_SECTION_TILES/2); - int len = (upperY1 - upperY0) / 2; - System::arraycopy(inputData, blockLightP, &blockLightData, slot, len); - blockLightP += len; - } - } - chunk->setBlockLightData(blockLightData); - delete blockLightData.data; - } + PIXBeginNamedEvent(0, "Applying Data data"); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0) >> + 1; + int len = (lowerY1 - lowerY0) / 2; + System::arraycopy(inputData, dataP, &dataData, slot, len); + dataP += len; + } + if (bHasUpper) { + int slot = ((x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) + + Level::COMPRESSED_CHUNK_SECTION_TILES) >> + 1; + int len = (upperY1 - upperY0) / 2; + System::arraycopy(inputData, dataP, &dataData, slot, len); + dataP += len; + } + } + PIXEndNamedEvent(); + // 4J Stu - Allow ignoring light data + if (blockLightP > -1) { + byteArray blockLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + chunk->getBlockLightData(blockLightData); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0) >> + 1; + int len = (lowerY1 - lowerY0) / 2; + System::arraycopy(inputData, blockLightP, &blockLightData, + slot, len); + blockLightP += len; + } + if (bHasUpper) { + int slot = ((x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) >> + 1) + + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); + int len = (upperY1 - upperY0) / 2; + System::arraycopy(inputData, blockLightP, &blockLightData, + slot, len); + blockLightP += len; + } + } + chunk->setBlockLightData(blockLightData); + delete blockLightData.data; + } - // 4J Stu - Allow ignoring light data - if(skyLightP > -1) - { - byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); - chunk->getSkyLightData(skyLightData); - for (int x = x0; x < x1; x++) - for (int z = z0; z < z1; z++) - { - if(bHasLower) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | lowerY0) >> 1; - int len = (lowerY1 - lowerY0) / 2; - System::arraycopy(inputData, skyLightP, &skyLightData, slot, len); - skyLightP += len; - } - if(bHasUpper) - { - int slot = (x << Level::genDepthBitsPlusFour | z << Level::genDepthBits | upperY0) + (Level::COMPRESSED_CHUNK_SECTION_TILES/2); - int len = (upperY1 - upperY0) / 2; - System::arraycopy(inputData, skyLightP, &skyLightData, slot, len); - skyLightP += len; - } - } - chunk->setSkyLightData(skyLightData); - delete skyLightData.data; - } + // 4J Stu - Allow ignoring light data + if (skyLightP > -1) { + byteArray skyLightData = byteArray(Level::HALF_CHUNK_TILE_COUNT); + chunk->getSkyLightData(skyLightData); + for (int x = x0; x < x1; x++) + for (int z = z0; z < z1; z++) { + if (bHasLower) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | lowerY0) >> + 1; + int len = (lowerY1 - lowerY0) / 2; + System::arraycopy(inputData, skyLightP, &skyLightData, slot, + len); + skyLightP += len; + } + if (bHasUpper) { + int slot = (x << Level::genDepthBitsPlusFour | + z << Level::genDepthBits | upperY0) + + (Level::COMPRESSED_CHUNK_SECTION_TILES / 2); + int len = (upperY1 - upperY0) / 2; + System::arraycopy(inputData, skyLightP, &skyLightData, slot, + len); + skyLightP += len; + } + } + chunk->setSkyLightData(skyLightData); + delete skyLightData.data; + } } -std::vector > *ConsoleSchematicFile::getTileEntitiesInRegion(LevelChunk *chunk, int x0, int y0, int z0, int x1, int y1, int z1) -{ - std::vector > *result = new std::vector >; - for (AUTO_VAR(it, chunk->tileEntities.begin()); it != chunk->tileEntities.end(); ++it) - { - std::shared_ptr te = it->second; - if (te->x >= x0 && te->y >= y0 && te->z >= z0 && te->x < x1 && te->y < y1 && te->z < z1) - { - result->push_back(te); - } - } - return result; +std::vector >* +ConsoleSchematicFile::getTileEntitiesInRegion(LevelChunk* chunk, int x0, int y0, + int z0, int x1, int y1, int z1) { + std::vector >* result = + new std::vector >; + for (AUTO_VAR(it, chunk->tileEntities.begin()); + it != chunk->tileEntities.end(); ++it) { + std::shared_ptr te = it->second; + if (te->x >= x0 && te->y >= y0 && te->z >= z0 && te->x < x1 && + te->y < y1 && te->z < z1) { + result->push_back(te); + } + } + return result; } diff --git a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h index 371064960..1990328a8 100644 --- a/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h +++ b/Minecraft.Client/Platform/Common/GameRules/ConsoleSchematicFile.h @@ -1,5 +1,5 @@ #pragma once -//using namespace std; +// using namespace std; #define XBOX_SCHEMATIC_ORIGINAL_VERSION 1 #define XBOX_SCHEMATIC_CURRENT_VERSION 2 @@ -14,77 +14,95 @@ class LevelChunk; class AABB; class Vec3; -class ConsoleSchematicFile -{ +class ConsoleSchematicFile { public: - enum ESchematicRotation - { - eSchematicRot_0, - eSchematicRot_90, - eSchematicRot_180, - eSchematicRot_270 - }; + enum ESchematicRotation { + eSchematicRot_0, + eSchematicRot_90, + eSchematicRot_180, + eSchematicRot_270 + }; + private: - int m_refCount; + int m_refCount; public: - void incrementRefCount() { ++m_refCount; } - void decrementRefCount() { --m_refCount; } - bool shouldDelete() { return m_refCount <= 0; } + void incrementRefCount() { ++m_refCount; } + void decrementRefCount() { --m_refCount; } + bool shouldDelete() { return m_refCount <= 0; } - typedef struct _XboxSchematicInitParam - { - wchar_t name[64]; - int startX; - int startY; - int startZ; - int endX; - int endY; - int endZ; - bool bSaveMobs; + typedef struct _XboxSchematicInitParam { + wchar_t name[64]; + int startX; + int startY; + int startZ; + int endX; + int endY; + int endZ; + bool bSaveMobs; - Compression::ECompressionTypes compressionType; + Compression::ECompressionTypes compressionType; + + _XboxSchematicInitParam() { + ZeroMemory(name, 64 * (sizeof(wchar_t))); + startX = startY = startZ = endX = endY = endZ = 0; + bSaveMobs = false; + compressionType = Compression::eCompressionType_None; + } + } XboxSchematicInitParam; - _XboxSchematicInitParam() - { - ZeroMemory(name,64*(sizeof(wchar_t))); - startX = startY = startZ = endX = endY = endZ = 0; - bSaveMobs = false; - compressionType = Compression::eCompressionType_None; - } - } XboxSchematicInitParam; private: - int m_xSize, m_ySize, m_zSize; - std::vector > m_tileEntities; - std::vector< std::pair > m_entities; - -public: - byteArray m_data; + int m_xSize, m_ySize, m_zSize; + std::vector > m_tileEntities; + std::vector > m_entities; public: - ConsoleSchematicFile(); - ~ConsoleSchematicFile(); + byteArray m_data; - int getXSize() { return m_xSize; } - int getYSize() { return m_ySize; } - int getZSize() { return m_zSize; } +public: + ConsoleSchematicFile(); + ~ConsoleSchematicFile(); - void save(DataOutputStream *dos); - void load(DataInputStream *dis); + int getXSize() { return m_xSize; } + int getYSize() { return m_ySize; } + int getZSize() { return m_zSize; } - __int64 applyBlocksAndData(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot); - __int64 applyLighting(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot); - void applyTileEntities(LevelChunk *chunk, AABB *chunkBox, AABB *destinationBox, ESchematicRotation rot); + void save(DataOutputStream* dos); + void load(DataInputStream* dis); + + __int64 applyBlocksAndData(LevelChunk* chunk, AABB* chunkBox, + AABB* destinationBox, ESchematicRotation rot); + __int64 applyLighting(LevelChunk* chunk, AABB* chunkBox, + AABB* destinationBox, ESchematicRotation rot); + void applyTileEntities(LevelChunk* chunk, AABB* chunkBox, + AABB* destinationBox, ESchematicRotation rot); + + static void generateSchematicFile(DataOutputStream* dos, Level* level, + int xStart, int yStart, int zStart, + int xEnd, int yEnd, int zEnd, + bool bSaveMobs, + Compression::ECompressionTypes); + static void setBlocksAndData(LevelChunk* chunk, byteArray blockData, + byteArray dataData, byteArray data, int x0, + int y0, int z0, int x1, int y1, int z1, + int& blocksP, int& dataP, int& blockLightP, + int& skyLightP); - static void generateSchematicFile(DataOutputStream *dos, Level *level, int xStart, int yStart, int zStart, int xEnd, int yEnd, int zEnd, bool bSaveMobs, Compression::ECompressionTypes); - static void setBlocksAndData(LevelChunk *chunk, byteArray blockData, byteArray dataData, byteArray data, int x0, int y0, int z0, int x1, int y1, int z1, int &blocksP, int &dataP, int &blockLightP, int &skyLightP); private: - void save_tags(DataOutputStream *dos); - void load_tags(DataInputStream *dis); + void save_tags(DataOutputStream* dos); + void load_tags(DataInputStream* dis); - static void getBlocksAndData(LevelChunk *chunk, byteArray *data, int x0, int y0, int z0, int x1, int y1, int z1, int &blocksP, int &dataP, int &blockLightP, int &skyLightP); - static std::vector > *getTileEntitiesInRegion(LevelChunk *chunk, int x0, int y0, int z0, int x1, int y1, int z1); + static void getBlocksAndData(LevelChunk* chunk, byteArray* data, int x0, + int y0, int z0, int x1, int y1, int z1, + int& blocksP, int& dataP, int& blockLightP, + int& skyLightP); + static std::vector >* getTileEntitiesInRegion( + LevelChunk* chunk, int x0, int y0, int z0, int x1, int y1, int z1); - void chunkCoordToSchematicCoord(AABB *destinationBox, int chunkX, int chunkZ, ESchematicRotation rot, int &schematicX, int &schematicZ); - void schematicCoordToChunkCoord(AABB *destinationBox, double schematicX, double schematicZ, ESchematicRotation rot, double &chunkX, double &chunkZ); + void chunkCoordToSchematicCoord(AABB* destinationBox, int chunkX, + int chunkZ, ESchematicRotation rot, + int& schematicX, int& schematicZ); + void schematicCoordToChunkCoord(AABB* destinationBox, double schematicX, + double schematicZ, ESchematicRotation rot, + double& chunkX, double& chunkZ); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/GameRule.cpp b/Minecraft.Client/Platform/Common/GameRules/GameRule.cpp index 2bfcbb197..95e1a9037 100644 --- a/Minecraft.Client/Platform/Common/GameRules/GameRule.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/GameRule.cpp @@ -1,97 +1,83 @@ #include "../../Minecraft.World/Platform/stdafx.h" #include "ConsoleGameRules.h" -GameRule::GameRule(GameRuleDefinition *definition, Connection *connection) -{ - m_definition = definition; - m_connection = connection; +GameRule::GameRule(GameRuleDefinition* definition, Connection* connection) { + m_definition = definition; + m_connection = connection; } -GameRule::~GameRule() -{ - for(AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); ++it) - { - if(it->second.isPointer) - { - delete it->second.gr; - } - } +GameRule::~GameRule() { + for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); ++it) { + if (it->second.isPointer) { + delete it->second.gr; + } + } } -GameRule::ValueType GameRule::getParameter(const std::wstring ¶meterName) -{ - if(m_parameters.find(parameterName) == m_parameters.end()) - { +GameRule::ValueType GameRule::getParameter(const std::wstring& parameterName) { + if (m_parameters.find(parameterName) == m_parameters.end()) { #ifndef _CONTENT_PACKAGE - wprintf(L"WARNING: Parameter %ls was not set before being fetched\n", parameterName.c_str()); - __debugbreak(); + wprintf(L"WARNING: Parameter %ls was not set before being fetched\n", + parameterName.c_str()); + __debugbreak(); #endif - } - return m_parameters[parameterName]; + } + return m_parameters[parameterName]; } -void GameRule::setParameter(const std::wstring ¶meterName,ValueType value) -{ - if(m_parameters.find(parameterName) == m_parameters.end()) - { +void GameRule::setParameter(const std::wstring& parameterName, + ValueType value) { + if (m_parameters.find(parameterName) == m_parameters.end()) { #ifndef _CONTENT_PACKAGE - wprintf(L"Adding parameter %ls to GameRule\n", parameterName.c_str()); + wprintf(L"Adding parameter %ls to GameRule\n", parameterName.c_str()); #endif - } - else - { + } else { #ifndef _CONTENT_PACKAGE - wprintf(L"Setting parameter %ls for GameRule\n", parameterName.c_str()); + wprintf(L"Setting parameter %ls for GameRule\n", parameterName.c_str()); #endif - } - m_parameters[parameterName] = value; + } + m_parameters[parameterName] = value; } -GameRuleDefinition *GameRule::getGameRuleDefinition() -{ - return m_definition; +GameRuleDefinition* GameRule::getGameRuleDefinition() { return m_definition; } + +void GameRule::onUseTile(int tileId, int x, int y, int z) { + m_definition->onUseTile(this, tileId, x, y, z); +} +void GameRule::onCollectItem(std::shared_ptr item) { + m_definition->onCollectItem(this, item); } -void GameRule::onUseTile(int tileId, int x, int y, int z) { m_definition->onUseTile(this,tileId,x,y,z); } -void GameRule::onCollectItem(std::shared_ptr item) { m_definition->onCollectItem(this,item); } +void GameRule::write(DataOutputStream* dos) { + // Find required parameters. + dos->writeInt(m_parameters.size()); + for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); it++) { + std::wstring pName = (*it).first; + ValueType vType = (*it).second; -void GameRule::write(DataOutputStream *dos) -{ - // Find required parameters. - dos->writeInt(m_parameters.size()); - for (AUTO_VAR(it, m_parameters.begin()); it != m_parameters.end(); it++) - { - std::wstring pName = (*it).first; - ValueType vType = (*it).second; - - dos->writeUTF( (*it).first ); - dos->writeBoolean( vType.isPointer ); + dos->writeUTF((*it).first); + dos->writeBoolean(vType.isPointer); - if (vType.isPointer) - vType.gr->write(dos); - else - dos->writeLong( vType.i64 ); - } + if (vType.isPointer) + vType.gr->write(dos); + else + dos->writeLong(vType.i64); + } } -void GameRule::read(DataInputStream *dis) -{ - int savedParams = dis->readInt(); - for (int i = 0; i < savedParams; i++) - { - std::wstring pNames = dis->readUTF(); - - ValueType vType = getParameter(pNames); +void GameRule::read(DataInputStream* dis) { + int savedParams = dis->readInt(); + for (int i = 0; i < savedParams; i++) { + std::wstring pNames = dis->readUTF(); - if (dis->readBoolean()) - { - vType.gr->read(dis); - } - else - { - vType.isPointer = false; - vType.i64 = dis->readLong(); - setParameter(pNames, vType); - } - } + ValueType vType = getParameter(pNames); + + if (dis->readBoolean()) { + vType.gr->read(dis); + } else { + vType.isPointer = false; + vType.i64 = dis->readLong(); + setParameter(pNames, vType); + } + } } diff --git a/Minecraft.Client/Platform/Common/GameRules/GameRule.h b/Minecraft.Client/Platform/Common/GameRules/GameRule.h index 33eb1348d..51265967d 100644 --- a/Minecraft.Client/Platform/Common/GameRules/GameRule.h +++ b/Minecraft.Client/Platform/Common/GameRules/GameRule.h @@ -1,5 +1,5 @@ #pragma once -//using namespace std; +// using namespace std; #include @@ -8,55 +8,54 @@ class GameRuleDefinition; class Connection; // A game rule maintains the state for one particular definition -class GameRule -{ +class GameRule { public: - typedef struct _ValueType - { - union{ - __int64 i64; - int i; - char c; - bool b; - float f; - double d; - GameRule *gr; - }; - bool isPointer; + typedef struct _ValueType { + union { + __int64 i64; + int i; + char c; + bool b; + float f; + double d; + GameRule* gr; + }; + bool isPointer; - _ValueType() - { - i64 = 0; - isPointer = false; - } - } ValueType; + _ValueType() { + i64 = 0; + isPointer = false; + } + } ValueType; private: - GameRuleDefinition *m_definition; - Connection *m_connection; + GameRuleDefinition* m_definition; + Connection* m_connection; public: - typedef std::unordered_map stringValueMapType; - stringValueMapType m_parameters; // These are the members of this rule that maintain it's state + typedef std::unordered_map stringValueMapType; + stringValueMapType m_parameters; // These are the members of this rule that + // maintain it's state public: - GameRule(GameRuleDefinition *definition, Connection *connection = NULL); - virtual ~GameRule(); + GameRule(GameRuleDefinition* definition, Connection* connection = NULL); + virtual ~GameRule(); - Connection *getConnection() { return m_connection; } - - ValueType getParameter(const std::wstring ¶meterName); - void setParameter(const std::wstring ¶meterName,ValueType value); - GameRuleDefinition *getGameRuleDefinition(); + Connection* getConnection() { return m_connection; } - // All the hooks go here - void onUseTile(int tileId, int x, int y, int z); - void onCollectItem(std::shared_ptr item); + ValueType getParameter(const std::wstring& parameterName); + void setParameter(const std::wstring& parameterName, ValueType value); + GameRuleDefinition* getGameRuleDefinition(); - // 4J-JEV: For saving. - //CompoundTag *toTags(std::unordered_map *map); - //static GameRule *fromTags(Connection *c, CompoundTag *cTag, std::vector *grds); + // All the hooks go here + void onUseTile(int tileId, int x, int y, int z); + void onCollectItem(std::shared_ptr item); - void write(DataOutputStream *dos); - void read(DataInputStream *dos); + // 4J-JEV: For saving. + // CompoundTag *toTags(std::unordered_map *map); + // static GameRule *fromTags(Connection *c, CompoundTag *cTag, + // std::vector *grds); + + void write(DataOutputStream* dos); + void read(DataInputStream* dos); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.cpp index 0aaabb754..0cf38789b 100644 --- a/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.cpp @@ -3,149 +3,149 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "ConsoleGameRules.h" -GameRuleDefinition::GameRuleDefinition() -{ - m_descriptionId = L""; - m_promptId = L""; - m_4JDataValue = 0; +GameRuleDefinition::GameRuleDefinition() { + m_descriptionId = L""; + m_promptId = L""; + m_4JDataValue = 0; } -void GameRuleDefinition::write(DataOutputStream *dos) -{ - // Write EGameRuleType. - ConsoleGameRules::EGameRuleType eType = getActionType(); - assert( eType != ConsoleGameRules::eGameRuleType_Invalid ); - ConsoleGameRules::write(dos, eType); // stringID +void GameRuleDefinition::write(DataOutputStream* dos) { + // Write EGameRuleType. + ConsoleGameRules::EGameRuleType eType = getActionType(); + assert(eType != ConsoleGameRules::eGameRuleType_Invalid); + ConsoleGameRules::write(dos, eType); // stringID - writeAttributes(dos, 0); - - // 4J-JEV: Get children. - std::vector *children = new std::vector(); - getChildren( children ); + writeAttributes(dos, 0); - // Write children. - dos->writeInt( children->size() ); - for (AUTO_VAR(it, children->begin()); it != children->end(); it++) - (*it)->write(dos); + // 4J-JEV: Get children. + std::vector* children = + new std::vector(); + getChildren(children); + + // Write children. + dos->writeInt(children->size()); + for (AUTO_VAR(it, children->begin()); it != children->end(); it++) + (*it)->write(dos); } -void GameRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) -{ - dos->writeInt(numAttributes + 3); +void GameRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttributes) { + dos->writeInt(numAttributes + 3); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_descriptionName); - dos->writeUTF(m_descriptionId); + ConsoleGameRules::write(dos, + ConsoleGameRules::eGameRuleAttr_descriptionName); + dos->writeUTF(m_descriptionId); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName); - dos->writeUTF(m_promptId); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_promptName); + dos->writeUTF(m_promptId); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag); - dos->writeUTF(_toString(m_4JDataValue)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_dataTag); + dos->writeUTF(_toString(m_4JDataValue)); } -void GameRuleDefinition::getChildren(std::vector *children) {} +void GameRuleDefinition::getChildren( + std::vector* children) {} -GameRuleDefinition *GameRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ +GameRuleDefinition* GameRuleDefinition::addChild( + ConsoleGameRules::EGameRuleType ruleType) { #ifndef _CONTENT_PACKAGE - wprintf(L"GameRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); + wprintf(L"GameRuleDefinition: Attempted to add invalid child rule - %d\n", + ruleType); #endif - return NULL; + return NULL; } -void GameRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"descriptionName") == 0) - { - m_descriptionId = attributeValue; +void GameRuleDefinition::addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue) { + if (attributeName.compare(L"descriptionName") == 0) { + m_descriptionId = attributeValue; #ifndef _CONTENT_PACKAGE - wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n",m_descriptionId.c_str()); + wprintf(L"GameRuleDefinition: Adding parameter descriptionId=%ls\n", + m_descriptionId.c_str()); #endif - } - else if(attributeName.compare(L"promptName") == 0) - { - m_promptId = attributeValue; + } else if (attributeName.compare(L"promptName") == 0) { + m_promptId = attributeValue; #ifndef _CONTENT_PACKAGE - wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n",m_promptId.c_str()); + wprintf(L"GameRuleDefinition: Adding parameter m_promptId=%ls\n", + m_promptId.c_str()); #endif - } - else if(attributeName.compare(L"dataTag") == 0) - { - m_4JDataValue = _fromString(attributeValue); - app.DebugPrintf("GameRuleDefinition: Adding parameter m_4JDataValue=%d\n",m_4JDataValue); - } - else - { + } else if (attributeName.compare(L"dataTag") == 0) { + m_4JDataValue = _fromString(attributeValue); + app.DebugPrintf( + "GameRuleDefinition: Adding parameter m_4JDataValue=%d\n", + m_4JDataValue); + } else { #ifndef _CONTENT_PACKAGE - wprintf(L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n", attributeName.c_str()); + wprintf( + L"GameRuleDefinition: Attempted to add invalid attribute: %ls\n", + attributeName.c_str()); #endif - } + } } -void GameRuleDefinition::populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule) -{ - GameRule::ValueType value; - value.b = false; - rule->setParameter(L"bComplete",value); +void GameRuleDefinition::populateGameRule( + GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) { + GameRule::ValueType value; + value.b = false; + rule->setParameter(L"bComplete", value); } -bool GameRuleDefinition::getComplete(GameRule *rule) -{ - GameRule::ValueType value; - value = rule->getParameter(L"bComplete"); - return value.b; +bool GameRuleDefinition::getComplete(GameRule* rule) { + GameRule::ValueType value; + value = rule->getParameter(L"bComplete"); + return value.b; } -void GameRuleDefinition::setComplete(GameRule *rule, bool val) -{ - GameRule::ValueType value; - value = rule->getParameter(L"bComplete"); - value.b = val; - rule->setParameter(L"bComplete",value); +void GameRuleDefinition::setComplete(GameRule* rule, bool val) { + GameRule::ValueType value; + value = rule->getParameter(L"bComplete"); + value.b = val; + rule->setParameter(L"bComplete", value); } -std::vector *GameRuleDefinition::enumerate() -{ - // Get Vector. - std::vector *gRules; - gRules = new std::vector(); - gRules->push_back(this); - getChildren(gRules); - return gRules; +std::vector* GameRuleDefinition::enumerate() { + // Get Vector. + std::vector* gRules; + gRules = new std::vector(); + gRules->push_back(this); + getChildren(gRules); + return gRules; } -std::unordered_map *GameRuleDefinition::enumerateMap() -{ - std::unordered_map *out - = new std::unordered_map(); +std::unordered_map* +GameRuleDefinition::enumerateMap() { + std::unordered_map* out = + new std::unordered_map(); - int i = 0; - std::vector *gRules = enumerate(); - for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++) - out->insert( std::pair( *it, i++ ) ); + int i = 0; + std::vector* gRules = enumerate(); + for (AUTO_VAR(it, gRules->begin()); it != gRules->end(); it++) + out->insert(std::pair(*it, i++)); - return out; + return out; } -GameRulesInstance *GameRuleDefinition::generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection) -{ - GameRulesInstance *manager = new GameRulesInstance(rules, connection); +GameRulesInstance* GameRuleDefinition::generateNewGameRulesInstance( + GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules, + Connection* connection) { + GameRulesInstance* manager = new GameRulesInstance(rules, connection); - rules->populateGameRule(type, manager); + rules->populateGameRule(type, manager); - return manager; + return manager; } -std::wstring GameRuleDefinition::generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const std::wstring &description, void *data, int dataLength) -{ - std::wstring formatted = description; - switch(defType) - { - case ConsoleGameRules::eGameRuleType_CompleteAllRule: - formatted = CompleteAllRuleDefinition::generateDescriptionString(description,data,dataLength); - break; - default: - break; - }; - return formatted; +std::wstring GameRuleDefinition::generateDescriptionString( + ConsoleGameRules::EGameRuleType defType, const std::wstring& description, + void* data, int dataLength) { + std::wstring formatted = description; + switch (defType) { + case ConsoleGameRules::eGameRuleType_CompleteAllRule: + formatted = CompleteAllRuleDefinition::generateDescriptionString( + description, data, dataLength); + break; + default: + break; + }; + return formatted; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.h index ae917556f..6480d6936 100644 --- a/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/GameRuleDefinition.h @@ -1,5 +1,5 @@ #pragma once -//using namespace std; +// using namespace std; #include #include @@ -13,55 +13,69 @@ class LevelRuleset; class Player; class WstringLookup; -class GameRuleDefinition -{ +class GameRuleDefinition { private: - // Owner type defines who this rule applies to - GameRulesInstance::EGameRulesInstanceType m_ownerType; + // Owner type defines who this rule applies to + GameRulesInstance::EGameRulesInstanceType m_ownerType; protected: - // These attributes should map to those in the XSD GameRuleType - std::wstring m_descriptionId; - std::wstring m_promptId; - int m_4JDataValue; + // These attributes should map to those in the XSD GameRuleType + std::wstring m_descriptionId; + std::wstring m_promptId; + int m_4JDataValue; public: - GameRuleDefinition(); - virtual ~GameRuleDefinition(){} + GameRuleDefinition(); + virtual ~GameRuleDefinition() {} - virtual ConsoleGameRules::EGameRuleType getActionType() = 0; + virtual ConsoleGameRules::EGameRuleType getActionType() = 0; - void setOwnerType(GameRulesInstance::EGameRulesInstanceType ownerType) { m_ownerType = ownerType;} + void setOwnerType(GameRulesInstance::EGameRulesInstanceType ownerType) { + m_ownerType = ownerType; + } - virtual void write(DataOutputStream *); + virtual void write(DataOutputStream*); - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); - virtual void getChildren(std::vector *); + virtual void writeAttributes(DataOutputStream* dos, + unsigned int numAttributes); + virtual void getChildren(std::vector*); - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); - - virtual void populateGameRule(GameRulesInstance::EGameRulesInstanceType type, GameRule *rule); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - bool getComplete(GameRule *rule); - void setComplete(GameRule *rule, bool val); + virtual void populateGameRule( + GameRulesInstance::EGameRulesInstanceType type, GameRule* rule); - virtual int getGoal() { return 0; } - virtual int getProgress(GameRule *rule) { return 0; } + bool getComplete(GameRule* rule); + void setComplete(GameRule* rule, bool val); - virtual int getIcon() { return -1; } - virtual int getAuxValue() { return 0; } + virtual int getGoal() { return 0; } + virtual int getProgress(GameRule* rule) { return 0; } - // Here we should have functions for all the hooks, with a GameRule* as the first parameter - virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z) { return false; } - virtual bool onCollectItem(GameRule *rule, std::shared_ptr item) { return false; } - virtual void postProcessPlayer(std::shared_ptr player) { } + virtual int getIcon() { return -1; } + virtual int getAuxValue() { return 0; } - std::vector *enumerate(); - std::unordered_map *enumerateMap(); + // Here we should have functions for all the hooks, with a GameRule* as the + // first parameter + virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z) { + return false; + } + virtual bool onCollectItem(GameRule* rule, + std::shared_ptr item) { + return false; + } + virtual void postProcessPlayer(std::shared_ptr player) {} - // Static functions - static GameRulesInstance *generateNewGameRulesInstance(GameRulesInstance::EGameRulesInstanceType type, LevelRuleset *rules, Connection *connection); - static std::wstring generateDescriptionString(ConsoleGameRules::EGameRuleType defType, const std::wstring &description, void *data = NULL, int dataLength = 0); + std::vector* enumerate(); + std::unordered_map* enumerateMap(); + // Static functions + static GameRulesInstance* generateNewGameRulesInstance( + GameRulesInstance::EGameRulesInstanceType type, LevelRuleset* rules, + Connection* connection); + static std::wstring generateDescriptionString( + ConsoleGameRules::EGameRuleType defType, + const std::wstring& description, void* data = NULL, int dataLength = 0); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.cpp b/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.cpp index 4f9134908..8acdd2b1b 100644 --- a/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.cpp @@ -12,788 +12,782 @@ #include "ConsoleGameRules.h" #include "GameRuleManager.h" -const WCHAR *GameRuleManager::wchTagNameA[] = -{ - L"", // eGameRuleType_Root - L"MapOptions", // eGameRuleType_LevelGenerationOptions - L"ApplySchematic", // eGameRuleType_ApplySchematic - L"GenerateStructure", // eGameRuleType_GenerateStructure - L"GenerateBox", // eGameRuleType_GenerateBox - L"PlaceBlock", // eGameRuleType_PlaceBlock - L"PlaceContainer", // eGameRuleType_PlaceContainer - L"PlaceSpawner", // eGameRuleType_PlaceSpawner - L"BiomeOverride", // eGameRuleType_BiomeOverride - L"StartFeature", // eGameRuleType_StartFeature - L"AddItem", // eGameRuleType_AddItem - L"AddEnchantment", // eGameRuleType_AddEnchantment - L"LevelRules", // eGameRuleType_LevelRules - L"NamedArea", // eGameRuleType_NamedArea - L"UseTile", // eGameRuleType_UseTileRule - L"CollectItem", // eGameRuleType_CollectItemRule - L"CompleteAll", // eGameRuleType_CompleteAllRule - L"UpdatePlayer", // eGameRuleType_UpdatePlayerRule +const WCHAR* GameRuleManager::wchTagNameA[] = { + L"", // eGameRuleType_Root + L"MapOptions", // eGameRuleType_LevelGenerationOptions + L"ApplySchematic", // eGameRuleType_ApplySchematic + L"GenerateStructure", // eGameRuleType_GenerateStructure + L"GenerateBox", // eGameRuleType_GenerateBox + L"PlaceBlock", // eGameRuleType_PlaceBlock + L"PlaceContainer", // eGameRuleType_PlaceContainer + L"PlaceSpawner", // eGameRuleType_PlaceSpawner + L"BiomeOverride", // eGameRuleType_BiomeOverride + L"StartFeature", // eGameRuleType_StartFeature + L"AddItem", // eGameRuleType_AddItem + L"AddEnchantment", // eGameRuleType_AddEnchantment + L"LevelRules", // eGameRuleType_LevelRules + L"NamedArea", // eGameRuleType_NamedArea + L"UseTile", // eGameRuleType_UseTileRule + L"CollectItem", // eGameRuleType_CollectItemRule + L"CompleteAll", // eGameRuleType_CompleteAllRule + L"UpdatePlayer", // eGameRuleType_UpdatePlayerRule }; -const WCHAR *GameRuleManager::wchAttrNameA[] = -{ - L"descriptionName", // eGameRuleAttr_descriptionName - L"promptName", // eGameRuleAttr_promptName - L"dataTag", // eGameRuleAttr_dataTag - L"enchantmentId", // eGameRuleAttr_enchantmentId - L"enchantmentLevel", // eGameRuleAttr_enchantmentLevel - L"itemId", // eGameRuleAttr_itemId - L"quantity", // eGameRuleAttr_quantity - L"auxValue", // eGameRuleAttr_auxValue - L"slot", // eGameRuleAttr_slot - L"name", // eGameRuleAttr_name - L"food", // eGameRuleAttr_food - L"health", // eGameRuleAttr_health - L"tileId", // eGameRuleAttr_tileId - L"useCoords", // eGameRuleAttr_useCoords - L"seed", // eGameRuleAttr_seed - L"flatworld", // eGameRuleAttr_flatworld - L"filename", // eGameRuleAttr_filename - L"rot", // eGameRuleAttr_rot - L"data", // eGameRuleAttr_data - L"block", // eGameRuleAttr_block - L"entity", // eGameRuleAttr_entity - L"facing", // eGameRuleAttr_facing - L"edgeTile", // eGameRuleAttr_edgeTile - L"fillTile", // eGameRuleAttr_fillTile - L"skipAir", // eGameRuleAttr_skipAir - L"x", // eGameRuleAttr_x - L"x0", // eGameRuleAttr_x0 - L"x1", // eGameRuleAttr_x1 - L"y", // eGameRuleAttr_y - L"y0", // eGameRuleAttr_y0 - L"y1", // eGameRuleAttr_y1 - L"z", // eGameRuleAttr_z - L"z0", // eGameRuleAttr_z0 - L"z1", // eGameRuleAttr_z1 - L"chunkX", // eGameRuleAttr_chunkX - L"chunkZ", // eGameRuleAttr_chunkZ - L"yRot", // eGameRuleAttr_yRot - L"spawnX", // eGameRuleAttr_spawnX - L"spawnY", // eGameRuleAttr_spawnY - L"spawnZ", // eGameRuleAttr_spawnZ - L"orientation", - L"dimension", - L"topTileId", // eGameRuleAttr_topTileId - L"biomeId", // eGameRuleAttr_biomeId - L"feature", // eGameRuleAttr_feature +const WCHAR* GameRuleManager::wchAttrNameA[] = { + L"descriptionName", // eGameRuleAttr_descriptionName + L"promptName", // eGameRuleAttr_promptName + L"dataTag", // eGameRuleAttr_dataTag + L"enchantmentId", // eGameRuleAttr_enchantmentId + L"enchantmentLevel", // eGameRuleAttr_enchantmentLevel + L"itemId", // eGameRuleAttr_itemId + L"quantity", // eGameRuleAttr_quantity + L"auxValue", // eGameRuleAttr_auxValue + L"slot", // eGameRuleAttr_slot + L"name", // eGameRuleAttr_name + L"food", // eGameRuleAttr_food + L"health", // eGameRuleAttr_health + L"tileId", // eGameRuleAttr_tileId + L"useCoords", // eGameRuleAttr_useCoords + L"seed", // eGameRuleAttr_seed + L"flatworld", // eGameRuleAttr_flatworld + L"filename", // eGameRuleAttr_filename + L"rot", // eGameRuleAttr_rot + L"data", // eGameRuleAttr_data + L"block", // eGameRuleAttr_block + L"entity", // eGameRuleAttr_entity + L"facing", // eGameRuleAttr_facing + L"edgeTile", // eGameRuleAttr_edgeTile + L"fillTile", // eGameRuleAttr_fillTile + L"skipAir", // eGameRuleAttr_skipAir + L"x", // eGameRuleAttr_x + L"x0", // eGameRuleAttr_x0 + L"x1", // eGameRuleAttr_x1 + L"y", // eGameRuleAttr_y + L"y0", // eGameRuleAttr_y0 + L"y1", // eGameRuleAttr_y1 + L"z", // eGameRuleAttr_z + L"z0", // eGameRuleAttr_z0 + L"z1", // eGameRuleAttr_z1 + L"chunkX", // eGameRuleAttr_chunkX + L"chunkZ", // eGameRuleAttr_chunkZ + L"yRot", // eGameRuleAttr_yRot + L"spawnX", // eGameRuleAttr_spawnX + L"spawnY", // eGameRuleAttr_spawnY + L"spawnZ", // eGameRuleAttr_spawnZ + L"orientation", + L"dimension", + L"topTileId", // eGameRuleAttr_topTileId + L"biomeId", // eGameRuleAttr_biomeId + L"feature", // eGameRuleAttr_feature }; -GameRuleManager::GameRuleManager() -{ - m_currentGameRuleDefinitions = NULL; - m_currentLevelGenerationOptions = NULL; +GameRuleManager::GameRuleManager() { + m_currentGameRuleDefinitions = NULL; + m_currentLevelGenerationOptions = NULL; } -void GameRuleManager::loadGameRules(DLCPack *pack) -{ - StringTable *strings = NULL; +void GameRuleManager::loadGameRules(DLCPack* pack) { + StringTable* strings = NULL; - if(pack->doesPackContainFile(DLCManager::e_DLCType_LocalisationData,L"languages.loc")) - { - DLCLocalisationFile *localisationFile = (DLCLocalisationFile *)pack->getFile(DLCManager::e_DLCType_LocalisationData, L"languages.loc"); - strings = localisationFile->getStringTable(); - } + if (pack->doesPackContainFile(DLCManager::e_DLCType_LocalisationData, + L"languages.loc")) { + DLCLocalisationFile* localisationFile = + (DLCLocalisationFile*)pack->getFile( + DLCManager::e_DLCType_LocalisationData, L"languages.loc"); + strings = localisationFile->getStringTable(); + } - int gameRulesCount = pack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader); - for(int i = 0; i < gameRulesCount; ++i) - { - DLCGameRulesHeader *dlcHeader = (DLCGameRulesHeader *)pack->getFile(DLCManager::e_DLCType_GameRulesHeader, i); - std::uint32_t dSize; - uint8_t *dData = dlcHeader->getData(dSize); + int gameRulesCount = + pack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader); + for (int i = 0; i < gameRulesCount; ++i) { + DLCGameRulesHeader* dlcHeader = (DLCGameRulesHeader*)pack->getFile( + DLCManager::e_DLCType_GameRulesHeader, i); + std::uint32_t dSize; + uint8_t* dData = dlcHeader->getData(dSize); - LevelGenerationOptions *createdLevelGenerationOptions = new LevelGenerationOptions(); - // = loadGameRules(dData, dSize); //, strings); + LevelGenerationOptions* createdLevelGenerationOptions = + new LevelGenerationOptions(); + // = loadGameRules(dData, dSize); //, strings); - createdLevelGenerationOptions->setGrSource( dlcHeader ); + createdLevelGenerationOptions->setGrSource(dlcHeader); - readRuleFile(createdLevelGenerationOptions, dData, dSize, strings); + readRuleFile(createdLevelGenerationOptions, dData, dSize, strings); - createdLevelGenerationOptions->setSrc( LevelGenerationOptions::eSrc_fromDLC ); - + createdLevelGenerationOptions->setSrc( + LevelGenerationOptions::eSrc_fromDLC); - //createdLevelGenerationOptions->setSrc( LevelGenerationOptions::eSrc_fromDLC ); - dlcHeader->lgo = createdLevelGenerationOptions; - } + // createdLevelGenerationOptions->setSrc( + // LevelGenerationOptions::eSrc_fromDLC ); + dlcHeader->lgo = createdLevelGenerationOptions; + } - gameRulesCount = pack->getDLCItemsCount(DLCManager::e_DLCType_GameRules); - for (int i = 0; i < gameRulesCount; ++i) - { - DLCGameRulesFile *dlcFile = (DLCGameRulesFile *)pack->getFile(DLCManager::e_DLCType_GameRules, i); + gameRulesCount = pack->getDLCItemsCount(DLCManager::e_DLCType_GameRules); + for (int i = 0; i < gameRulesCount; ++i) { + DLCGameRulesFile* dlcFile = (DLCGameRulesFile*)pack->getFile( + DLCManager::e_DLCType_GameRules, i); - std::uint32_t dSize; - uint8_t *dData = dlcFile->getData(dSize); + std::uint32_t dSize; + uint8_t* dData = dlcFile->getData(dSize); - LevelGenerationOptions *createdLevelGenerationOptions = new LevelGenerationOptions(); - // = loadGameRules(dData, dSize); //, strings); - - createdLevelGenerationOptions->setGrSource( new JustGrSource() ); - readRuleFile(createdLevelGenerationOptions, dData, dSize, strings); + LevelGenerationOptions* createdLevelGenerationOptions = + new LevelGenerationOptions(); + // = loadGameRules(dData, dSize); //, strings); - createdLevelGenerationOptions->setSrc( LevelGenerationOptions::eSrc_tutorial ); - - //createdLevelGenerationOptions->set_DLCGameRulesFile( dlcFile ); + createdLevelGenerationOptions->setGrSource(new JustGrSource()); + readRuleFile(createdLevelGenerationOptions, dData, dSize, strings); - createdLevelGenerationOptions->setLoadedData(); - } + createdLevelGenerationOptions->setSrc( + LevelGenerationOptions::eSrc_tutorial); + + // createdLevelGenerationOptions->set_DLCGameRulesFile( dlcFile ); + + createdLevelGenerationOptions->setLoadedData(); + } } -LevelGenerationOptions *GameRuleManager::loadGameRules(uint8_t *dIn, unsigned int dSize) -{ - LevelGenerationOptions *lgo = new LevelGenerationOptions(); - lgo->setGrSource( new JustGrSource() ); - lgo->setSrc( LevelGenerationOptions::eSrc_fromSave ); - loadGameRules(lgo, dIn, dSize); - lgo->setLoadedData(); - return lgo; +LevelGenerationOptions* GameRuleManager::loadGameRules(uint8_t* dIn, + unsigned int dSize) { + LevelGenerationOptions* lgo = new LevelGenerationOptions(); + lgo->setGrSource(new JustGrSource()); + lgo->setSrc(LevelGenerationOptions::eSrc_fromSave); + loadGameRules(lgo, dIn, dSize); + lgo->setLoadedData(); + return lgo; } // 4J-JEV: Reverse of saveGameRules. -void GameRuleManager::loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize) -{ - app.DebugPrintf("GameRuleManager::LoadingGameRules:\n"); +void GameRuleManager::loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn, + unsigned int dSize) { + app.DebugPrintf("GameRuleManager::LoadingGameRules:\n"); - ByteArrayInputStream bais( byteArray(dIn,dSize) ); - DataInputStream dis(&bais); + ByteArrayInputStream bais(byteArray(dIn, dSize)); + DataInputStream dis(&bais); - // Read file header. + // Read file header. - //dis.readInt(); // File Size + // dis.readInt(); // File Size - short version = dis.readShort(); - assert( 0x1 == version ); - app.DebugPrintf("\tversion=%d.\n", version); + short version = dis.readShort(); + assert(0x1 == version); + app.DebugPrintf("\tversion=%d.\n", version); - for (int i = 0; i < 8; i++) dis.readByte(); - - std::uint8_t compression_type = dis.readByte(); + for (int i = 0; i < 8; i++) dis.readByte(); - app.DebugPrintf("\tcompressionType=%d.\n", compression_type); + std::uint8_t compression_type = dis.readByte(); - unsigned int compr_len, decomp_len; - compr_len = dis.readInt(); - decomp_len = dis.readInt(); + app.DebugPrintf("\tcompressionType=%d.\n", compression_type); - app.DebugPrintf("\tcompr_len=%d.\n\tdecomp_len=%d.\n", compr_len, decomp_len); - + unsigned int compr_len, decomp_len; + compr_len = dis.readInt(); + decomp_len = dis.readInt(); - // Decompress File Body + app.DebugPrintf("\tcompr_len=%d.\n\tdecomp_len=%d.\n", compr_len, + decomp_len); - byteArray content(new std::uint8_t[decomp_len], decomp_len), - compr_content(new std::uint8_t[compr_len], compr_len); - dis.read(compr_content); + // Decompress File Body - Compression::getCompression()->SetDecompressionType( (Compression::ECompressionTypes)compression_type ); - Compression::getCompression()->DecompressLZXRLE( content.data, &content.length, - compr_content.data, compr_content.length); - Compression::getCompression()->SetDecompressionType( SAVE_FILE_PLATFORM_LOCAL ); + byteArray content(new std::uint8_t[decomp_len], decomp_len), + compr_content(new std::uint8_t[compr_len], compr_len); + dis.read(compr_content); - dis.close(); - bais.close(); + Compression::getCompression()->SetDecompressionType( + (Compression::ECompressionTypes)compression_type); + Compression::getCompression()->DecompressLZXRLE( + content.data, &content.length, compr_content.data, + compr_content.length); + Compression::getCompression()->SetDecompressionType( + SAVE_FILE_PLATFORM_LOCAL); - delete [] compr_content.data; + dis.close(); + bais.close(); - ByteArrayInputStream bais2( content ); - DataInputStream dis2( &bais2 ); + delete[] compr_content.data; - // Read StringTable. - byteArray bStringTable; - bStringTable.length = dis2.readInt(); - bStringTable.data = new std::uint8_t[ bStringTable.length ]; - dis2.read(bStringTable); - StringTable *strings = new StringTable(bStringTable.data, bStringTable.length); + ByteArrayInputStream bais2(content); + DataInputStream dis2(&bais2); - // Read RuleFile. - byteArray bRuleFile; - bRuleFile.length = content.length - bStringTable.length; - bRuleFile.data = new std::uint8_t[ bRuleFile.length ]; - dis2.read(bRuleFile); + // Read StringTable. + byteArray bStringTable; + bStringTable.length = dis2.readInt(); + bStringTable.data = new std::uint8_t[bStringTable.length]; + dis2.read(bStringTable); + StringTable* strings = + new StringTable(bStringTable.data, bStringTable.length); - // 4J-JEV: I don't believe that the path-name is ever used. - //DLCGameRulesFile *dlcgr = new DLCGameRulesFile(L"__PLACEHOLDER__"); - //dlcgr->addData(bRuleFile.data,bRuleFile.length); + // Read RuleFile. + byteArray bRuleFile; + bRuleFile.length = content.length - bStringTable.length; + bRuleFile.data = new std::uint8_t[bRuleFile.length]; + dis2.read(bRuleFile); - if (readRuleFile(lgo, bRuleFile.data, bRuleFile.length, strings)) - { - // Set current gen options and ruleset. - //createdLevelGenerationOptions->setFromSaveGame(true); - lgo->setSrc(LevelGenerationOptions::eSrc_fromSave); - setLevelGenerationOptions( lgo ); - //m_currentGameRuleDefinitions = lgo->getRequiredGameRules(); - } - else - { - delete lgo; - } + // 4J-JEV: I don't believe that the path-name is ever used. + // DLCGameRulesFile *dlcgr = new DLCGameRulesFile(L"__PLACEHOLDER__"); + // dlcgr->addData(bRuleFile.data,bRuleFile.length); - //delete [] content.data; + if (readRuleFile(lgo, bRuleFile.data, bRuleFile.length, strings)) { + // Set current gen options and ruleset. + // createdLevelGenerationOptions->setFromSaveGame(true); + lgo->setSrc(LevelGenerationOptions::eSrc_fromSave); + setLevelGenerationOptions(lgo); + // m_currentGameRuleDefinitions = lgo->getRequiredGameRules(); + } else { + delete lgo; + } - // Close and return. - dis2.close(); - bais2.close(); + // delete [] content.data; - return ; + // Close and return. + dis2.close(); + bais2.close(); + + return; } // 4J-JEV: Reverse of loadGameRules. -void GameRuleManager::saveGameRules(uint8_t **dOut, unsigned int *dSize) -{ - if (m_currentGameRuleDefinitions == NULL && - m_currentLevelGenerationOptions == NULL) - { - app.DebugPrintf("GameRuleManager:: Nothing here to save."); - *dOut = NULL; - *dSize = 0; - return; - } +void GameRuleManager::saveGameRules(uint8_t** dOut, unsigned int* dSize) { + if (m_currentGameRuleDefinitions == NULL && + m_currentLevelGenerationOptions == NULL) { + app.DebugPrintf("GameRuleManager:: Nothing here to save."); + *dOut = NULL; + *dSize = 0; + return; + } - app.DebugPrintf("GameRuleManager::saveGameRules:\n"); + app.DebugPrintf("GameRuleManager::saveGameRules:\n"); - // Initialise output stream. - ByteArrayOutputStream baos; - DataOutputStream dos(&baos); - - // Write header. + // Initialise output stream. + ByteArrayOutputStream baos; + DataOutputStream dos(&baos); - // VERSION NUMBER - dos.writeShort( 0x1 ); // version_number + // Write header. - // Write 8 bytes of empty space in case we need them later. - // Mainly useful for the ones we save embedded in game saves. - for (unsigned int i = 0; i < 8; i++) - dos.writeByte(0x0); + // VERSION NUMBER + dos.writeShort(0x1); // version_number - dos.writeByte(APPROPRIATE_COMPRESSION_TYPE); // m_compressionType + // Write 8 bytes of empty space in case we need them later. + // Mainly useful for the ones we save embedded in game saves. + for (unsigned int i = 0; i < 8; i++) dos.writeByte(0x0); - // -- START COMPRESSED -- // - ByteArrayOutputStream compr_baos; - DataOutputStream compr_dos(&compr_baos); + dos.writeByte(APPROPRIATE_COMPRESSION_TYPE); // m_compressionType - if (m_currentGameRuleDefinitions == NULL) - { - compr_dos.writeInt( 0 ); // numStrings for StringTable - compr_dos.writeInt( version_number ); - compr_dos.writeByte(Compression::eCompressionType_None); // compression type - for (int i=0; i<2; i++) compr_dos.writeByte(0x0); // Padding. - compr_dos.writeInt( 0 ); // StringLookup.length - compr_dos.writeInt( 0 ); // SchematicFiles.length - compr_dos.writeInt( 0 ); // XmlObjects.length - } - else - { - StringTable *st = m_currentGameRuleDefinitions->getStringTable(); + // -- START COMPRESSED -- // + ByteArrayOutputStream compr_baos; + DataOutputStream compr_dos(&compr_baos); - if (st == NULL) - { - app.DebugPrintf("GameRuleManager::saveGameRules: StringTable == NULL!"); - } - else - { - // Write string table. - byteArray stba; - m_currentGameRuleDefinitions->getStringTable()->getData(&stba.data, &stba.length); - compr_dos.writeInt( stba.length ); - compr_dos.write( stba ); + if (m_currentGameRuleDefinitions == NULL) { + compr_dos.writeInt(0); // numStrings for StringTable + compr_dos.writeInt(version_number); + compr_dos.writeByte( + Compression::eCompressionType_None); // compression type + for (int i = 0; i < 2; i++) compr_dos.writeByte(0x0); // Padding. + compr_dos.writeInt(0); // StringLookup.length + compr_dos.writeInt(0); // SchematicFiles.length + compr_dos.writeInt(0); // XmlObjects.length + } else { + StringTable* st = m_currentGameRuleDefinitions->getStringTable(); - // Write game rule file to second - // buffer and generate string lookup. - writeRuleFile(&compr_dos); - } - } + if (st == NULL) { + app.DebugPrintf( + "GameRuleManager::saveGameRules: StringTable == NULL!"); + } else { + // Write string table. + byteArray stba; + m_currentGameRuleDefinitions->getStringTable()->getData( + &stba.data, &stba.length); + compr_dos.writeInt(stba.length); + compr_dos.write(stba); - // Compress compr_dos and write to dos. - byteArray compr_ba(new std::uint8_t[ compr_baos.buf.length ], compr_baos.buf.length); - Compression::getCompression()->CompressLZXRLE( compr_ba.data, &compr_ba.length, - compr_baos.buf.data, compr_baos.buf.length ); + // Write game rule file to second + // buffer and generate string lookup. + writeRuleFile(&compr_dos); + } + } - app.DebugPrintf("\tcompr_ba.length=%d.\n\tcompr_baos.buf.length=%d.\n", - compr_ba.length, compr_baos.buf.length ); + // Compress compr_dos and write to dos. + byteArray compr_ba(new std::uint8_t[compr_baos.buf.length], + compr_baos.buf.length); + Compression::getCompression()->CompressLZXRLE( + compr_ba.data, &compr_ba.length, compr_baos.buf.data, + compr_baos.buf.length); - dos.writeInt( compr_ba.length ); // Write length - dos.writeInt( compr_baos.buf.length ); - dos.write(compr_ba); - - delete [] compr_ba.data; - - compr_dos.close(); - compr_baos.close(); - // -- END COMPRESSED -- // + app.DebugPrintf("\tcompr_ba.length=%d.\n\tcompr_baos.buf.length=%d.\n", + compr_ba.length, compr_baos.buf.length); - // return - *dSize = baos.buf.length; - *dOut = baos.buf.data; + dos.writeInt(compr_ba.length); // Write length + dos.writeInt(compr_baos.buf.length); + dos.write(compr_ba); - baos.buf.data = NULL; - - dos.close(); baos.close(); + delete[] compr_ba.data; + + compr_dos.close(); + compr_baos.close(); + // -- END COMPRESSED -- // + + // return + *dSize = baos.buf.length; + *dOut = baos.buf.data; + + baos.buf.data = NULL; + + dos.close(); + baos.close(); } // 4J-JEV: Reverse of readRuleFile. -void GameRuleManager::writeRuleFile(DataOutputStream *dos) -{ - // Write Header - dos->writeShort(version_number); // Version number. - dos->writeByte(Compression::eCompressionType_None); // compression type - for (int i=0; i<8; i++) dos->writeBoolean(false); // Padding. +void GameRuleManager::writeRuleFile(DataOutputStream* dos) { + // Write Header + dos->writeShort(version_number); // Version number. + dos->writeByte(Compression::eCompressionType_None); // compression type + for (int i = 0; i < 8; i++) dos->writeBoolean(false); // Padding. - // Write string lookup. - int numStrings = static_cast(ConsoleGameRules::eGameRuleType_Count) + - static_cast(ConsoleGameRules::eGameRuleAttr_Count); - dos->writeInt(numStrings); - for (int i = 0; i < ConsoleGameRules::eGameRuleType_Count; i++) dos->writeUTF( wchTagNameA[i] ); - for (int i = 0; i < ConsoleGameRules::eGameRuleAttr_Count; i++) dos->writeUTF( wchAttrNameA[i] ); + // Write string lookup. + int numStrings = static_cast(ConsoleGameRules::eGameRuleType_Count) + + static_cast(ConsoleGameRules::eGameRuleAttr_Count); + dos->writeInt(numStrings); + for (int i = 0; i < ConsoleGameRules::eGameRuleType_Count; i++) + dos->writeUTF(wchTagNameA[i]); + for (int i = 0; i < ConsoleGameRules::eGameRuleAttr_Count; i++) + dos->writeUTF(wchAttrNameA[i]); - // Write schematic files. - std::unordered_map *files; - files = getLevelGenerationOptions()->getUnfinishedSchematicFiles(); - dos->writeInt( files->size() ); - for (AUTO_VAR(it, files->begin()); it != files->end(); it++) - { - std::wstring filename = it->first; - ConsoleSchematicFile *file = it->second; + // Write schematic files. + std::unordered_map* files; + files = getLevelGenerationOptions()->getUnfinishedSchematicFiles(); + dos->writeInt(files->size()); + for (AUTO_VAR(it, files->begin()); it != files->end(); it++) { + std::wstring filename = it->first; + ConsoleSchematicFile* file = it->second; - ByteArrayOutputStream fileBaos; - DataOutputStream fileDos(&fileBaos); - file->save(&fileDos); + ByteArrayOutputStream fileBaos; + DataOutputStream fileDos(&fileBaos); + file->save(&fileDos); - dos->writeUTF(filename); - //dos->writeInt(file->m_data.length); - dos->writeInt(fileBaos.buf.length); - dos->write((byteArray)fileBaos.buf); + dos->writeUTF(filename); + // dos->writeInt(file->m_data.length); + dos->writeInt(fileBaos.buf.length); + dos->write((byteArray)fileBaos.buf); - fileDos.close(); fileBaos.close(); - } + fileDos.close(); + fileBaos.close(); + } - // Write xml objects. - dos->writeInt( 2 ); // numChildren - m_currentLevelGenerationOptions->write(dos); - m_currentGameRuleDefinitions->write(dos); + // Write xml objects. + dos->writeInt(2); // numChildren + m_currentLevelGenerationOptions->write(dos); + m_currentGameRuleDefinitions->write(dos); } -bool GameRuleManager::readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize, StringTable *strings) //(DLCGameRulesFile *dlcFile, StringTable *strings) +bool GameRuleManager::readRuleFile( + LevelGenerationOptions* lgo, uint8_t* dIn, unsigned int dSize, + StringTable* strings) //(DLCGameRulesFile *dlcFile, StringTable *strings) { - bool levelGenAdded = false; - bool gameRulesAdded = false; - LevelGenerationOptions *levelGenerator = lgo;//new LevelGenerationOptions(); - LevelRuleset *gameRules = new LevelRuleset(); + bool levelGenAdded = false; + bool gameRulesAdded = false; + LevelGenerationOptions* levelGenerator = + lgo; // new LevelGenerationOptions(); + LevelRuleset* gameRules = new LevelRuleset(); - //std::uint32_t dataLength = 0; - //std::uint8_t *data = dlcFile->getData(dataLength); - //byteArray data(pbData,dwLen); - - byteArray data(dIn, dSize); - ByteArrayInputStream bais(data); - DataInputStream dis(&bais); + // std::uint32_t dataLength = 0; + // std::uint8_t *data = dlcFile->getData(dataLength); + // byteArray data(pbData,dwLen); - // Read File. + byteArray data(dIn, dSize); + ByteArrayInputStream bais(data); + DataInputStream dis(&bais); - // version_number - __int64 version = dis.readShort(); - unsigned char compressionType = 0; - if(version == 0) - { - for (int i = 0; i < 14; i++) dis.readByte(); // Read padding. - } - else - { - compressionType = dis.readByte(); + // Read File. - // Read the spare bytes we inserted for future use - for(int i = 0; i < 8; ++i) dis.readBoolean(); - } + // version_number + __int64 version = dis.readShort(); + unsigned char compressionType = 0; + if (version == 0) { + for (int i = 0; i < 14; i++) dis.readByte(); // Read padding. + } else { + compressionType = dis.readByte(); - ByteArrayInputStream *contentBais = NULL; - DataInputStream *contentDis = NULL; + // Read the spare bytes we inserted for future use + for (int i = 0; i < 8; ++i) dis.readBoolean(); + } - if(compressionType == Compression::eCompressionType_None) - { - // No compression - // No need to read buffer size, as we can read the stream as it is; - app.DebugPrintf("De-compressing game rules with: None\n"); - contentDis = &dis; - } - else - { - unsigned int uncompressedSize = dis.readInt(); - unsigned int compressedSize = dis.readInt(); - byteArray compressedBuffer(compressedSize); - dis.read(compressedBuffer); + ByteArrayInputStream* contentBais = NULL; + DataInputStream* contentDis = NULL; - byteArray decompressedBuffer = byteArray(uncompressedSize); + if (compressionType == Compression::eCompressionType_None) { + // No compression + // No need to read buffer size, as we can read the stream as it is; + app.DebugPrintf("De-compressing game rules with: None\n"); + contentDis = &dis; + } else { + unsigned int uncompressedSize = dis.readInt(); + unsigned int compressedSize = dis.readInt(); + byteArray compressedBuffer(compressedSize); + dis.read(compressedBuffer); - switch(compressionType) - { - case Compression::eCompressionType_None: - memcpy(decompressedBuffer.data, compressedBuffer.data, uncompressedSize); - break; + byteArray decompressedBuffer = byteArray(uncompressedSize); - case Compression::eCompressionType_RLE: - app.DebugPrintf("De-compressing game rules with: RLE\n"); - Compression::getCompression()->Decompress( decompressedBuffer.data, &decompressedBuffer.length, compressedBuffer.data, compressedSize); - break; + switch (compressionType) { + case Compression::eCompressionType_None: + memcpy(decompressedBuffer.data, compressedBuffer.data, + uncompressedSize); + break; - default: - app.DebugPrintf("De-compressing game rules."); + case Compression::eCompressionType_RLE: + app.DebugPrintf("De-compressing game rules with: RLE\n"); + Compression::getCompression()->Decompress( + decompressedBuffer.data, &decompressedBuffer.length, + compressedBuffer.data, compressedSize); + break; + + default: + app.DebugPrintf("De-compressing game rules."); #ifndef _CONTENT_PACKAGE - assert( compressionType == APPROPRIATE_COMPRESSION_TYPE ); + assert(compressionType == APPROPRIATE_COMPRESSION_TYPE); #endif - // 4J-JEV: DecompressLZXRLE uses the correct platform specific compression type. (need to assert that the data is compressed with it though). - Compression::getCompression()->DecompressLZXRLE(decompressedBuffer.data, &decompressedBuffer.length, compressedBuffer.data, compressedSize); - break; -/* 4J-JEV: - Each platform has only 1 method of compression, 'compression.h' file deals with it. + // 4J-JEV: DecompressLZXRLE uses the correct platform specific + // compression type. (need to assert that the data is compressed + // with it though). + Compression::getCompression()->DecompressLZXRLE( + decompressedBuffer.data, &decompressedBuffer.length, + compressedBuffer.data, compressedSize); + break; + /* 4J-JEV: + Each platform has only 1 method of compression, + 'compression.h' file deals with it. - case Compression::eCompressionType_LZXRLE: - app.DebugPrintf("De-compressing game rules with: LZX+RLE\n"); - Compression::getCompression()->DecompressLZXRLE( decompressedBuffer.data, &uncompressedSize, compressedBuffer.data, compressedSize); - break; - default: - app.DebugPrintf("Invalid compression type %d found\n", compressionType); - __debugbreak(); + case Compression::eCompressionType_LZXRLE: + app.DebugPrintf("De-compressing game + rules with: LZX+RLE\n"); + Compression::getCompression()->DecompressLZXRLE( + decompressedBuffer.data, &uncompressedSize, + compressedBuffer.data, compressedSize); break; default: + app.DebugPrintf("Invalid compression + type %d found\n", compressionType); + __debugbreak(); - delete [] compressedBuffer.data; delete [] decompressedBuffer.data; - dis.close(); bais.reset(); + delete [] compressedBuffer.data; delete + [] decompressedBuffer.data; dis.close(); bais.reset(); - if(!gameRulesAdded) delete gameRules; - return false; - */ - }; + if(!gameRulesAdded) delete gameRules; + return false; + */ + }; - delete [] compressedBuffer.data; + delete[] compressedBuffer.data; - contentBais = new ByteArrayInputStream(decompressedBuffer); - contentDis = new DataInputStream(contentBais); - } + contentBais = new ByteArrayInputStream(decompressedBuffer); + contentDis = new DataInputStream(contentBais); + } - // string lookup. - unsigned int numStrings = contentDis->readInt(); - std::vector tagsAndAtts; - for (unsigned int i = 0; i < numStrings; i++) - tagsAndAtts.push_back( contentDis->readUTF() ); + // string lookup. + unsigned int numStrings = contentDis->readInt(); + std::vector tagsAndAtts; + for (unsigned int i = 0; i < numStrings; i++) + tagsAndAtts.push_back(contentDis->readUTF()); - std::unordered_map tagIdMap; - for(int type = (int)ConsoleGameRules::eGameRuleType_Root; type < (int)ConsoleGameRules::eGameRuleType_Count; ++type) - { - for(unsigned int i = 0; i < numStrings; ++i) - { - if(tagsAndAtts[i].compare(wchTagNameA[type]) == 0) - { - tagIdMap.insert( std::unordered_map::value_type(i, (ConsoleGameRules::EGameRuleType)type) ); - break; - } - } - } + std::unordered_map tagIdMap; + for (int type = (int)ConsoleGameRules::eGameRuleType_Root; + type < (int)ConsoleGameRules::eGameRuleType_Count; ++type) { + for (unsigned int i = 0; i < numStrings; ++i) { + if (tagsAndAtts[i].compare(wchTagNameA[type]) == 0) { + tagIdMap.insert( + std::unordered_map:: + value_type(i, (ConsoleGameRules::EGameRuleType)type)); + break; + } + } + } - // 4J-JEV: TODO: As yet unused. - /* - std::unordered_map attrIdMap; - for(int attr = (int)ConsoleGameRules::eGameRuleAttr_descriptionName; attr < (int)ConsoleGameRules::eGameRuleAttr_Count; ++attr) - { - for (unsigned int i = 0; i < numStrings; i++) - { - if (tagsAndAtts[i].compare(wchAttrNameA[attr]) == 0) - { - tagIdMap.insert( std::unordered_map::value_type(i , (ConsoleGameRules::EGameRuleAttr)attr) ); - break; - } - } - }*/ + // 4J-JEV: TODO: As yet unused. + /* + std::unordered_map attrIdMap; + for(int attr = (int)ConsoleGameRules::eGameRuleAttr_descriptionName; attr < + (int)ConsoleGameRules::eGameRuleAttr_Count; ++attr) + { + for (unsigned int i = 0; i < numStrings; i++) + { + if (tagsAndAtts[i].compare(wchAttrNameA[attr]) == 0) + { + tagIdMap.insert( std::unordered_map::value_type(i , + (ConsoleGameRules::EGameRuleAttr)attr) ); break; + } + } + }*/ - // subfile - unsigned int numFiles = contentDis->readInt(); - for (unsigned int i = 0; i < numFiles; i++) - { - std::wstring sFilename = contentDis->readUTF(); - int length = contentDis->readInt(); - byteArray ba( length ); + // subfile + unsigned int numFiles = contentDis->readInt(); + for (unsigned int i = 0; i < numFiles; i++) { + std::wstring sFilename = contentDis->readUTF(); + int length = contentDis->readInt(); + byteArray ba(length); - contentDis->read(ba); + contentDis->read(ba); - levelGenerator->loadSchematicFile(sFilename, ba.data, ba.length); + levelGenerator->loadSchematicFile(sFilename, ba.data, ba.length); + } - } + LEVEL_GEN_ID lgoID = LEVEL_GEN_ID_NULL; - LEVEL_GEN_ID lgoID = LEVEL_GEN_ID_NULL; + // xml objects + unsigned int numObjects = contentDis->readInt(); + for (unsigned int i = 0; i < numObjects; ++i) { + int tagId = contentDis->readInt(); + ConsoleGameRules::EGameRuleType tagVal = + ConsoleGameRules::eGameRuleType_Invalid; + AUTO_VAR(it, tagIdMap.find(tagId)); + if (it != tagIdMap.end()) tagVal = it->second; - // xml objects - unsigned int numObjects = contentDis->readInt(); - for(unsigned int i = 0; i < numObjects; ++i) - { - int tagId = contentDis->readInt(); - ConsoleGameRules::EGameRuleType tagVal = ConsoleGameRules::eGameRuleType_Invalid; - AUTO_VAR(it,tagIdMap.find(tagId)); - if(it != tagIdMap.end()) tagVal = it->second; + GameRuleDefinition* rule = NULL; - GameRuleDefinition *rule = NULL; + if (tagVal == ConsoleGameRules::eGameRuleType_LevelGenerationOptions) { + rule = levelGenerator; + levelGenAdded = true; + // m_levelGenerators.addLevelGenerator(L"",levelGenerator); + lgoID = addLevelGenerationOptions(levelGenerator); + levelGenerator->loadStringTable(strings); + } else if (tagVal == ConsoleGameRules::eGameRuleType_LevelRules) { + rule = gameRules; + gameRulesAdded = true; + m_levelRules.addLevelRule(L"", gameRules); + levelGenerator->setRequiredGameRules(gameRules); + gameRules->loadStringTable(strings); + } - if(tagVal == ConsoleGameRules::eGameRuleType_LevelGenerationOptions) - { - rule = levelGenerator; - levelGenAdded = true; - //m_levelGenerators.addLevelGenerator(L"",levelGenerator); - lgoID = addLevelGenerationOptions(levelGenerator); - levelGenerator->loadStringTable(strings); - } - else if(tagVal == ConsoleGameRules::eGameRuleType_LevelRules) - { - rule = gameRules; - gameRulesAdded = true; - m_levelRules.addLevelRule(L"",gameRules); - levelGenerator->setRequiredGameRules(gameRules); - gameRules->loadStringTable(strings); - } + readAttributes(contentDis, &tagsAndAtts, rule); + readChildren(contentDis, &tagsAndAtts, &tagIdMap, rule); + } - readAttributes(contentDis, &tagsAndAtts, rule); - readChildren(contentDis, &tagsAndAtts, &tagIdMap, rule); - } + if (compressionType != 0) { + // Not default + contentDis->close(); + if (contentBais != NULL) delete contentBais; + delete contentDis; + } - if(compressionType != 0) - { - // Not default - contentDis->close(); - if(contentBais != NULL) delete contentBais; - delete contentDis; - } + dis.close(); + bais.reset(); - dis.close(); - bais.reset(); + // if(!levelGenAdded) { delete levelGenerator; levelGenerator = NULL; } + if (!gameRulesAdded) delete gameRules; - //if(!levelGenAdded) { delete levelGenerator; levelGenerator = NULL; } - if(!gameRulesAdded) delete gameRules; - - return true; - //return levelGenerator; + return true; + // return levelGenerator; } -LevelGenerationOptions *GameRuleManager::readHeader(DLCGameRulesHeader *grh) -{ - LevelGenerationOptions *out = - new LevelGenerationOptions(); +LevelGenerationOptions* GameRuleManager::readHeader(DLCGameRulesHeader* grh) { + LevelGenerationOptions* out = new LevelGenerationOptions(); - - out->setSrc(LevelGenerationOptions::eSrc_fromDLC); - out->setGrSource(grh); - addLevelGenerationOptions(out); + out->setSrc(LevelGenerationOptions::eSrc_fromDLC); + out->setGrSource(grh); + addLevelGenerationOptions(out); - return out; + return out; } -void GameRuleManager::readAttributes(DataInputStream *dis, std::vector *tagsAndAtts, GameRuleDefinition *rule) -{ - int numAttrs = dis->readInt(); - for (unsigned int att = 0; att < static_cast(numAttrs); ++att) - { - int attID = dis->readInt(); - std::wstring value = dis->readUTF(); +void GameRuleManager::readAttributes(DataInputStream* dis, + std::vector* tagsAndAtts, + GameRuleDefinition* rule) { + int numAttrs = dis->readInt(); + for (unsigned int att = 0; att < static_cast(numAttrs); + ++att) { + int attID = dis->readInt(); + std::wstring value = dis->readUTF(); - if(rule != NULL) rule->addAttribute(tagsAndAtts->at(attID),value); - } + if (rule != NULL) rule->addAttribute(tagsAndAtts->at(attID), value); + } } -void GameRuleManager::readChildren(DataInputStream *dis, std::vector *tagsAndAtts, std::unordered_map *tagIdMap, GameRuleDefinition *rule) -{ - int numChildren = dis->readInt(); - for(unsigned int child = 0; child < static_cast(numChildren); ++child) - { - int tagId = dis->readInt(); - ConsoleGameRules::EGameRuleType tagVal = ConsoleGameRules::eGameRuleType_Invalid; - AUTO_VAR(it,tagIdMap->find(tagId)); - if(it != tagIdMap->end()) tagVal = it->second; +void GameRuleManager::readChildren( + DataInputStream* dis, std::vector* tagsAndAtts, + std::unordered_map* tagIdMap, + GameRuleDefinition* rule) { + int numChildren = dis->readInt(); + for (unsigned int child = 0; child < static_cast(numChildren); + ++child) { + int tagId = dis->readInt(); + ConsoleGameRules::EGameRuleType tagVal = + ConsoleGameRules::eGameRuleType_Invalid; + AUTO_VAR(it, tagIdMap->find(tagId)); + if (it != tagIdMap->end()) tagVal = it->second; - GameRuleDefinition *childRule = NULL; - if(rule != NULL) childRule = rule->addChild(tagVal); + GameRuleDefinition* childRule = NULL; + if (rule != NULL) childRule = rule->addChild(tagVal); - readAttributes(dis,tagsAndAtts,childRule); - readChildren(dis,tagsAndAtts,tagIdMap,childRule); - } + readAttributes(dis, tagsAndAtts, childRule); + readChildren(dis, tagsAndAtts, tagIdMap, childRule); + } } -void GameRuleManager::processSchematics(LevelChunk *levelChunk) -{ - if(getLevelGenerationOptions() != NULL) - { - LevelGenerationOptions *levelGenOptions = getLevelGenerationOptions(); - levelGenOptions->processSchematics(levelChunk); - } +void GameRuleManager::processSchematics(LevelChunk* levelChunk) { + if (getLevelGenerationOptions() != NULL) { + LevelGenerationOptions* levelGenOptions = getLevelGenerationOptions(); + levelGenOptions->processSchematics(levelChunk); + } } -void GameRuleManager::processSchematicsLighting(LevelChunk *levelChunk) -{ - if(getLevelGenerationOptions() != NULL) - { - LevelGenerationOptions *levelGenOptions = getLevelGenerationOptions(); - levelGenOptions->processSchematicsLighting(levelChunk); - } +void GameRuleManager::processSchematicsLighting(LevelChunk* levelChunk) { + if (getLevelGenerationOptions() != NULL) { + LevelGenerationOptions* levelGenOptions = getLevelGenerationOptions(); + levelGenOptions->processSchematicsLighting(levelChunk); + } } -void GameRuleManager::loadDefaultGameRules() -{ +void GameRuleManager::loadDefaultGameRules() { #ifdef _XBOX #ifdef _TU_BUILD - std::wstring fileRoot = L"UPDATE:\\res\\GameRules\\Tutorial.pck"; + std::wstring fileRoot = L"UPDATE:\\res\\GameRules\\Tutorial.pck"; #else - std::wstring fileRoot = L"GAME:\\res\\TitleUpdate\\GameRules\\Tutorial.pck"; + std::wstring fileRoot = L"GAME:\\res\\TitleUpdate\\GameRules\\Tutorial.pck"; #endif - File packedTutorialFile(fileRoot); - if(loadGameRulesPack(&packedTutorialFile)) - { - m_levelGenerators.getLevelGenerators()->at(0)->setWorldName(app.GetString(IDS_PLAY_TUTORIAL)); - //m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(L"Tutorial"); - m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME)); - } + File packedTutorialFile(fileRoot); + if (loadGameRulesPack(&packedTutorialFile)) { + m_levelGenerators.getLevelGenerators()->at(0)->setWorldName( + app.GetString(IDS_PLAY_TUTORIAL)); + // m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(L"Tutorial"); + m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName( + app.GetString(IDS_TUTORIALSAVENAME)); + } #ifndef _CONTENT_PACKAGE - // 4J Stu - Remove these just now - //File testRulesPath(L"GAME:\\GameRules"); - //std::vector *packFiles = testRulesPath.listFiles(); + // 4J Stu - Remove these just now + // File testRulesPath(L"GAME:\\GameRules"); + // std::vector *packFiles = testRulesPath.listFiles(); - //for(AUTO_VAR(it,packFiles->begin()); it != packFiles->end(); ++it) - //{ - // loadGameRulesPack(*it); - //} - //delete packFiles; + // for(AUTO_VAR(it,packFiles->begin()); it != packFiles->end(); ++it) + //{ + // loadGameRulesPack(*it); + // } + // delete packFiles; #endif -#else // _XBOX +#else // _XBOX - std::wstring fpTutorial = L"Tutorial.pck"; - if(app.getArchiveFileSize(fpTutorial) >= 0) - { - DLCPack *pack = new DLCPack(L"",0xffffffff); - unsigned int dwFilesProcessed = 0; - if ( app.m_dlcManager.readDLCDataFile(dwFilesProcessed,fpTutorial,pack,true) ) - { - app.m_dlcManager.addPack(pack); - if (!m_levelGenerators.getLevelGenerators()->empty()) - { - m_levelGenerators.getLevelGenerators()->at(0)->setWorldName(app.GetString(IDS_PLAY_TUTORIAL)); - m_levelGenerators.getLevelGenerators()->at(0)->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME)); - } - else - { - app.DebugPrintf("loadDefaultGameRules: Tutorial.pck parsed OK but no level generators were added (missing GameRules/LevelGenerationOptions tag?)\n"); - } - } - else - { - app.DebugPrintf("loadDefaultGameRules: readDLCDataFile failed for Tutorial.pck (version too old, IO error, or DLC_TYPE_GameRules not found)\n"); - delete pack; - } - } - else - { - app.DebugPrintf("loadDefaultGameRules: Tutorial.pck not found in archive\n"); - } + std::wstring fpTutorial = L"Tutorial.pck"; + if (app.getArchiveFileSize(fpTutorial) >= 0) { + DLCPack* pack = new DLCPack(L"", 0xffffffff); + unsigned int dwFilesProcessed = 0; + if (app.m_dlcManager.readDLCDataFile(dwFilesProcessed, fpTutorial, pack, + true)) { + app.m_dlcManager.addPack(pack); + if (!m_levelGenerators.getLevelGenerators()->empty()) { + m_levelGenerators.getLevelGenerators()->at(0)->setWorldName( + app.GetString(IDS_PLAY_TUTORIAL)); + m_levelGenerators.getLevelGenerators() + ->at(0) + ->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME)); + } else { + app.DebugPrintf( + "loadDefaultGameRules: Tutorial.pck parsed OK but no level " + "generators were added (missing " + "GameRules/LevelGenerationOptions tag?)\n"); + } + } else { + app.DebugPrintf( + "loadDefaultGameRules: readDLCDataFile failed for Tutorial.pck " + "(version too old, IO error, or DLC_TYPE_GameRules not " + "found)\n"); + delete pack; + } + } else { + app.DebugPrintf( + "loadDefaultGameRules: Tutorial.pck not found in archive\n"); + } - // Linux/PC port fallback: if Tutorial.pck parsing didn't populate level generators - // (e.g. DLC version mismatch, missing GameRules tag), create a minimal placeholder so - // the game doesn't crash with vector::at(0) in LoadTrial(). - if (m_levelGenerators.getLevelGenerators()->empty()) - { - app.DebugPrintf("loadDefaultGameRules: creating minimal fallback LevelGenerationOptions\n"); - LevelGenerationOptions *lgo = new LevelGenerationOptions(); - lgo->setGrSource(new JustGrSource()); - lgo->setSrc(LevelGenerationOptions::eSrc_tutorial); - lgo->setWorldName(app.GetString(IDS_PLAY_TUTORIAL)); - lgo->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME)); - lgo->setLoadedData(); - addLevelGenerationOptions(lgo); - } + // Linux/PC port fallback: if Tutorial.pck parsing didn't populate level + // generators (e.g. DLC version mismatch, missing GameRules tag), create a + // minimal placeholder so the game doesn't crash with vector::at(0) in + // LoadTrial(). + if (m_levelGenerators.getLevelGenerators()->empty()) { + app.DebugPrintf( + "loadDefaultGameRules: creating minimal fallback " + "LevelGenerationOptions\n"); + LevelGenerationOptions* lgo = new LevelGenerationOptions(); + lgo->setGrSource(new JustGrSource()); + lgo->setSrc(LevelGenerationOptions::eSrc_tutorial); + lgo->setWorldName(app.GetString(IDS_PLAY_TUTORIAL)); + lgo->setDefaultSaveName(app.GetString(IDS_TUTORIALSAVENAME)); + lgo->setLoadedData(); + addLevelGenerationOptions(lgo); + } - /*StringTable *strings = new StringTable(baStrings.data, baStrings.length); - LevelGenerationOptions *lgo = new LevelGenerationOptions(); - lgo->setGrSource( new JustGrSource() ); - lgo->setSrc( LevelGenerationOptions::eSrc_tutorial ); - readRuleFile(lgo, tutorial.data, tutorial.length, strings); - lgo->setLoadedData();*/ + /*StringTable *strings = new StringTable(baStrings.data, baStrings.length); + LevelGenerationOptions *lgo = new LevelGenerationOptions(); + lgo->setGrSource( new JustGrSource() ); + lgo->setSrc( LevelGenerationOptions::eSrc_tutorial ); + readRuleFile(lgo, tutorial.data, tutorial.length, strings); + lgo->setLoadedData();*/ #endif } -bool GameRuleManager::loadGameRulesPack(File *path) -{ - bool success = false; +bool GameRuleManager::loadGameRulesPack(File* path) { + bool success = false; #ifdef _XBOX - if(path->exists()) - { - DLCPack *pack = new DLCPack(L"",0xffffffff); - unsigned int dwFilesProcessed = 0; - if( app.m_dlcManager.readDLCDataFile(dwFilesProcessed, path->getPath(),pack)) - { - app.m_dlcManager.addPack(pack); - success = true; - } - else - { - delete pack; - } - } + if (path->exists()) { + DLCPack* pack = new DLCPack(L"", 0xffffffff); + unsigned int dwFilesProcessed = 0; + if (app.m_dlcManager.readDLCDataFile(dwFilesProcessed, path->getPath(), + pack)) { + app.m_dlcManager.addPack(pack); + success = true; + } else { + delete pack; + } + } #endif - return success; + return success; } -void GameRuleManager::setLevelGenerationOptions(LevelGenerationOptions *levelGen) -{ - m_currentGameRuleDefinitions = NULL; - m_currentLevelGenerationOptions = levelGen; +void GameRuleManager::setLevelGenerationOptions( + LevelGenerationOptions* levelGen) { + m_currentGameRuleDefinitions = NULL; + m_currentLevelGenerationOptions = levelGen; - if(m_currentLevelGenerationOptions != NULL && m_currentLevelGenerationOptions->requiresGameRules() ) - { - m_currentGameRuleDefinitions = m_currentLevelGenerationOptions->getRequiredGameRules(); - } + if (m_currentLevelGenerationOptions != NULL && + m_currentLevelGenerationOptions->requiresGameRules()) { + m_currentGameRuleDefinitions = + m_currentLevelGenerationOptions->getRequiredGameRules(); + } - if(m_currentLevelGenerationOptions != NULL) - m_currentLevelGenerationOptions->reset_start(); + if (m_currentLevelGenerationOptions != NULL) + m_currentLevelGenerationOptions->reset_start(); } -const wchar_t *GameRuleManager::GetGameRulesString(const std::wstring &key) -{ - if(m_currentGameRuleDefinitions != NULL && !key.empty() ) - { - return m_currentGameRuleDefinitions->getString(key); - } - else - { - return L""; - } +const wchar_t* GameRuleManager::GetGameRulesString(const std::wstring& key) { + if (m_currentGameRuleDefinitions != NULL && !key.empty()) { + return m_currentGameRuleDefinitions->getString(key); + } else { + return L""; + } } -LEVEL_GEN_ID GameRuleManager::addLevelGenerationOptions(LevelGenerationOptions *lgo) -{ - std::vector *lgs = m_levelGenerators.getLevelGenerators(); - - for (int i = 0; isize(); i++) - if (lgs->at(i) == lgo) - return i; +LEVEL_GEN_ID GameRuleManager::addLevelGenerationOptions( + LevelGenerationOptions* lgo) { + std::vector* lgs = + m_levelGenerators.getLevelGenerators(); - lgs->push_back(lgo); - return lgs->size() - 1; + for (int i = 0; i < lgs->size(); i++) + if (lgs->at(i) == lgo) return i; + + lgs->push_back(lgo); + return lgs->size() - 1; } -void GameRuleManager::unloadCurrentGameRules() -{ - if (m_currentLevelGenerationOptions != NULL) - { - if (m_currentGameRuleDefinitions != NULL - && m_currentLevelGenerationOptions->isFromSave()) - m_levelRules.removeLevelRule( m_currentGameRuleDefinitions ); +void GameRuleManager::unloadCurrentGameRules() { + if (m_currentLevelGenerationOptions != NULL) { + if (m_currentGameRuleDefinitions != NULL && + m_currentLevelGenerationOptions->isFromSave()) + m_levelRules.removeLevelRule(m_currentGameRuleDefinitions); - if (m_currentLevelGenerationOptions->isFromSave()) - { - m_levelGenerators.removeLevelGenerator( m_currentLevelGenerationOptions ); - - delete m_currentLevelGenerationOptions; - } - else if (m_currentLevelGenerationOptions->isFromDLC()) - { - m_currentLevelGenerationOptions->reset_finish(); - } - } + if (m_currentLevelGenerationOptions->isFromSave()) { + m_levelGenerators.removeLevelGenerator( + m_currentLevelGenerationOptions); - m_currentGameRuleDefinitions = NULL; - m_currentLevelGenerationOptions = NULL; + delete m_currentLevelGenerationOptions; + } else if (m_currentLevelGenerationOptions->isFromDLC()) { + m_currentLevelGenerationOptions->reset_finish(); + } + } + + m_currentGameRuleDefinitions = NULL; + m_currentLevelGenerationOptions = NULL; } diff --git a/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.h b/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.h index 95a0dbf4d..76a6c5fa7 100644 --- a/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.h +++ b/Minecraft.Client/Platform/Common/GameRules/GameRuleManager.h @@ -17,64 +17,78 @@ class WstringLookup; #define GAME_RULE_SAVENAME L"requiredGameRules.grf" -// 4J-JEV: +// 4J-JEV: #define LEVEL_GEN_ID int #define LEVEL_GEN_ID_NULL 0 -class GameRuleManager -{ +class GameRuleManager { public: - static const WCHAR *wchTagNameA[ConsoleGameRules::eGameRuleType_Count]; - static const WCHAR *wchAttrNameA[ConsoleGameRules::eGameRuleAttr_Count]; + static const WCHAR* wchTagNameA[ConsoleGameRules::eGameRuleType_Count]; + static const WCHAR* wchAttrNameA[ConsoleGameRules::eGameRuleAttr_Count]; - static const short version_number = 2; + static const short version_number = 2; private: - LevelGenerationOptions *m_currentLevelGenerationOptions; - LevelRuleset *m_currentGameRuleDefinitions; - LevelGenerators m_levelGenerators; - LevelRules m_levelRules; + LevelGenerationOptions* m_currentLevelGenerationOptions; + LevelRuleset* m_currentGameRuleDefinitions; + LevelGenerators m_levelGenerators; + LevelRules m_levelRules; public: - GameRuleManager(); + GameRuleManager(); - void loadGameRules(DLCPack *); + void loadGameRules(DLCPack*); - LevelGenerationOptions *loadGameRules(uint8_t *dIn, unsigned int dSize); - void loadGameRules(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize); + LevelGenerationOptions* loadGameRules(uint8_t* dIn, unsigned int dSize); + void loadGameRules(LevelGenerationOptions* lgo, uint8_t* dIn, + unsigned int dSize); - void saveGameRules(uint8_t **dOut, unsigned int *dSize); + void saveGameRules(uint8_t** dOut, unsigned int* dSize); private: - LevelGenerationOptions *readHeader(DLCGameRulesHeader *grh); + LevelGenerationOptions* readHeader(DLCGameRulesHeader* grh); - void writeRuleFile(DataOutputStream *dos); + void writeRuleFile(DataOutputStream* dos); public: - bool readRuleFile(LevelGenerationOptions *lgo, uint8_t *dIn, unsigned int dSize, StringTable *strings); //(DLCGameRulesFile *dlcFile, StringTable *strings); + bool readRuleFile(LevelGenerationOptions* lgo, uint8_t* dIn, + unsigned int dSize, + StringTable* strings); //(DLCGameRulesFile *dlcFile, + //StringTable *strings); private: - void readAttributes(DataInputStream *dis, std::vector *tagsAndAtts, GameRuleDefinition *rule); - void readChildren(DataInputStream *dis, std::vector *tagsAndAtts, std::unordered_map *tagIdMap, GameRuleDefinition *rule); + void readAttributes(DataInputStream* dis, + std::vector* tagsAndAtts, + GameRuleDefinition* rule); + void readChildren( + DataInputStream* dis, std::vector* tagsAndAtts, + std::unordered_map* tagIdMap, + GameRuleDefinition* rule); public: - void processSchematics(LevelChunk *levelChunk); - void processSchematicsLighting(LevelChunk *levelChunk); - void loadDefaultGameRules(); + void processSchematics(LevelChunk* levelChunk); + void processSchematicsLighting(LevelChunk* levelChunk); + void loadDefaultGameRules(); private: - bool loadGameRulesPack(File *path); + bool loadGameRulesPack(File* path); - LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions *); + LEVEL_GEN_ID addLevelGenerationOptions(LevelGenerationOptions*); public: - std::vector *getLevelGenerators() { return m_levelGenerators.getLevelGenerators(); } - void setLevelGenerationOptions(LevelGenerationOptions *levelGen); - LevelRuleset *getGameRuleDefinitions() { return m_currentGameRuleDefinitions; } - LevelGenerationOptions *getLevelGenerationOptions() { return m_currentLevelGenerationOptions; } - const wchar_t *GetGameRulesString(const std::wstring &key); + std::vector* getLevelGenerators() { + return m_levelGenerators.getLevelGenerators(); + } + void setLevelGenerationOptions(LevelGenerationOptions* levelGen); + LevelRuleset* getGameRuleDefinitions() { + return m_currentGameRuleDefinitions; + } + LevelGenerationOptions* getLevelGenerationOptions() { + return m_currentLevelGenerationOptions; + } + const wchar_t* GetGameRulesString(const std::wstring& key); - // 4J-JEV: - // Properly cleans-up and unloads the current set of gameRules. - void unloadCurrentGameRules(); + // 4J-JEV: + // Properly cleans-up and unloads the current set of gameRules. + void unloadCurrentGameRules(); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/GameRulesInstance.h b/Minecraft.Client/Platform/Common/GameRules/GameRulesInstance.h index c2c79547c..93f3e28cd 100644 --- a/Minecraft.Client/Platform/Common/GameRules/GameRulesInstance.h +++ b/Minecraft.Client/Platform/Common/GameRules/GameRulesInstance.h @@ -1,24 +1,24 @@ #pragma once -//using namespace std; +// using namespace std; #include #include "GameRule.h" class GameRuleDefinition; -// The game rule manager belongs to a player/server or other object, and maintains their current state for each of -// the rules that apply to them -class GameRulesInstance : public GameRule -{ +// The game rule manager belongs to a player/server or other object, and +// maintains their current state for each of the rules that apply to them +class GameRulesInstance : public GameRule { public: - // These types are used by the GameRuleDefinition to know which rules to add to this GameRulesInstance - enum EGameRulesInstanceType - { - eGameRulesInstanceType_ServerPlayer, - eGameRulesInstanceType_Server, - eGameRulesInstanceType_Count - }; + // These types are used by the GameRuleDefinition to know which rules to add + // to this GameRulesInstance + enum EGameRulesInstanceType { + eGameRulesInstanceType_ServerPlayer, + eGameRulesInstanceType_Server, + eGameRulesInstanceType_Count + }; public: - GameRulesInstance(GameRuleDefinition *definition, Connection *connection) : GameRule(definition,connection) {} - // Functions for all the hooks should go here + GameRulesInstance(GameRuleDefinition* definition, Connection* connection) + : GameRule(definition, connection) {} + // Functions for all the hooks should go here }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp index c3875f134..47b1f225a 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp @@ -11,465 +11,465 @@ #include "LevelGenerationOptions.h" #include "ConsoleGameRules.h" -JustGrSource::JustGrSource() -{ - m_displayName = L"Default_DisplayName"; - m_worldName= L"Default_WorldName"; - m_defaultSaveName = L"Default_DefaultSaveName"; - m_bRequiresTexturePack = false; - m_requiredTexturePackId = 0; - m_grfPath = L"__NO_GRF_PATH__"; - m_bRequiresBaseSave = false; +JustGrSource::JustGrSource() { + m_displayName = L"Default_DisplayName"; + m_worldName = L"Default_WorldName"; + m_defaultSaveName = L"Default_DefaultSaveName"; + m_bRequiresTexturePack = false; + m_requiredTexturePackId = 0; + m_grfPath = L"__NO_GRF_PATH__"; + m_bRequiresBaseSave = false; } -bool JustGrSource::requiresTexturePack() {return m_bRequiresTexturePack;} -std::uint32_t JustGrSource::getRequiredTexturePackId() {return m_requiredTexturePackId;} -std::wstring JustGrSource::getDefaultSaveName() {return m_defaultSaveName;} -const wchar_t *JustGrSource::getWorldName() {return m_worldName.c_str();} -const wchar_t *JustGrSource::getDisplayName() {return m_displayName.c_str();} -std::wstring JustGrSource::getGrfPath() {return m_grfPath;} +bool JustGrSource::requiresTexturePack() { return m_bRequiresTexturePack; } +std::uint32_t JustGrSource::getRequiredTexturePackId() { + return m_requiredTexturePackId; +} +std::wstring JustGrSource::getDefaultSaveName() { return m_defaultSaveName; } +const wchar_t* JustGrSource::getWorldName() { return m_worldName.c_str(); } +const wchar_t* JustGrSource::getDisplayName() { return m_displayName.c_str(); } +std::wstring JustGrSource::getGrfPath() { return m_grfPath; } bool JustGrSource::requiresBaseSave() { return m_bRequiresBaseSave; }; std::wstring JustGrSource::getBaseSavePath() { return m_baseSavePath; }; -void JustGrSource::setRequiresTexturePack(bool x) {m_bRequiresTexturePack = x;} -void JustGrSource::setRequiredTexturePackId(std::uint32_t x) {m_requiredTexturePackId = x;} -void JustGrSource::setDefaultSaveName(const std::wstring &x) {m_defaultSaveName = x;} -void JustGrSource::setWorldName(const std::wstring &x) {m_worldName = x;} -void JustGrSource::setDisplayName(const std::wstring &x) {m_displayName = x;} -void JustGrSource::setGrfPath(const std::wstring &x) {m_grfPath = x;} -void JustGrSource::setBaseSavePath(const std::wstring &x) { m_baseSavePath = x; m_bRequiresBaseSave = true; } +void JustGrSource::setRequiresTexturePack(bool x) { + m_bRequiresTexturePack = x; +} +void JustGrSource::setRequiredTexturePackId(std::uint32_t x) { + m_requiredTexturePackId = x; +} +void JustGrSource::setDefaultSaveName(const std::wstring& x) { + m_defaultSaveName = x; +} +void JustGrSource::setWorldName(const std::wstring& x) { m_worldName = x; } +void JustGrSource::setDisplayName(const std::wstring& x) { m_displayName = x; } +void JustGrSource::setGrfPath(const std::wstring& x) { m_grfPath = x; } +void JustGrSource::setBaseSavePath(const std::wstring& x) { + m_baseSavePath = x; + m_bRequiresBaseSave = true; +} bool JustGrSource::ready() { return true; } -LevelGenerationOptions::LevelGenerationOptions() -{ - m_spawnPos = NULL; - m_stringTable = NULL; +LevelGenerationOptions::LevelGenerationOptions() { + m_spawnPos = NULL; + m_stringTable = NULL; - m_hasLoadedData = false; + m_hasLoadedData = false; - m_seed = 0; - m_useFlatWorld = false; - m_bHaveMinY = false; - m_minY = INT_MAX; - m_bRequiresGameRules = false; + m_seed = 0; + m_useFlatWorld = false; + m_bHaveMinY = false; + m_minY = INT_MAX; + m_bRequiresGameRules = false; - m_pbBaseSaveData = NULL; - m_baseSaveSize = 0; + m_pbBaseSaveData = NULL; + m_baseSaveSize = 0; } -LevelGenerationOptions::~LevelGenerationOptions() -{ - clearSchematics(); - if(m_spawnPos != NULL) delete m_spawnPos; - for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); ++it) - { - delete *it; - } - for(AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); ++it) - { - delete *it; - } - - for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it) - { - delete *it; - } - - for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) - { - delete *it; - } - - if (m_stringTable) - if (!isTutorial()) - delete m_stringTable; +LevelGenerationOptions::~LevelGenerationOptions() { + clearSchematics(); + if (m_spawnPos != NULL) delete m_spawnPos; + for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); + ++it) { + delete *it; + } + for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); + ++it) { + delete *it; + } - if (isFromSave()) delete m_pSrc; + for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); + ++it) { + delete *it; + } + + for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) { + delete *it; + } + + if (m_stringTable) + if (!isTutorial()) delete m_stringTable; + + if (isFromSave()) delete m_pSrc; } -ConsoleGameRules::EGameRuleType LevelGenerationOptions::getActionType() { return ConsoleGameRules::eGameRuleType_LevelGenerationOptions; } - -void LevelGenerationOptions::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - GameRuleDefinition::writeAttributes(dos, numAttrs + 5); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX); - dos->writeUTF(_toString(m_spawnPos->x)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY); - dos->writeUTF(_toString(m_spawnPos->y)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ); - dos->writeUTF(_toString(m_spawnPos->z)); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_seed); - dos->writeUTF(_toString(m_seed)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_flatworld); - dos->writeUTF(_toString(m_useFlatWorld)); +ConsoleGameRules::EGameRuleType LevelGenerationOptions::getActionType() { + return ConsoleGameRules::eGameRuleType_LevelGenerationOptions; } -void LevelGenerationOptions::getChildren(std::vector *children) -{ - GameRuleDefinition::getChildren(children); - - std::vector used_schematics; - for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); it++) - if ( !(*it)->isComplete() ) - used_schematics.push_back( *it ); - - for(AUTO_VAR(it, m_structureRules.begin()); it!=m_structureRules.end(); it++) - children->push_back( *it ); - for(AUTO_VAR(it, used_schematics.begin()); it!=used_schematics.end(); it++) - children->push_back( *it ); - for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it) - children->push_back( *it ); - for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) - children->push_back( *it ); +void LevelGenerationOptions::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + GameRuleDefinition::writeAttributes(dos, numAttrs + 5); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX); + dos->writeUTF(_toString(m_spawnPos->x)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY); + dos->writeUTF(_toString(m_spawnPos->y)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ); + dos->writeUTF(_toString(m_spawnPos->z)); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_seed); + dos->writeUTF(_toString(m_seed)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_flatworld); + dos->writeUTF(_toString(m_useFlatWorld)); } -GameRuleDefinition *LevelGenerationOptions::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ - GameRuleDefinition *rule = NULL; - if(ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic) - { - rule = new ApplySchematicRuleDefinition(this); - m_schematicRules.push_back((ApplySchematicRuleDefinition *)rule); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure) - { - rule = new ConsoleGenerateStructure(); - m_structureRules.push_back((ConsoleGenerateStructure *)rule); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride) - { - rule = new BiomeOverride(); - m_biomeOverrides.push_back((BiomeOverride *)rule); - } - else if(ruleType == ConsoleGameRules::eGameRuleType_StartFeature) - { - rule = new StartFeature(); - m_features.push_back((StartFeature *)rule); - } - else - { +void LevelGenerationOptions::getChildren( + std::vector* children) { + GameRuleDefinition::getChildren(children); + + std::vector used_schematics; + for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); + it++) + if (!(*it)->isComplete()) used_schematics.push_back(*it); + + for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); + it++) + children->push_back(*it); + for (AUTO_VAR(it, used_schematics.begin()); it != used_schematics.end(); + it++) + children->push_back(*it); + for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); + ++it) + children->push_back(*it); + for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) + children->push_back(*it); +} + +GameRuleDefinition* LevelGenerationOptions::addChild( + ConsoleGameRules::EGameRuleType ruleType) { + GameRuleDefinition* rule = NULL; + if (ruleType == ConsoleGameRules::eGameRuleType_ApplySchematic) { + rule = new ApplySchematicRuleDefinition(this); + m_schematicRules.push_back((ApplySchematicRuleDefinition*)rule); + } else if (ruleType == ConsoleGameRules::eGameRuleType_GenerateStructure) { + rule = new ConsoleGenerateStructure(); + m_structureRules.push_back((ConsoleGenerateStructure*)rule); + } else if (ruleType == ConsoleGameRules::eGameRuleType_BiomeOverride) { + rule = new BiomeOverride(); + m_biomeOverrides.push_back((BiomeOverride*)rule); + } else if (ruleType == ConsoleGameRules::eGameRuleType_StartFeature) { + rule = new StartFeature(); + m_features.push_back((StartFeature*)rule); + } else { #ifndef _CONTENT_PACKAGE - wprintf(L"LevelGenerationOptions: Attempted to add invalid child rule - %d\n", ruleType ); + wprintf( + L"LevelGenerationOptions: Attempted to add invalid child rule - " + L"%d\n", + ruleType); #endif - } - return rule; + } + return rule; } -void LevelGenerationOptions::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"seed") == 0) - { - m_seed = _fromString<__int64>(attributeValue); - app.DebugPrintf("LevelGenerationOptions: Adding parameter m_seed=%I64d\n",m_seed); - } - else if(attributeName.compare(L"spawnX") == 0) - { - if(m_spawnPos == NULL) m_spawnPos = new Pos(); - int value = _fromString(attributeValue); - m_spawnPos->x = value; - app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n",value); - } - else if(attributeName.compare(L"spawnY") == 0) - { - if(m_spawnPos == NULL) m_spawnPos = new Pos(); - int value = _fromString(attributeValue); - m_spawnPos->y = value; - app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n",value); - } - else if(attributeName.compare(L"spawnZ") == 0) - { - if(m_spawnPos == NULL) m_spawnPos = new Pos(); - int value = _fromString(attributeValue); - m_spawnPos->z = value; - app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n",value); - } - else if(attributeName.compare(L"flatworld") == 0) - { - if(attributeValue.compare(L"true") == 0) m_useFlatWorld = true; - app.DebugPrintf("LevelGenerationOptions: Adding parameter flatworld=%s\n",m_useFlatWorld?"TRUE":"FALSE"); - } - else if(attributeName.compare(L"saveName") == 0) - { - std::wstring string(getString(attributeValue)); - if(!string.empty()) setDefaultSaveName( string ); - else setDefaultSaveName( attributeValue ); - app.DebugPrintf("LevelGenerationOptions: Adding parameter saveName=%ls\n", getDefaultSaveName().c_str()); - } - else if(attributeName.compare(L"worldName") == 0) - { - std::wstring string(getString(attributeValue)); - if(!string.empty()) setWorldName( string ); - else setWorldName( attributeValue ); - app.DebugPrintf("LevelGenerationOptions: Adding parameter worldName=%ls\n", getWorldName()); - } - else if(attributeName.compare(L"displayName") == 0) - { - std::wstring string(getString(attributeValue)); - if(!string.empty()) setDisplayName( string ); - else setDisplayName( attributeValue ); - app.DebugPrintf("LevelGenerationOptions: Adding parameter displayName=%ls\n", getDisplayName()); - } - else if(attributeName.compare(L"texturePackId") == 0) - { - setRequiredTexturePackId( _fromString(attributeValue) ); - setRequiresTexturePack( true ); - app.DebugPrintf("LevelGenerationOptions: Adding parameter texturePackId=%0x\n", getRequiredTexturePackId()); - } - else if(attributeName.compare(L"isTutorial") == 0) - { - if(attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial); - app.DebugPrintf("LevelGenerationOptions: Adding parameter isTutorial=%s\n",isTutorial()?"TRUE":"FALSE"); - } - else if(attributeName.compare(L"baseSaveName") == 0) - { - setBaseSavePath( attributeValue ); - app.DebugPrintf("LevelGenerationOptions: Adding parameter baseSaveName=%ls\n", getBaseSavePath().c_str()); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void LevelGenerationOptions::addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue) { + if (attributeName.compare(L"seed") == 0) { + m_seed = _fromString<__int64>(attributeValue); + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter m_seed=%I64d\n", m_seed); + } else if (attributeName.compare(L"spawnX") == 0) { + if (m_spawnPos == NULL) m_spawnPos = new Pos(); + int value = _fromString(attributeValue); + m_spawnPos->x = value; + app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnX=%d\n", + value); + } else if (attributeName.compare(L"spawnY") == 0) { + if (m_spawnPos == NULL) m_spawnPos = new Pos(); + int value = _fromString(attributeValue); + m_spawnPos->y = value; + app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnY=%d\n", + value); + } else if (attributeName.compare(L"spawnZ") == 0) { + if (m_spawnPos == NULL) m_spawnPos = new Pos(); + int value = _fromString(attributeValue); + m_spawnPos->z = value; + app.DebugPrintf("LevelGenerationOptions: Adding parameter spawnZ=%d\n", + value); + } else if (attributeName.compare(L"flatworld") == 0) { + if (attributeValue.compare(L"true") == 0) m_useFlatWorld = true; + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter flatworld=%s\n", + m_useFlatWorld ? "TRUE" : "FALSE"); + } else if (attributeName.compare(L"saveName") == 0) { + std::wstring string(getString(attributeValue)); + if (!string.empty()) + setDefaultSaveName(string); + else + setDefaultSaveName(attributeValue); + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter saveName=%ls\n", + getDefaultSaveName().c_str()); + } else if (attributeName.compare(L"worldName") == 0) { + std::wstring string(getString(attributeValue)); + if (!string.empty()) + setWorldName(string); + else + setWorldName(attributeValue); + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter worldName=%ls\n", + getWorldName()); + } else if (attributeName.compare(L"displayName") == 0) { + std::wstring string(getString(attributeValue)); + if (!string.empty()) + setDisplayName(string); + else + setDisplayName(attributeValue); + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter displayName=%ls\n", + getDisplayName()); + } else if (attributeName.compare(L"texturePackId") == 0) { + setRequiredTexturePackId(_fromString(attributeValue)); + setRequiresTexturePack(true); + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter texturePackId=%0x\n", + getRequiredTexturePackId()); + } else if (attributeName.compare(L"isTutorial") == 0) { + if (attributeValue.compare(L"true") == 0) setSrc(eSrc_tutorial); + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter isTutorial=%s\n", + isTutorial() ? "TRUE" : "FALSE"); + } else if (attributeName.compare(L"baseSaveName") == 0) { + setBaseSavePath(attributeValue); + app.DebugPrintf( + "LevelGenerationOptions: Adding parameter baseSaveName=%ls\n", + getBaseSavePath().c_str()); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -void LevelGenerationOptions::processSchematics(LevelChunk *chunk) -{ - PIXBeginNamedEvent(0,"Processing schematics for chunk (%d,%d)", chunk->x, chunk->z); - AABB *chunkBox = AABB::newTemp(chunk->x*16,0,chunk->z*16,chunk->x*16 + 16,Level::maxBuildHeight,chunk->z*16 + 16); - for( AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) - { - ApplySchematicRuleDefinition *rule = *it; - rule->processSchematic(chunkBox, chunk); - } +void LevelGenerationOptions::processSchematics(LevelChunk* chunk) { + PIXBeginNamedEvent(0, "Processing schematics for chunk (%d,%d)", chunk->x, + chunk->z); + AABB* chunkBox = + AABB::newTemp(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16, + Level::maxBuildHeight, chunk->z * 16 + 16); + for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); + ++it) { + ApplySchematicRuleDefinition* rule = *it; + rule->processSchematic(chunkBox, chunk); + } - // 4jcraft added cast to unsigned - int cx = ((unsigned)chunk->x << 4); - int cz = ((unsigned)chunk->z << 4); + // 4jcraft added cast to unsigned + int cx = ((unsigned)chunk->x << 4); + int cz = ((unsigned)chunk->z << 4); - for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ ) - { - ConsoleGenerateStructure *structureStart = *it; + for (AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); + it++) { + ConsoleGenerateStructure* structureStart = *it; - if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15, cz + 15)) - { - BoundingBox *bb = new BoundingBox(cx, cz, cx + 15, cz + 15); - structureStart->postProcess(chunk->level, NULL, bb); - delete bb; - } - } - PIXEndNamedEvent(); + if (structureStart->getBoundingBox()->intersects(cx, cz, cx + 15, + cz + 15)) { + BoundingBox* bb = new BoundingBox(cx, cz, cx + 15, cz + 15); + structureStart->postProcess(chunk->level, NULL, bb); + delete bb; + } + } + PIXEndNamedEvent(); } -void LevelGenerationOptions::processSchematicsLighting(LevelChunk *chunk) -{ - PIXBeginNamedEvent(0,"Processing schematics (lighting) for chunk (%d,%d)", chunk->x, chunk->z); - AABB *chunkBox = AABB::newTemp(chunk->x*16,0,chunk->z*16,chunk->x*16 + 16,Level::maxBuildHeight,chunk->z*16 + 16); - for( AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) - { - ApplySchematicRuleDefinition *rule = *it; - rule->processSchematicLighting(chunkBox, chunk); - } - PIXEndNamedEvent(); +void LevelGenerationOptions::processSchematicsLighting(LevelChunk* chunk) { + PIXBeginNamedEvent(0, "Processing schematics (lighting) for chunk (%d,%d)", + chunk->x, chunk->z); + AABB* chunkBox = + AABB::newTemp(chunk->x * 16, 0, chunk->z * 16, chunk->x * 16 + 16, + Level::maxBuildHeight, chunk->z * 16 + 16); + for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); + ++it) { + ApplySchematicRuleDefinition* rule = *it; + rule->processSchematicLighting(chunkBox, chunk); + } + PIXEndNamedEvent(); } -bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1) -{ - PIXBeginNamedEvent(0,"Check Intersects"); +bool LevelGenerationOptions::checkIntersects(int x0, int y0, int z0, int x1, + int y1, int z1) { + PIXBeginNamedEvent(0, "Check Intersects"); - // As an optimisation, we can quickly discard things below a certain y which makes most ore checks faster due to - // a) ores generally being below ground/sea level and b) tutorial world additions generally being above ground/sea level - if(!m_bHaveMinY) - { - for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) - { - ApplySchematicRuleDefinition *rule = *it; - int minY = rule->getMinY(); - if(minY < m_minY) m_minY = minY; - } + // As an optimisation, we can quickly discard things below a certain y which + // makes most ore checks faster due to a) ores generally being below + // ground/sea level and b) tutorial world additions generally being above + // ground/sea level + if (!m_bHaveMinY) { + for (AUTO_VAR(it, m_schematicRules.begin()); + it != m_schematicRules.end(); ++it) { + ApplySchematicRuleDefinition* rule = *it; + int minY = rule->getMinY(); + if (minY < m_minY) m_minY = minY; + } - for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ ) - { - ConsoleGenerateStructure *structureStart = *it; - int minY = structureStart->getMinY(); - if(minY < m_minY) m_minY = minY; - } + for (AUTO_VAR(it, m_structureRules.begin()); + it != m_structureRules.end(); it++) { + ConsoleGenerateStructure* structureStart = *it; + int minY = structureStart->getMinY(); + if (minY < m_minY) m_minY = minY; + } - m_bHaveMinY = true; - } - - // 4J Stu - We DO NOT intersect if our upper bound is below the lower bound for all schematics - if( y1 < m_minY ) return false; + m_bHaveMinY = true; + } - bool intersects = false; - for(AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end();++it) - { - ApplySchematicRuleDefinition *rule = *it; - intersects = rule->checkIntersects(x0,y0,z0,x1,y1,z1); - if(intersects) break; - } + // 4J Stu - We DO NOT intersect if our upper bound is below the lower bound + // for all schematics + if (y1 < m_minY) return false; - if(!intersects) - { - for( AUTO_VAR(it, m_structureRules.begin()); it != m_structureRules.end(); it++ ) - { - ConsoleGenerateStructure *structureStart = *it; - intersects = structureStart->checkIntersects(x0,y0,z0,x1,y1,z1); - if(intersects) break; - } - } - PIXEndNamedEvent(); - return intersects; + bool intersects = false; + for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); + ++it) { + ApplySchematicRuleDefinition* rule = *it; + intersects = rule->checkIntersects(x0, y0, z0, x1, y1, z1); + if (intersects) break; + } + + if (!intersects) { + for (AUTO_VAR(it, m_structureRules.begin()); + it != m_structureRules.end(); it++) { + ConsoleGenerateStructure* structureStart = *it; + intersects = + structureStart->checkIntersects(x0, y0, z0, x1, y1, z1); + if (intersects) break; + } + } + PIXEndNamedEvent(); + return intersects; } -void LevelGenerationOptions::clearSchematics() -{ - for(AUTO_VAR(it, m_schematics.begin()); it != m_schematics.end(); ++it) - { - delete it->second; - } - m_schematics.clear(); +void LevelGenerationOptions::clearSchematics() { + for (AUTO_VAR(it, m_schematics.begin()); it != m_schematics.end(); ++it) { + delete it->second; + } + m_schematics.clear(); } -ConsoleSchematicFile *LevelGenerationOptions::loadSchematicFile(const std::wstring &filename, std::uint8_t *pbData, unsigned int dataLength) -{ - // If we have already loaded this, just return - AUTO_VAR(it, m_schematics.find(filename)); - if(it != m_schematics.end()) - { +ConsoleSchematicFile* LevelGenerationOptions::loadSchematicFile( + const std::wstring& filename, std::uint8_t* pbData, + unsigned int dataLength) { + // If we have already loaded this, just return + AUTO_VAR(it, m_schematics.find(filename)); + if (it != m_schematics.end()) { #ifndef _CONTENT_PACKAGE - wprintf(L"We have already loaded schematic file %ls\n", filename.c_str() ); + wprintf(L"We have already loaded schematic file %ls\n", + filename.c_str()); #endif - it->second->incrementRefCount(); - return it->second; - } + it->second->incrementRefCount(); + return it->second; + } - ConsoleSchematicFile *schematic = NULL; - byteArray data(pbData, dataLength); - ByteArrayInputStream bais(data); - DataInputStream dis(&bais); - schematic = new ConsoleSchematicFile(); - schematic->load(&dis); - m_schematics[filename] = schematic; - bais.reset(); - return schematic; + ConsoleSchematicFile* schematic = NULL; + byteArray data(pbData, dataLength); + ByteArrayInputStream bais(data); + DataInputStream dis(&bais); + schematic = new ConsoleSchematicFile(); + schematic->load(&dis); + m_schematics[filename] = schematic; + bais.reset(); + return schematic; } -ConsoleSchematicFile *LevelGenerationOptions::getSchematicFile(const std::wstring &filename) -{ - ConsoleSchematicFile *schematic = NULL; - // If we have already loaded this, just return - AUTO_VAR(it, m_schematics.find(filename)); - if(it != m_schematics.end()) - { - schematic = it->second; - } - return schematic; +ConsoleSchematicFile* LevelGenerationOptions::getSchematicFile( + const std::wstring& filename) { + ConsoleSchematicFile* schematic = NULL; + // If we have already loaded this, just return + AUTO_VAR(it, m_schematics.find(filename)); + if (it != m_schematics.end()) { + schematic = it->second; + } + return schematic; } -void LevelGenerationOptions::releaseSchematicFile(const std::wstring &filename) -{ - // 4J Stu - We don't want to delete them when done, but probably want to keep a set of active schematics for the current world - //AUTO_VAR(it, m_schematics.find(filename)); - //if(it != m_schematics.end()) - //{ - // ConsoleSchematicFile *schematic = it->second; - // schematic->decrementRefCount(); - // if(schematic->shouldDelete()) - // { - // delete schematic; - // m_schematics.erase(it); - // } - //} +void LevelGenerationOptions::releaseSchematicFile( + const std::wstring& filename) { + // 4J Stu - We don't want to delete them when done, but probably want to + // keep a set of active schematics for the current world + // AUTO_VAR(it, m_schematics.find(filename)); + // if(it != m_schematics.end()) + //{ + // ConsoleSchematicFile *schematic = it->second; + // schematic->decrementRefCount(); + // if(schematic->shouldDelete()) + // { + // delete schematic; + // m_schematics.erase(it); + // } + //} } -void LevelGenerationOptions::loadStringTable(StringTable *table) -{ - m_stringTable = table; +void LevelGenerationOptions::loadStringTable(StringTable* table) { + m_stringTable = table; } -const wchar_t *LevelGenerationOptions::getString(const std::wstring &key) -{ - if(m_stringTable == NULL) - { - return L""; - } - else - { - return m_stringTable->getString(key); - } +const wchar_t* LevelGenerationOptions::getString(const std::wstring& key) { + if (m_stringTable == NULL) { + return L""; + } else { + return m_stringTable->getString(key); + } } -void LevelGenerationOptions::getBiomeOverride(int biomeId, std::uint8_t &tile, std::uint8_t &topTile) -{ - for(AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); ++it) - { - BiomeOverride *bo = *it; - if(bo->isBiome(biomeId)) - { - bo->getTileValues(tile,topTile); - break; - } - } +void LevelGenerationOptions::getBiomeOverride(int biomeId, std::uint8_t& tile, + std::uint8_t& topTile) { + for (AUTO_VAR(it, m_biomeOverrides.begin()); it != m_biomeOverrides.end(); + ++it) { + BiomeOverride* bo = *it; + if (bo->isBiome(biomeId)) { + bo->getTileValues(tile, topTile); + break; + } + } } -bool LevelGenerationOptions::isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature) -{ - bool isFeature = false; +bool LevelGenerationOptions::isFeatureChunk( + int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature) { + bool isFeature = false; - for(AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) - { - StartFeature *sf = *it; - if(sf->isFeatureChunk(chunkX, chunkZ, feature)) - { - isFeature = true; - break; - } - } - return isFeature; + for (AUTO_VAR(it, m_features.begin()); it != m_features.end(); ++it) { + StartFeature* sf = *it; + if (sf->isFeatureChunk(chunkX, chunkZ, feature)) { + isFeature = true; + break; + } + } + return isFeature; } -std::unordered_map *LevelGenerationOptions::getUnfinishedSchematicFiles() -{ - // Clean schematic rules. - std::unordered_set usedFiles = std::unordered_set(); - for (AUTO_VAR(it, m_schematicRules.begin()); it!=m_schematicRules.end(); it++) - if ( !(*it)->isComplete() ) - usedFiles.insert( (*it)->getSchematicName() ); +std::unordered_map* +LevelGenerationOptions::getUnfinishedSchematicFiles() { + // Clean schematic rules. + std::unordered_set usedFiles = + std::unordered_set(); + for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); + it++) + if (!(*it)->isComplete()) usedFiles.insert((*it)->getSchematicName()); - // Clean schematic files. - std::unordered_map *out - = new std::unordered_map(); - for (AUTO_VAR(it, usedFiles.begin()); it!=usedFiles.end(); it++) - out->insert( std::pair(*it, getSchematicFile(*it)) ); - - return out; + // Clean schematic files. + std::unordered_map* out = + new std::unordered_map(); + for (AUTO_VAR(it, usedFiles.begin()); it != usedFiles.end(); it++) + out->insert(std::pair( + *it, getSchematicFile(*it))); + + return out; } -void LevelGenerationOptions::reset_start() -{ - for ( AUTO_VAR( it, m_schematicRules.begin()); - it != m_schematicRules.end(); - it++ ) - { - (*it)->reset(); - } +void LevelGenerationOptions::reset_start() { + for (AUTO_VAR(it, m_schematicRules.begin()); it != m_schematicRules.end(); + it++) { + (*it)->reset(); + } } -void LevelGenerationOptions::reset_finish() -{ - //if (m_spawnPos) { delete m_spawnPos; m_spawnPos = NULL; } - //if (m_stringTable) { delete m_stringTable; m_stringTable = NULL; } +void LevelGenerationOptions::reset_finish() { + // if (m_spawnPos) { delete m_spawnPos; m_spawnPos + // = NULL; } if (m_stringTable) { delete m_stringTable; + // m_stringTable = NULL; } - if (isFromDLC()) - { - m_hasLoadedData = false; - } + if (isFromDLC()) { + m_hasLoadedData = false; + } } - -GrSource *LevelGenerationOptions::info() { return m_pSrc; } +GrSource* LevelGenerationOptions::info() { return m_pSrc; } void LevelGenerationOptions::setSrc(eSrc src) { m_src = src; } LevelGenerationOptions::eSrc LevelGenerationOptions::getSrc() { return m_src; } @@ -477,39 +477,89 @@ bool LevelGenerationOptions::isTutorial() { return getSrc() == eSrc_tutorial; } bool LevelGenerationOptions::isFromSave() { return getSrc() == eSrc_fromSave; } bool LevelGenerationOptions::isFromDLC() { return getSrc() == eSrc_fromDLC; } -bool LevelGenerationOptions::requiresTexturePack() { return info()->requiresTexturePack(); } -std::uint32_t LevelGenerationOptions::getRequiredTexturePackId() { return info()->getRequiredTexturePackId(); } -std::wstring LevelGenerationOptions::getDefaultSaveName() { return info()->getDefaultSaveName(); } -const wchar_t *LevelGenerationOptions::getWorldName() { return info()->getWorldName(); } -const wchar_t *LevelGenerationOptions::getDisplayName() { return info()->getDisplayName(); } -std::wstring LevelGenerationOptions::getGrfPath() { return info()->getGrfPath(); } -bool LevelGenerationOptions::requiresBaseSave() { return info()->requiresBaseSave(); } -std::wstring LevelGenerationOptions::getBaseSavePath() { return info()->getBaseSavePath(); } +bool LevelGenerationOptions::requiresTexturePack() { + return info()->requiresTexturePack(); +} +std::uint32_t LevelGenerationOptions::getRequiredTexturePackId() { + return info()->getRequiredTexturePackId(); +} +std::wstring LevelGenerationOptions::getDefaultSaveName() { + return info()->getDefaultSaveName(); +} +const wchar_t* LevelGenerationOptions::getWorldName() { + return info()->getWorldName(); +} +const wchar_t* LevelGenerationOptions::getDisplayName() { + return info()->getDisplayName(); +} +std::wstring LevelGenerationOptions::getGrfPath() { + return info()->getGrfPath(); +} +bool LevelGenerationOptions::requiresBaseSave() { + return info()->requiresBaseSave(); +} +std::wstring LevelGenerationOptions::getBaseSavePath() { + return info()->getBaseSavePath(); +} -void LevelGenerationOptions::setGrSource(GrSource *grs) { m_pSrc = grs; } +void LevelGenerationOptions::setGrSource(GrSource* grs) { m_pSrc = grs; } -void LevelGenerationOptions::setRequiresTexturePack(bool x) { info()->setRequiresTexturePack(x); } -void LevelGenerationOptions::setRequiredTexturePackId(std::uint32_t x) { info()->setRequiredTexturePackId(x); } -void LevelGenerationOptions::setDefaultSaveName(const std::wstring &x) { info()->setDefaultSaveName(x); } -void LevelGenerationOptions::setWorldName(const std::wstring &x) { info()->setWorldName(x); } -void LevelGenerationOptions::setDisplayName(const std::wstring &x) { info()->setDisplayName(x); } -void LevelGenerationOptions::setGrfPath(const std::wstring &x) { info()->setGrfPath(x); } -void LevelGenerationOptions::setBaseSavePath(const std::wstring &x) { info()->setBaseSavePath(x); } +void LevelGenerationOptions::setRequiresTexturePack(bool x) { + info()->setRequiresTexturePack(x); +} +void LevelGenerationOptions::setRequiredTexturePackId(std::uint32_t x) { + info()->setRequiredTexturePackId(x); +} +void LevelGenerationOptions::setDefaultSaveName(const std::wstring& x) { + info()->setDefaultSaveName(x); +} +void LevelGenerationOptions::setWorldName(const std::wstring& x) { + info()->setWorldName(x); +} +void LevelGenerationOptions::setDisplayName(const std::wstring& x) { + info()->setDisplayName(x); +} +void LevelGenerationOptions::setGrfPath(const std::wstring& x) { + info()->setGrfPath(x); +} +void LevelGenerationOptions::setBaseSavePath(const std::wstring& x) { + info()->setBaseSavePath(x); +} bool LevelGenerationOptions::ready() { return info()->ready(); } -void LevelGenerationOptions::setBaseSaveData(std::uint8_t *pbData, unsigned int dataSize) { m_pbBaseSaveData = pbData; m_baseSaveSize = dataSize; } -std::uint8_t *LevelGenerationOptions::getBaseSaveData(unsigned int &size) { size = m_baseSaveSize; return m_pbBaseSaveData; } -bool LevelGenerationOptions::hasBaseSaveData() { return m_baseSaveSize > 0 && m_pbBaseSaveData != NULL; } -void LevelGenerationOptions::deleteBaseSaveData() { delete[] m_pbBaseSaveData; m_pbBaseSaveData = NULL; m_baseSaveSize = 0; } +void LevelGenerationOptions::setBaseSaveData(std::uint8_t* pbData, + unsigned int dataSize) { + m_pbBaseSaveData = pbData; + m_baseSaveSize = dataSize; +} +std::uint8_t* LevelGenerationOptions::getBaseSaveData(unsigned int& size) { + size = m_baseSaveSize; + return m_pbBaseSaveData; +} +bool LevelGenerationOptions::hasBaseSaveData() { + return m_baseSaveSize > 0 && m_pbBaseSaveData != NULL; +} +void LevelGenerationOptions::deleteBaseSaveData() { + delete[] m_pbBaseSaveData; + m_pbBaseSaveData = NULL; + m_baseSaveSize = 0; +} bool LevelGenerationOptions::hasLoadedData() { return m_hasLoadedData; } void LevelGenerationOptions::setLoadedData() { m_hasLoadedData = true; } __int64 LevelGenerationOptions::getLevelSeed() { return m_seed; } -Pos *LevelGenerationOptions::getSpawnPos() { return m_spawnPos; } +Pos* LevelGenerationOptions::getSpawnPos() { return m_spawnPos; } bool LevelGenerationOptions::getuseFlatWorld() { return m_useFlatWorld; } -bool LevelGenerationOptions::requiresGameRules() { return m_bRequiresGameRules; } -void LevelGenerationOptions::setRequiredGameRules(LevelRuleset *rules) { m_requiredGameRules = rules; m_bRequiresGameRules = true; } -LevelRuleset *LevelGenerationOptions::getRequiredGameRules() { return m_requiredGameRules; } +bool LevelGenerationOptions::requiresGameRules() { + return m_bRequiresGameRules; +} +void LevelGenerationOptions::setRequiredGameRules(LevelRuleset* rules) { + m_requiredGameRules = rules; + m_bRequiresGameRules = true; +} +LevelRuleset* LevelGenerationOptions::getRequiredGameRules() { + return m_requiredGameRules; +} diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.h b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.h index 1ba465405..a690dcbc2 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.h +++ b/Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.h @@ -1,5 +1,5 @@ #pragma once -//using namespace std; +// using namespace std; // #pragma message("LevelGenerationOptions.h ") @@ -16,204 +16,209 @@ class LevelRuleset; class BiomeOverride; class StartFeature; -class GrSource -{ +class GrSource { public: - // 4J-JEV: - // Moved all this here; I didn't like that all this header information - // was being mixed in with all the game information as they have - // completely different lifespans. + // 4J-JEV: + // Moved all this here; I didn't like that all this header information + // was being mixed in with all the game information as they have + // completely different lifespans. - virtual ~GrSource(){} - virtual bool requiresTexturePack()=0; - virtual std::uint32_t getRequiredTexturePackId()=0; - virtual std::wstring getDefaultSaveName()=0; - virtual const wchar_t *getWorldName()=0; - virtual const wchar_t *getDisplayName()=0; - virtual std::wstring getGrfPath()=0; - virtual bool requiresBaseSave() = 0; - virtual std::wstring getBaseSavePath() = 0; + virtual ~GrSource() {} + virtual bool requiresTexturePack() = 0; + virtual std::uint32_t getRequiredTexturePackId() = 0; + virtual std::wstring getDefaultSaveName() = 0; + virtual const wchar_t* getWorldName() = 0; + virtual const wchar_t* getDisplayName() = 0; + virtual std::wstring getGrfPath() = 0; + virtual bool requiresBaseSave() = 0; + virtual std::wstring getBaseSavePath() = 0; - virtual void setRequiresTexturePack(bool)=0; - virtual void setRequiredTexturePackId(std::uint32_t)=0; - virtual void setDefaultSaveName(const std::wstring &)=0; - virtual void setWorldName(const std::wstring &)=0; - virtual void setDisplayName(const std::wstring &)=0; - virtual void setGrfPath(const std::wstring &)=0; - virtual void setBaseSavePath(const std::wstring &)=0; + virtual void setRequiresTexturePack(bool) = 0; + virtual void setRequiredTexturePackId(std::uint32_t) = 0; + virtual void setDefaultSaveName(const std::wstring&) = 0; + virtual void setWorldName(const std::wstring&) = 0; + virtual void setDisplayName(const std::wstring&) = 0; + virtual void setGrfPath(const std::wstring&) = 0; + virtual void setBaseSavePath(const std::wstring&) = 0; - virtual bool ready()=0; + virtual bool ready() = 0; - //virtual void getGrfData(std::uint8_t *&pData, unsigned int &pSize)=0; + // virtual void getGrfData(std::uint8_t *&pData, unsigned int &pSize)=0; }; -class JustGrSource : public GrSource -{ +class JustGrSource : public GrSource { protected: - std::wstring m_worldName; - std::wstring m_displayName; - std::wstring m_defaultSaveName; - bool m_bRequiresTexturePack; - std::uint32_t m_requiredTexturePackId; - std::wstring m_grfPath; - std::wstring m_baseSavePath; - bool m_bRequiresBaseSave; + std::wstring m_worldName; + std::wstring m_displayName; + std::wstring m_defaultSaveName; + bool m_bRequiresTexturePack; + std::uint32_t m_requiredTexturePackId; + std::wstring m_grfPath; + std::wstring m_baseSavePath; + bool m_bRequiresBaseSave; public: - virtual bool requiresTexturePack(); - virtual std::uint32_t getRequiredTexturePackId(); - virtual std::wstring getDefaultSaveName(); - virtual const wchar_t *getWorldName(); - virtual const wchar_t *getDisplayName(); - virtual std::wstring getGrfPath(); - virtual bool requiresBaseSave(); - virtual std::wstring getBaseSavePath(); + virtual bool requiresTexturePack(); + virtual std::uint32_t getRequiredTexturePackId(); + virtual std::wstring getDefaultSaveName(); + virtual const wchar_t* getWorldName(); + virtual const wchar_t* getDisplayName(); + virtual std::wstring getGrfPath(); + virtual bool requiresBaseSave(); + virtual std::wstring getBaseSavePath(); - virtual void setRequiresTexturePack(bool x); - virtual void setRequiredTexturePackId(std::uint32_t x); - virtual void setDefaultSaveName(const std::wstring &x); - virtual void setWorldName(const std::wstring &x); - virtual void setDisplayName(const std::wstring &x); - virtual void setGrfPath(const std::wstring &x); - virtual void setBaseSavePath(const std::wstring &x); + virtual void setRequiresTexturePack(bool x); + virtual void setRequiredTexturePackId(std::uint32_t x); + virtual void setDefaultSaveName(const std::wstring& x); + virtual void setWorldName(const std::wstring& x); + virtual void setDisplayName(const std::wstring& x); + virtual void setGrfPath(const std::wstring& x); + virtual void setBaseSavePath(const std::wstring& x); - virtual bool ready(); + virtual bool ready(); - JustGrSource(); + JustGrSource(); }; -class LevelGenerationOptions : public GameRuleDefinition -{ +class LevelGenerationOptions : public GameRuleDefinition { public: - enum eSrc - { - eSrc_none, + enum eSrc { + eSrc_none, - eSrc_fromSave, // Neither content or header is persistent. + eSrc_fromSave, // Neither content or header is persistent. - eSrc_fromDLC, // Header is persistent, content should be deleted to conserve space. + eSrc_fromDLC, // Header is persistent, content should be deleted to + // conserve space. - eSrc_tutorial, // Both header and content is persistent, content cannot be reloaded. + eSrc_tutorial, // Both header and content is persistent, content cannot + // be reloaded. - eSrc_MAX - }; + eSrc_MAX + }; private: - eSrc m_src; + eSrc m_src; - GrSource *m_pSrc; - GrSource *info(); + GrSource* m_pSrc; + GrSource* info(); - bool m_hasLoadedData; + bool m_hasLoadedData; - std::uint8_t *m_pbBaseSaveData; - unsigned int m_baseSaveSize; + std::uint8_t* m_pbBaseSaveData; + unsigned int m_baseSaveSize; public: + void setSrc(eSrc src); + eSrc getSrc(); - void setSrc(eSrc src); - eSrc getSrc(); + bool isTutorial(); + bool isFromSave(); + bool isFromDLC(); - bool isTutorial(); - bool isFromSave(); - bool isFromDLC(); + bool requiresTexturePack(); + std::uint32_t getRequiredTexturePackId(); + std::wstring getDefaultSaveName(); + const wchar_t* getWorldName(); + const wchar_t* getDisplayName(); + std::wstring getGrfPath(); + bool requiresBaseSave(); + std::wstring getBaseSavePath(); - bool requiresTexturePack(); - std::uint32_t getRequiredTexturePackId(); - std::wstring getDefaultSaveName(); - const wchar_t *getWorldName(); - const wchar_t *getDisplayName(); - std::wstring getGrfPath(); - bool requiresBaseSave(); - std::wstring getBaseSavePath(); + void setGrSource(GrSource* grs); - void setGrSource(GrSource *grs); + void setRequiresTexturePack(bool x); + void setRequiredTexturePackId(std::uint32_t x); + void setDefaultSaveName(const std::wstring& x); + void setWorldName(const std::wstring& x); + void setDisplayName(const std::wstring& x); + void setGrfPath(const std::wstring& x); + void setBaseSavePath(const std::wstring& x); - void setRequiresTexturePack(bool x); - void setRequiredTexturePackId(std::uint32_t x); - void setDefaultSaveName(const std::wstring &x); - void setWorldName(const std::wstring &x); - void setDisplayName(const std::wstring &x); - void setGrfPath(const std::wstring &x); - void setBaseSavePath(const std::wstring &x); + bool ready(); - bool ready(); + void setBaseSaveData(std::uint8_t* pbData, unsigned int dataSize); + std::uint8_t* getBaseSaveData(unsigned int& size); + bool hasBaseSaveData(); + void deleteBaseSaveData(); - void setBaseSaveData(std::uint8_t *pbData, unsigned int dataSize); - std::uint8_t *getBaseSaveData(unsigned int &size); - bool hasBaseSaveData(); - void deleteBaseSaveData(); - - bool hasLoadedData(); - void setLoadedData(); + bool hasLoadedData(); + void setLoadedData(); private: - // This should match the "MapOptionsRule" definition in the XML schema - __int64 m_seed; - bool m_useFlatWorld; - Pos *m_spawnPos; - std::vector m_schematicRules; - std::vector m_structureRules; - bool m_bHaveMinY; - int m_minY; - std::unordered_map m_schematics; - std::vector m_biomeOverrides; - std::vector m_features; + // This should match the "MapOptionsRule" definition in the XML schema + __int64 m_seed; + bool m_useFlatWorld; + Pos* m_spawnPos; + std::vector m_schematicRules; + std::vector m_structureRules; + bool m_bHaveMinY; + int m_minY; + std::unordered_map m_schematics; + std::vector m_biomeOverrides; + std::vector m_features; - bool m_bRequiresGameRules; - LevelRuleset *m_requiredGameRules; + bool m_bRequiresGameRules; + LevelRuleset* m_requiredGameRules; - StringTable *m_stringTable; + StringTable* m_stringTable; public: - LevelGenerationOptions(); - ~LevelGenerationOptions(); + LevelGenerationOptions(); + ~LevelGenerationOptions(); - virtual ConsoleGameRules::EGameRuleType getActionType(); - - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); - virtual void getChildren(std::vector *children); - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual ConsoleGameRules::EGameRuleType getActionType(); - __int64 getLevelSeed(); - Pos *getSpawnPos(); - bool getuseFlatWorld(); + virtual void writeAttributes(DataOutputStream* dos, + unsigned int numAttributes); + virtual void getChildren(std::vector* children); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - void processSchematics(LevelChunk *chunk); - void processSchematicsLighting(LevelChunk *chunk); + __int64 getLevelSeed(); + Pos* getSpawnPos(); + bool getuseFlatWorld(); - bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); + void processSchematics(LevelChunk* chunk); + void processSchematicsLighting(LevelChunk* chunk); + + bool checkIntersects(int x0, int y0, int z0, int x1, int y1, int z1); private: - void clearSchematics(); - -public: - ConsoleSchematicFile *loadSchematicFile(const std::wstring &filename, std::uint8_t *pbData, unsigned int dataLength); + void clearSchematics(); public: - ConsoleSchematicFile *getSchematicFile(const std::wstring &filename); - void releaseSchematicFile(const std::wstring &filename); + ConsoleSchematicFile* loadSchematicFile(const std::wstring& filename, + std::uint8_t* pbData, + unsigned int dataLength); - bool requiresGameRules(); - void setRequiredGameRules(LevelRuleset *rules); - LevelRuleset *getRequiredGameRules(); +public: + ConsoleSchematicFile* getSchematicFile(const std::wstring& filename); + void releaseSchematicFile(const std::wstring& filename); - void getBiomeOverride(int biomeId, std::uint8_t &tile, std::uint8_t &topTile); - bool isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature); + bool requiresGameRules(); + void setRequiredGameRules(LevelRuleset* rules); + LevelRuleset* getRequiredGameRules(); - void loadStringTable(StringTable *table); - const wchar_t *getString(const std::wstring &key); + void getBiomeOverride(int biomeId, std::uint8_t& tile, + std::uint8_t& topTile); + bool isFeatureChunk(int chunkX, int chunkZ, + StructureFeature::EFeatureTypes feature); - std::unordered_map *getUnfinishedSchematicFiles(); - - // 4J-JEV: - // ApplySchematicRules contain limited state - // which needs to be reset BEFORE a new game starts. - void reset_start(); + void loadStringTable(StringTable* table); + const wchar_t* getString(const std::wstring& key); - // 4J-JEV: - // This file contains state that needs to be deleted - // or reset once a game has finished. - void reset_finish(); + std::unordered_map* + getUnfinishedSchematicFiles(); + + // 4J-JEV: + // ApplySchematicRules contain limited state + // which needs to be reset BEFORE a new game starts. + void reset_start(); + + // 4J-JEV: + // This file contains state that needs to be deleted + // or reset once a game has finished. + void reset_finish(); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.cpp b/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.cpp index 0140f5851..5c8fdff78 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.cpp @@ -2,25 +2,18 @@ #include "LevelGenerationOptions.h" #include "LevelGenerators.h" +LevelGenerators::LevelGenerators() {} -LevelGenerators::LevelGenerators() -{ +void LevelGenerators::addLevelGenerator(const std::wstring& displayName, + LevelGenerationOptions* generator) { + if (!displayName.empty()) generator->setDisplayName(displayName); + m_levelGenerators.push_back(generator); } -void LevelGenerators::addLevelGenerator(const std::wstring &displayName, LevelGenerationOptions *generator) -{ - if(!displayName.empty()) generator->setDisplayName(displayName); - m_levelGenerators.push_back(generator); -} - -void LevelGenerators::removeLevelGenerator(LevelGenerationOptions *generator) -{ - std::vector::iterator it; - while ( (it = find( m_levelGenerators.begin(), - m_levelGenerators.end(), - generator ) ) - != m_levelGenerators.end() ) - { - m_levelGenerators.erase(it); - } +void LevelGenerators::removeLevelGenerator(LevelGenerationOptions* generator) { + std::vector::iterator it; + while ((it = find(m_levelGenerators.begin(), m_levelGenerators.end(), + generator)) != m_levelGenerators.end()) { + m_levelGenerators.erase(it); + } } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.h b/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.h index ac05ee857..ccfbff3ad 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.h +++ b/Minecraft.Client/Platform/Common/GameRules/LevelGenerators.h @@ -1,19 +1,21 @@ #pragma once -//using namespace std; +// using namespace std; class LevelGenerationOptions; -class LevelGenerators -{ +class LevelGenerators { private: - std::vector m_levelGenerators; + std::vector m_levelGenerators; public: - LevelGenerators(); + LevelGenerators(); - void addLevelGenerator(const std::wstring &displayName, LevelGenerationOptions *generator); - void removeLevelGenerator(LevelGenerationOptions *generator); + void addLevelGenerator(const std::wstring& displayName, + LevelGenerationOptions* generator); + void removeLevelGenerator(LevelGenerationOptions* generator); - std::vector *getLevelGenerators() { return &m_levelGenerators; } + std::vector* getLevelGenerators() { + return &m_levelGenerators; + } }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelRules.cpp b/Minecraft.Client/Platform/Common/GameRules/LevelRules.cpp index 94d2d55f7..8e280e0ac 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelRules.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/LevelRules.cpp @@ -1,20 +1,14 @@ #include "../../Minecraft.World/Platform/stdafx.h" #include "LevelRules.h" +LevelRules::LevelRules() {} -LevelRules::LevelRules() -{ -} +void LevelRules::addLevelRule(const std::wstring& displayName, + std::uint8_t* pbData, unsigned int dataLength) {} -void LevelRules::addLevelRule(const std::wstring &displayName, std::uint8_t *pbData, unsigned int dataLength) -{ -} +void LevelRules::addLevelRule(const std::wstring& displayName, + LevelRuleset* rootRule) {} -void LevelRules::addLevelRule(const std::wstring &displayName, LevelRuleset *rootRule) -{ -} - -void LevelRules::removeLevelRule(LevelRuleset *removing) -{ - // TODO ? +void LevelRules::removeLevelRule(LevelRuleset* removing) { + // TODO ? } diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelRules.h b/Minecraft.Client/Platform/Common/GameRules/LevelRules.h index d32577eef..d297beb2a 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelRules.h +++ b/Minecraft.Client/Platform/Common/GameRules/LevelRules.h @@ -2,13 +2,13 @@ class LevelRuleset; -class LevelRules -{ +class LevelRules { public: - LevelRules(); + LevelRules(); - void addLevelRule(const std::wstring &displayName, std::uint8_t *pbData, unsigned int dataLength); - void addLevelRule(const std::wstring &displayName, LevelRuleset *rootRule); + void addLevelRule(const std::wstring& displayName, std::uint8_t* pbData, + unsigned int dataLength); + void addLevelRule(const std::wstring& displayName, LevelRuleset* rootRule); - void removeLevelRule(LevelRuleset *removing); + void removeLevelRule(LevelRuleset* removing); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp b/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp index 0c0e2cb08..30bc16254 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp @@ -4,68 +4,51 @@ #include "ConsoleGameRules.h" #include "LevelRuleset.h" -LevelRuleset::LevelRuleset() -{ - m_stringTable = NULL; +LevelRuleset::LevelRuleset() { m_stringTable = NULL; } + +LevelRuleset::~LevelRuleset() { + for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) { + delete *it; + } } -LevelRuleset::~LevelRuleset() -{ - for(AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) - { - delete *it; - } +void LevelRuleset::getChildren(std::vector* children) { + CompoundGameRuleDefinition::getChildren(children); + for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); it++) + children->push_back(*it); } -void LevelRuleset::getChildren(std::vector *children) -{ - CompoundGameRuleDefinition::getChildren(children); - for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); it++) - children->push_back(*it); +GameRuleDefinition* LevelRuleset::addChild( + ConsoleGameRules::EGameRuleType ruleType) { + GameRuleDefinition* rule = NULL; + if (ruleType == ConsoleGameRules::eGameRuleType_NamedArea) { + rule = new NamedAreaRuleDefinition(); + m_areas.push_back((NamedAreaRuleDefinition*)rule); + } else { + rule = CompoundGameRuleDefinition::addChild(ruleType); + } + return rule; } -GameRuleDefinition *LevelRuleset::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ - GameRuleDefinition *rule = NULL; - if(ruleType == ConsoleGameRules::eGameRuleType_NamedArea) - { - rule = new NamedAreaRuleDefinition(); - m_areas.push_back((NamedAreaRuleDefinition *)rule); - } - else - { - rule = CompoundGameRuleDefinition::addChild(ruleType); - } - return rule; +void LevelRuleset::loadStringTable(StringTable* table) { + m_stringTable = table; } -void LevelRuleset::loadStringTable(StringTable *table) -{ - m_stringTable = table; +const wchar_t* LevelRuleset::getString(const std::wstring& key) { + if (m_stringTable == NULL) { + return L""; + } else { + return m_stringTable->getString(key); + } } -const wchar_t *LevelRuleset::getString(const std::wstring &key) -{ - if(m_stringTable == NULL) - { - return L""; - } - else - { - return m_stringTable->getString(key); - } -} - -AABB *LevelRuleset::getNamedArea(const std::wstring &areaName) -{ - AABB *area = NULL; - for(AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) - { - if( (*it)->getName().compare(areaName) == 0 ) - { - area = (*it)->getArea(); - break; - } - } - return area; +AABB* LevelRuleset::getNamedArea(const std::wstring& areaName) { + AABB* area = NULL; + for (AUTO_VAR(it, m_areas.begin()); it != m_areas.end(); ++it) { + if ((*it)->getName().compare(areaName) == 0) { + area = (*it)->getArea(); + break; + } + } + return area; } diff --git a/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.h b/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.h index 1b7810659..c44c19d91 100644 --- a/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.h +++ b/Minecraft.Client/Platform/Common/GameRules/LevelRuleset.h @@ -4,24 +4,27 @@ class NamedAreaRuleDefinition; -class LevelRuleset : public CompoundGameRuleDefinition -{ +class LevelRuleset : public CompoundGameRuleDefinition { private: - std::vector m_areas; - StringTable *m_stringTable; + std::vector m_areas; + StringTable* m_stringTable; + public: - LevelRuleset(); - ~LevelRuleset(); + LevelRuleset(); + ~LevelRuleset(); - virtual void getChildren(std::vector *children); - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); + virtual void getChildren(std::vector* children); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_LevelRules; } + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_LevelRules; + } - void loadStringTable(StringTable *table); - const wchar_t *getString(const std::wstring &key); + void loadStringTable(StringTable* table); + const wchar_t* getString(const std::wstring& key); - AABB *getNamedArea(const std::wstring &areaName); + AABB* getNamedArea(const std::wstring& areaName); - StringTable *getStringTable() { return m_stringTable; } + StringTable* getStringTable() { return m_stringTable; } }; diff --git a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp index bf79d1c14..b09982ae9 100644 --- a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.cpp @@ -3,82 +3,70 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Headers/net.minecraft.world.phys.h" -NamedAreaRuleDefinition::NamedAreaRuleDefinition() -{ - m_name = L""; - m_area = AABB::newPermanent(0,0,0,0,0,0); +NamedAreaRuleDefinition::NamedAreaRuleDefinition() { + m_name = L""; + m_area = AABB::newPermanent(0, 0, 0, 0, 0, 0); } -NamedAreaRuleDefinition::~NamedAreaRuleDefinition() -{ - delete m_area; +NamedAreaRuleDefinition::~NamedAreaRuleDefinition() { delete m_area; } + +void NamedAreaRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttributes) { + GameRuleDefinition::writeAttributes(dos, numAttributes + 7); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_name); + dos->writeUTF(m_name); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0); + dos->writeUTF(_toString(m_area->x0)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0); + dos->writeUTF(_toString(m_area->y0)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0); + dos->writeUTF(_toString(m_area->z0)); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1); + dos->writeUTF(_toString(m_area->x1)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1); + dos->writeUTF(_toString(m_area->y1)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1); + dos->writeUTF(_toString(m_area->z1)); } -void NamedAreaRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) -{ - GameRuleDefinition::writeAttributes(dos, numAttributes + 7); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_name); - dos->writeUTF(m_name); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0); - dos->writeUTF(_toString(m_area->x0)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0); - dos->writeUTF(_toString(m_area->y0)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0); - dos->writeUTF(_toString(m_area->z0)); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1); - dos->writeUTF(_toString(m_area->x1)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1); - dos->writeUTF(_toString(m_area->y1)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1); - dos->writeUTF(_toString(m_area->z1)); -} - -void NamedAreaRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"name") == 0) - { - m_name = attributeValue; +void NamedAreaRuleDefinition::addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue) { + if (attributeName.compare(L"name") == 0) { + m_name = attributeValue; #ifndef _CONTENT_PACKAGE - wprintf(L"NamedAreaRuleDefinition: Adding parameter name=%ls\n",m_name.c_str()); + wprintf(L"NamedAreaRuleDefinition: Adding parameter name=%ls\n", + m_name.c_str()); #endif - } - else if(attributeName.compare(L"x0") == 0) - { - m_area->x0 = _fromString(attributeValue); - app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n",m_area->x0); - } - else if(attributeName.compare(L"y0") == 0) - { - m_area->y0 = _fromString(attributeValue); - if(m_area->y0 < 0) m_area->y0 = 0; - app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n",m_area->y0); - } - else if(attributeName.compare(L"z0") == 0) - { - m_area->z0 = _fromString(attributeValue); - app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n",m_area->z0); - } - else if(attributeName.compare(L"x1") == 0) - { - m_area->x1 = _fromString(attributeValue); - app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n",m_area->x1); - } - else if(attributeName.compare(L"y1") == 0) - { - m_area->y1 = _fromString(attributeValue); - if(m_area->y1 < 0) m_area->y1 = 0; - app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n",m_area->y1); - } - else if(attributeName.compare(L"z1") == 0) - { - m_area->z1 = _fromString(attributeValue); - app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n",m_area->z1); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } + } else if (attributeName.compare(L"x0") == 0) { + m_area->x0 = _fromString(attributeValue); + app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x0=%f\n", + m_area->x0); + } else if (attributeName.compare(L"y0") == 0) { + m_area->y0 = _fromString(attributeValue); + if (m_area->y0 < 0) m_area->y0 = 0; + app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y0=%f\n", + m_area->y0); + } else if (attributeName.compare(L"z0") == 0) { + m_area->z0 = _fromString(attributeValue); + app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z0=%f\n", + m_area->z0); + } else if (attributeName.compare(L"x1") == 0) { + m_area->x1 = _fromString(attributeValue); + app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter x1=%f\n", + m_area->x1); + } else if (attributeName.compare(L"y1") == 0) { + m_area->y1 = _fromString(attributeValue); + if (m_area->y1 < 0) m_area->y1 = 0; + app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter y1=%f\n", + m_area->y1); + } else if (attributeName.compare(L"z1") == 0) { + m_area->z1 = _fromString(attributeValue); + app.DebugPrintf("NamedAreaRuleDefinition: Adding parameter z1=%f\n", + m_area->z1); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } diff --git a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h index ff3eb3cb9..93f8a0c47 100644 --- a/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/NamedAreaRuleDefinition.h @@ -2,22 +2,25 @@ #include "GameRuleDefinition.h" -class NamedAreaRuleDefinition : public GameRuleDefinition -{ +class NamedAreaRuleDefinition : public GameRuleDefinition { private: - std::wstring m_name; - AABB *m_area; + std::wstring m_name; + AABB* m_area; public: - NamedAreaRuleDefinition(); - ~NamedAreaRuleDefinition(); + NamedAreaRuleDefinition(); + ~NamedAreaRuleDefinition(); - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); + virtual void writeAttributes(DataOutputStream* dos, + unsigned int numAttributes); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_NamedArea; } - - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_NamedArea; + } - AABB *getArea() { return m_area; } - std::wstring getName() { return m_name; } + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); + + AABB* getArea() { return m_area; } + std::wstring getName() { return m_name; } }; diff --git a/Minecraft.Client/Platform/Common/GameRules/StartFeature.cpp b/Minecraft.Client/Platform/Common/GameRules/StartFeature.cpp index be44ca2b4..20c7f0b5b 100644 --- a/Minecraft.Client/Platform/Common/GameRules/StartFeature.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/StartFeature.cpp @@ -2,52 +2,45 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "StartFeature.h" -StartFeature::StartFeature() -{ - m_chunkX = 0; - m_chunkZ = 0; - m_feature = StructureFeature::eFeature_Temples; +StartFeature::StartFeature() { + m_chunkX = 0; + m_chunkZ = 0; + m_feature = StructureFeature::eFeature_Temples; } -void StartFeature::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - GameRuleDefinition::writeAttributes(dos, numAttrs + 3); +void StartFeature::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + GameRuleDefinition::writeAttributes(dos, numAttrs + 3); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkX); - dos->writeUTF(_toString(m_chunkX)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkZ); - dos->writeUTF(_toString(m_chunkZ)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_feature); - dos->writeUTF(_toString((int)m_feature)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkX); + dos->writeUTF(_toString(m_chunkX)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_chunkZ); + dos->writeUTF(_toString(m_chunkZ)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_feature); + dos->writeUTF(_toString((int)m_feature)); } -void StartFeature::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"chunkX") == 0) - { - int value = _fromString(attributeValue); - m_chunkX = value; - app.DebugPrintf("StartFeature: Adding parameter chunkX=%d\n",m_chunkX); - } - else if(attributeName.compare(L"chunkZ") == 0) - { - int value = _fromString(attributeValue); - m_chunkZ = value; - app.DebugPrintf("StartFeature: Adding parameter chunkZ=%d\n",m_chunkZ); - } - else if(attributeName.compare(L"feature") == 0) - { - int value = _fromString(attributeValue); - m_feature = (StructureFeature::EFeatureTypes)value; - app.DebugPrintf("StartFeature: Adding parameter feature=%d\n",m_feature); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void StartFeature::addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue) { + if (attributeName.compare(L"chunkX") == 0) { + int value = _fromString(attributeValue); + m_chunkX = value; + app.DebugPrintf("StartFeature: Adding parameter chunkX=%d\n", m_chunkX); + } else if (attributeName.compare(L"chunkZ") == 0) { + int value = _fromString(attributeValue); + m_chunkZ = value; + app.DebugPrintf("StartFeature: Adding parameter chunkZ=%d\n", m_chunkZ); + } else if (attributeName.compare(L"feature") == 0) { + int value = _fromString(attributeValue); + m_feature = (StructureFeature::EFeatureTypes)value; + app.DebugPrintf("StartFeature: Adding parameter feature=%d\n", + m_feature); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -bool StartFeature::isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature) -{ - return chunkX == m_chunkX && chunkZ == m_chunkZ && feature == m_feature; +bool StartFeature::isFeatureChunk(int chunkX, int chunkZ, + StructureFeature::EFeatureTypes feature) { + return chunkX == m_chunkX && chunkZ == m_chunkZ && feature == m_feature; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/StartFeature.h b/Minecraft.Client/Platform/Common/GameRules/StartFeature.h index 6a153bfcd..c7fccf882 100644 --- a/Minecraft.Client/Platform/Common/GameRules/StartFeature.h +++ b/Minecraft.Client/Platform/Common/GameRules/StartFeature.h @@ -1,22 +1,25 @@ #pragma once -//using namespace std; +// using namespace std; #include "GameRuleDefinition.h" #include "../../Minecraft.World/WorldGen/Features/StructureFeature.h" -class StartFeature : public GameRuleDefinition -{ +class StartFeature : public GameRuleDefinition { private: - int m_chunkX, m_chunkZ; - StructureFeature::EFeatureTypes m_feature; + int m_chunkX, m_chunkZ; + StructureFeature::EFeatureTypes m_feature; public: - StartFeature(); + StartFeature(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_StartFeature; } - - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_StartFeature; + } - bool isFeatureChunk(int chunkX, int chunkZ, StructureFeature::EFeatureTypes feature); + virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); + + bool isFeatureChunk(int chunkX, int chunkZ, + StructureFeature::EFeatureTypes feature); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.cpp index 38ffc2768..1a160a017 100644 --- a/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.cpp @@ -7,165 +7,149 @@ #include "../../Minecraft.World/Headers/net.minecraft.world.food.h" #include "../../Minecraft.World/Headers/net.minecraft.world.item.h" -UpdatePlayerRuleDefinition::UpdatePlayerRuleDefinition() -{ - m_bUpdateHealth = m_bUpdateFood = m_bUpdateYRot = false;; - m_health = 0; - m_food = 0; - m_spawnPos = NULL; - m_yRot = 0.0f; +UpdatePlayerRuleDefinition::UpdatePlayerRuleDefinition() { + m_bUpdateHealth = m_bUpdateFood = m_bUpdateYRot = false; + ; + m_health = 0; + m_food = 0; + m_spawnPos = NULL; + m_yRot = 0.0f; } -UpdatePlayerRuleDefinition::~UpdatePlayerRuleDefinition() -{ - for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) - { - delete *it; - } +UpdatePlayerRuleDefinition::~UpdatePlayerRuleDefinition() { + for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) { + delete *it; + } } -void UpdatePlayerRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) -{ - int attrCount = 3; - if(m_bUpdateHealth) ++attrCount; - if(m_bUpdateFood) ++attrCount; - if(m_bUpdateYRot) ++attrCount; - GameRuleDefinition::writeAttributes(dos, numAttributes + attrCount ); +void UpdatePlayerRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttributes) { + int attrCount = 3; + if (m_bUpdateHealth) ++attrCount; + if (m_bUpdateFood) ++attrCount; + if (m_bUpdateYRot) ++attrCount; + GameRuleDefinition::writeAttributes(dos, numAttributes + attrCount); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX); - dos->writeUTF(_toString(m_spawnPos->x)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY); - dos->writeUTF(_toString(m_spawnPos->y)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ); - dos->writeUTF(_toString(m_spawnPos->z)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnX); + dos->writeUTF(_toString(m_spawnPos->x)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnY); + dos->writeUTF(_toString(m_spawnPos->y)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_spawnZ); + dos->writeUTF(_toString(m_spawnPos->z)); - if(m_bUpdateYRot) - { - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_yRot); - dos->writeUTF(_toString(m_yRot)); - } - if(m_bUpdateHealth) - { - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_food); - dos->writeUTF(_toString(m_health)); - } - if(m_bUpdateFood) - { - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_health); - dos->writeUTF(_toString(m_food)); - } + if (m_bUpdateYRot) { + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_yRot); + dos->writeUTF(_toString(m_yRot)); + } + if (m_bUpdateHealth) { + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_food); + dos->writeUTF(_toString(m_health)); + } + if (m_bUpdateFood) { + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_health); + dos->writeUTF(_toString(m_food)); + } } -void UpdatePlayerRuleDefinition::getChildren(std::vector *children) -{ - GameRuleDefinition::getChildren(children); - for(AUTO_VAR(it, m_items.begin()); it!=m_items.end(); it++) - children->push_back(*it); +void UpdatePlayerRuleDefinition::getChildren( + std::vector* children) { + GameRuleDefinition::getChildren(children); + for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); it++) + children->push_back(*it); } -GameRuleDefinition *UpdatePlayerRuleDefinition::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ - GameRuleDefinition *rule = NULL; - if(ruleType == ConsoleGameRules::eGameRuleType_AddItem) - { - rule = new AddItemRuleDefinition(); - m_items.push_back((AddItemRuleDefinition *)rule); - } - else - { +GameRuleDefinition* UpdatePlayerRuleDefinition::addChild( + ConsoleGameRules::EGameRuleType ruleType) { + GameRuleDefinition* rule = NULL; + if (ruleType == ConsoleGameRules::eGameRuleType_AddItem) { + rule = new AddItemRuleDefinition(); + m_items.push_back((AddItemRuleDefinition*)rule); + } else { #ifndef _CONTENT_PACKAGE - wprintf(L"UpdatePlayerRuleDefinition: Attempted to add invalid child rule - %d\n", ruleType ); + wprintf( + L"UpdatePlayerRuleDefinition: Attempted to add invalid child rule " + L"- %d\n", + ruleType); #endif - } - return rule; + } + return rule; } -void UpdatePlayerRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"spawnX") == 0) - { - if(m_spawnPos == NULL) m_spawnPos = new Pos(); - int value = _fromString(attributeValue); - m_spawnPos->x = value; - app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnX=%d\n",value); - } - else if(attributeName.compare(L"spawnY") == 0) - { - if(m_spawnPos == NULL) m_spawnPos = new Pos(); - int value = _fromString(attributeValue); - m_spawnPos->y = value; - app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnY=%d\n",value); - } - else if(attributeName.compare(L"spawnZ") == 0) - { - if(m_spawnPos == NULL) m_spawnPos = new Pos(); - int value = _fromString(attributeValue); - m_spawnPos->z = value; - app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter spawnZ=%d\n",value); - } - else if(attributeName.compare(L"health") == 0) - { - int value = _fromString(attributeValue); - m_health = value; - m_bUpdateHealth = true; - app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter health=%d\n",value); - } - else if(attributeName.compare(L"food") == 0) - { - int value = _fromString(attributeValue); - m_food = value; - m_bUpdateFood = true; - app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter health=%d\n",value); - } - else if(attributeName.compare(L"yRot") == 0) - { - float value = _fromString(attributeValue); - m_yRot = value; - m_bUpdateYRot = true; - app.DebugPrintf("UpdatePlayerRuleDefinition: Adding parameter yRot=%f\n",value); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void UpdatePlayerRuleDefinition::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"spawnX") == 0) { + if (m_spawnPos == NULL) m_spawnPos = new Pos(); + int value = _fromString(attributeValue); + m_spawnPos->x = value; + app.DebugPrintf( + "UpdatePlayerRuleDefinition: Adding parameter spawnX=%d\n", value); + } else if (attributeName.compare(L"spawnY") == 0) { + if (m_spawnPos == NULL) m_spawnPos = new Pos(); + int value = _fromString(attributeValue); + m_spawnPos->y = value; + app.DebugPrintf( + "UpdatePlayerRuleDefinition: Adding parameter spawnY=%d\n", value); + } else if (attributeName.compare(L"spawnZ") == 0) { + if (m_spawnPos == NULL) m_spawnPos = new Pos(); + int value = _fromString(attributeValue); + m_spawnPos->z = value; + app.DebugPrintf( + "UpdatePlayerRuleDefinition: Adding parameter spawnZ=%d\n", value); + } else if (attributeName.compare(L"health") == 0) { + int value = _fromString(attributeValue); + m_health = value; + m_bUpdateHealth = true; + app.DebugPrintf( + "UpdatePlayerRuleDefinition: Adding parameter health=%d\n", value); + } else if (attributeName.compare(L"food") == 0) { + int value = _fromString(attributeValue); + m_food = value; + m_bUpdateFood = true; + app.DebugPrintf( + "UpdatePlayerRuleDefinition: Adding parameter health=%d\n", value); + } else if (attributeName.compare(L"yRot") == 0) { + float value = _fromString(attributeValue); + m_yRot = value; + m_bUpdateYRot = true; + app.DebugPrintf( + "UpdatePlayerRuleDefinition: Adding parameter yRot=%f\n", value); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -void UpdatePlayerRuleDefinition::postProcessPlayer(std::shared_ptr player) -{ - if(m_bUpdateHealth) - { - player->lastHealth = m_health; - player->setHealth(m_health); - } +void UpdatePlayerRuleDefinition::postProcessPlayer( + std::shared_ptr player) { + if (m_bUpdateHealth) { + player->lastHealth = m_health; + player->setHealth(m_health); + } - if(m_bUpdateFood) - { - player->getFoodData()->setFoodLevel(m_food); - } + if (m_bUpdateFood) { + player->getFoodData()->setFoodLevel(m_food); + } - double x = player->x; - double y = player->y; - double z = player->z; - float yRot = player->yRot; - float xRot = player->xRot; - if(m_spawnPos != NULL) - { - x = m_spawnPos->x; - y = m_spawnPos->y; - z = m_spawnPos->z; - } + double x = player->x; + double y = player->y; + double z = player->z; + float yRot = player->yRot; + float xRot = player->xRot; + if (m_spawnPos != NULL) { + x = m_spawnPos->x; + y = m_spawnPos->y; + z = m_spawnPos->z; + } - if(m_bUpdateYRot) - { - yRot = m_yRot; - } + if (m_bUpdateYRot) { + yRot = m_yRot; + } - if(m_spawnPos != NULL || m_bUpdateYRot) player->absMoveTo(x,y,z,yRot,xRot); + if (m_spawnPos != NULL || m_bUpdateYRot) + player->absMoveTo(x, y, z, yRot, xRot); - for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) - { - AddItemRuleDefinition *addItem = *it; + for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) { + AddItemRuleDefinition* addItem = *it; - addItem->addItemToContainer(player->inventory, -1); - } + addItem->addItemToContainer(player->inventory, -1); + } } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.h index 0ac062dd7..5f768ff35 100644 --- a/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/UpdatePlayerRuleDefinition.h @@ -1,33 +1,37 @@ #pragma once -//using namespace std; +// using namespace std; #include "GameRuleDefinition.h" class AddItemRuleDefinition; class Pos; -class UpdatePlayerRuleDefinition : public GameRuleDefinition -{ +class UpdatePlayerRuleDefinition : public GameRuleDefinition { private: - std::vector m_items; + std::vector m_items; - bool m_bUpdateHealth, m_bUpdateFood, m_bUpdateYRot, m_bUpdateInventory; - int m_health; - int m_food; - Pos *m_spawnPos; - float m_yRot; + bool m_bUpdateHealth, m_bUpdateFood, m_bUpdateYRot, m_bUpdateInventory; + int m_health; + int m_food; + Pos* m_spawnPos; + float m_yRot; public: - UpdatePlayerRuleDefinition(); - ~UpdatePlayerRuleDefinition(); + UpdatePlayerRuleDefinition(); + ~UpdatePlayerRuleDefinition(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_UpdatePlayerRule; } - - virtual void getChildren(std::vector *children); - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_UpdatePlayerRule; + } - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual void getChildren(std::vector* children); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); - virtual void postProcessPlayer(std::shared_ptr player); + virtual void writeAttributes(DataOutputStream* dos, + unsigned int numAttributes); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); + + virtual void postProcessPlayer(std::shared_ptr player); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.cpp b/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.cpp index 5b775ea81..3ea08b987 100644 --- a/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.cpp @@ -2,81 +2,75 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "UseTileRuleDefinition.h" -UseTileRuleDefinition::UseTileRuleDefinition() -{ - m_tileId = -1; - m_useCoords = false; +UseTileRuleDefinition::UseTileRuleDefinition() { + m_tileId = -1; + m_useCoords = false; } -void UseTileRuleDefinition::writeAttributes(DataOutputStream *dos, unsigned int numAttributes) -{ - GameRuleDefinition::writeAttributes(dos, numAttributes + 5); +void UseTileRuleDefinition::writeAttributes(DataOutputStream* dos, + unsigned int numAttributes) { + GameRuleDefinition::writeAttributes(dos, numAttributes + 5); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId); - dos->writeUTF(_toString(m_tileId)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_tileId); + dos->writeUTF(_toString(m_tileId)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_useCoords); - dos->writeUTF(_toString(m_useCoords)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_useCoords); + dos->writeUTF(_toString(m_useCoords)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); - dos->writeUTF(_toString(m_coordinates.x)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); + dos->writeUTF(_toString(m_coordinates.x)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); - dos->writeUTF(_toString(m_coordinates.y)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); + dos->writeUTF(_toString(m_coordinates.y)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); - dos->writeUTF(_toString(m_coordinates.z)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); + dos->writeUTF(_toString(m_coordinates.z)); } -void UseTileRuleDefinition::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"tileId") == 0) - { - m_tileId = _fromString(attributeValue); - app.DebugPrintf("UseTileRule: Adding parameter tileId=%d\n",m_tileId); - } - else if(attributeName.compare(L"useCoords") == 0) - { - m_useCoords = _fromString(attributeValue); - app.DebugPrintf("UseTileRule: Adding parameter useCoords=%s\n",m_useCoords?"TRUE":"FALSE"); - } - else if(attributeName.compare(L"x") == 0) - { - m_coordinates.x = _fromString(attributeValue); - app.DebugPrintf("UseTileRule: Adding parameter x=%d\n",m_coordinates.x); - } - else if(attributeName.compare(L"y") == 0) - { - m_coordinates.y = _fromString(attributeValue); - app.DebugPrintf("UseTileRule: Adding parameter y=%d\n",m_coordinates.y); - } - else if(attributeName.compare(L"z") == 0) - { - m_coordinates.z = _fromString(attributeValue); - app.DebugPrintf("UseTileRule: Adding parameter z=%d\n",m_coordinates.z); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void UseTileRuleDefinition::addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue) { + if (attributeName.compare(L"tileId") == 0) { + m_tileId = _fromString(attributeValue); + app.DebugPrintf("UseTileRule: Adding parameter tileId=%d\n", m_tileId); + } else if (attributeName.compare(L"useCoords") == 0) { + m_useCoords = _fromString(attributeValue); + app.DebugPrintf("UseTileRule: Adding parameter useCoords=%s\n", + m_useCoords ? "TRUE" : "FALSE"); + } else if (attributeName.compare(L"x") == 0) { + m_coordinates.x = _fromString(attributeValue); + app.DebugPrintf("UseTileRule: Adding parameter x=%d\n", + m_coordinates.x); + } else if (attributeName.compare(L"y") == 0) { + m_coordinates.y = _fromString(attributeValue); + app.DebugPrintf("UseTileRule: Adding parameter y=%d\n", + m_coordinates.y); + } else if (attributeName.compare(L"z") == 0) { + m_coordinates.z = _fromString(attributeValue); + app.DebugPrintf("UseTileRule: Adding parameter z=%d\n", + m_coordinates.z); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -bool UseTileRuleDefinition::onUseTile(GameRule *rule, int tileId, int x, int y, int z) -{ - bool statusChanged = false; - if( m_tileId == tileId ) - { - if( !m_useCoords || (m_coordinates.x == x && m_coordinates.y == y && m_coordinates.z == z) ) - { - if(!getComplete(rule)) - { - statusChanged = true; - setComplete(rule,true); - app.DebugPrintf("Completed UseTileRule with info - t:%d, coords:%s, x:%d, y:%d, z:%d\n", m_tileId,m_useCoords?"TRUE":"FALSE",m_coordinates.x,m_coordinates.y,m_coordinates.z); +bool UseTileRuleDefinition::onUseTile(GameRule* rule, int tileId, int x, int y, + int z) { + bool statusChanged = false; + if (m_tileId == tileId) { + if (!m_useCoords || (m_coordinates.x == x && m_coordinates.y == y && + m_coordinates.z == z)) { + if (!getComplete(rule)) { + statusChanged = true; + setComplete(rule, true); + app.DebugPrintf( + "Completed UseTileRule with info - t:%d, coords:%s, x:%d, " + "y:%d, z:%d\n", + m_tileId, m_useCoords ? "TRUE" : "FALSE", m_coordinates.x, + m_coordinates.y, m_coordinates.z); - // Send a packet or some other announcement here - } - } - } - return statusChanged; + // Send a packet or some other announcement here + } + } + } + return statusChanged; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.h b/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.h index ee047d96b..d4b3e2eff 100644 --- a/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.h +++ b/Minecraft.Client/Platform/Common/GameRules/UseTileRuleDefinition.h @@ -1,24 +1,27 @@ #pragma once -//using namespace std; +// using namespace std; #include "GameRuleDefinition.h" #include "../../Minecraft.World/Util/Pos.h" -class UseTileRuleDefinition : public GameRuleDefinition -{ +class UseTileRuleDefinition : public GameRuleDefinition { private: - // These values should map directly to the xsd definition for this Rule - int m_tileId; - bool m_useCoords; - Pos m_coordinates; + // These values should map directly to the xsd definition for this Rule + int m_tileId; + bool m_useCoords; + Pos m_coordinates; public: - UseTileRuleDefinition(); + UseTileRuleDefinition(); - ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_UseTileRule; } + ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_UseTileRule; + } - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); - - virtual bool onUseTile(GameRule *rule, int tileId, int x, int y, int z); + virtual void writeAttributes(DataOutputStream* dos, + unsigned int numAttributes); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); + + virtual bool onUseTile(GameRule* rule, int tileId, int x, int y, int z); }; diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.cpp b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.cpp index a16822fe9..39afbe7f4 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.cpp @@ -3,102 +3,95 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h" -XboxStructureActionGenerateBox::XboxStructureActionGenerateBox() -{ - m_x0 = m_y0 = m_z0 = m_x1 = m_y1 = m_z1 = m_edgeTile = m_fillTile = 0; - m_skipAir = false; +XboxStructureActionGenerateBox::XboxStructureActionGenerateBox() { + m_x0 = m_y0 = m_z0 = m_x1 = m_y1 = m_z1 = m_edgeTile = m_fillTile = 0; + m_skipAir = false; } -void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 9); +void XboxStructureActionGenerateBox::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 9); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0); - dos->writeUTF(_toString(m_x0)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0); - dos->writeUTF(_toString(m_y0)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0); - dos->writeUTF(_toString(m_z0)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x0); + dos->writeUTF(_toString(m_x0)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y0); + dos->writeUTF(_toString(m_y0)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z0); + dos->writeUTF(_toString(m_z0)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1); - dos->writeUTF(_toString(m_x1)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1); - dos->writeUTF(_toString(m_y1)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1); - dos->writeUTF(_toString(m_z1)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x1); + dos->writeUTF(_toString(m_x1)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y1); + dos->writeUTF(_toString(m_y1)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z1); + dos->writeUTF(_toString(m_z1)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_edgeTile); - dos->writeUTF(_toString(m_edgeTile)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_fillTile); - dos->writeUTF(_toString(m_fillTile)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_skipAir); - dos->writeUTF(_toString(m_skipAir)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_edgeTile); + dos->writeUTF(_toString(m_edgeTile)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_fillTile); + dos->writeUTF(_toString(m_fillTile)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_skipAir); + dos->writeUTF(_toString(m_skipAir)); } -void XboxStructureActionGenerateBox::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"x0") == 0) - { - int value = _fromString(attributeValue); - m_x0 = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter x0=%d\n",m_x0); - } - else if(attributeName.compare(L"y0") == 0) - { - int value = _fromString(attributeValue); - m_y0 = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter y0=%d\n",m_y0); - } - else if(attributeName.compare(L"z0") == 0) - { - int value = _fromString(attributeValue); - m_z0 = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter z0=%d\n",m_z0); - } - else if(attributeName.compare(L"x1") == 0) - { - int value = _fromString(attributeValue); - m_x1 = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter x1=%d\n",m_x1); - } - else if(attributeName.compare(L"y1") == 0) - { - int value = _fromString(attributeValue); - m_y1 = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter y1=%d\n",m_y1); - } - else if(attributeName.compare(L"z1") == 0) - { - int value = _fromString(attributeValue); - m_z1 = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter z1=%d\n",m_z1); - } - else if(attributeName.compare(L"edgeTile") == 0) - { - int value = _fromString(attributeValue); - m_edgeTile = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter edgeTile=%d\n",m_edgeTile); - } - else if(attributeName.compare(L"fillTile") == 0) - { - int value = _fromString(attributeValue); - m_fillTile = value; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter fillTile=%d\n",m_fillTile); - } - else if(attributeName.compare(L"skipAir") == 0) - { - if(attributeValue.compare(L"true") == 0) m_skipAir = true; - app.DebugPrintf("XboxStructureActionGenerateBox: Adding parameter skipAir=%s\n",m_skipAir?"TRUE":"FALSE"); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void XboxStructureActionGenerateBox::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"x0") == 0) { + int value = _fromString(attributeValue); + m_x0 = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter x0=%d\n", m_x0); + } else if (attributeName.compare(L"y0") == 0) { + int value = _fromString(attributeValue); + m_y0 = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter y0=%d\n", m_y0); + } else if (attributeName.compare(L"z0") == 0) { + int value = _fromString(attributeValue); + m_z0 = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter z0=%d\n", m_z0); + } else if (attributeName.compare(L"x1") == 0) { + int value = _fromString(attributeValue); + m_x1 = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter x1=%d\n", m_x1); + } else if (attributeName.compare(L"y1") == 0) { + int value = _fromString(attributeValue); + m_y1 = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter y1=%d\n", m_y1); + } else if (attributeName.compare(L"z1") == 0) { + int value = _fromString(attributeValue); + m_z1 = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter z1=%d\n", m_z1); + } else if (attributeName.compare(L"edgeTile") == 0) { + int value = _fromString(attributeValue); + m_edgeTile = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter edgeTile=%d\n", + m_edgeTile); + } else if (attributeName.compare(L"fillTile") == 0) { + int value = _fromString(attributeValue); + m_fillTile = value; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter fillTile=%d\n", + m_fillTile); + } else if (attributeName.compare(L"skipAir") == 0) { + if (attributeValue.compare(L"true") == 0) m_skipAir = true; + app.DebugPrintf( + "XboxStructureActionGenerateBox: Adding parameter skipAir=%s\n", + m_skipAir ? "TRUE" : "FALSE"); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -bool XboxStructureActionGenerateBox::generateBoxInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) -{ - app.DebugPrintf("XboxStructureActionGenerateBox - generating a box\n"); - structure->generateBox(level,chunkBB,m_x0,m_y0,m_z0,m_x1,m_y1,m_z1,m_edgeTile,m_fillTile,m_skipAir); - return true; +bool XboxStructureActionGenerateBox::generateBoxInLevel( + StructurePiece* structure, Level* level, BoundingBox* chunkBB) { + app.DebugPrintf("XboxStructureActionGenerateBox - generating a box\n"); + structure->generateBox(level, chunkBB, m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, + m_edgeTile, m_fillTile, m_skipAir); + return true; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.h b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.h index 44ff199c9..7625f141c 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.h +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionGenerateBox.h @@ -5,22 +5,26 @@ class StructurePiece; class Level; class BoundingBox; -class XboxStructureActionGenerateBox : public ConsoleGenerateStructureAction -{ +class XboxStructureActionGenerateBox : public ConsoleGenerateStructureAction { private: - int m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, m_edgeTile, m_fillTile; - bool m_skipAir; + int m_x0, m_y0, m_z0, m_x1, m_y1, m_z1, m_edgeTile, m_fillTile; + bool m_skipAir; + public: - XboxStructureActionGenerateBox(); + XboxStructureActionGenerateBox(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_GenerateBox; } + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_GenerateBox; + } - virtual int getEndX() { return m_x1; } - virtual int getEndY() { return m_y1; } - virtual int getEndZ() { return m_z1; } + virtual int getEndX() { return m_x1; } + virtual int getEndY() { return m_y1; } + virtual int getEndZ() { return m_z1; } - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - bool generateBoxInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); + bool generateBoxInLevel(StructurePiece* structure, Level* level, + BoundingBox* chunkBB); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.cpp b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.cpp index dcc5d59ed..b98d4a974 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.cpp @@ -3,70 +3,65 @@ #include "../../Minecraft.World/Util/StringHelpers.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.levelgen.structure.h" -XboxStructureActionPlaceBlock::XboxStructureActionPlaceBlock() -{ - m_x = m_y = m_z = m_tile = m_data = 0; +XboxStructureActionPlaceBlock::XboxStructureActionPlaceBlock() { + m_x = m_y = m_z = m_tile = m_data = 0; } -void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 5); +void XboxStructureActionPlaceBlock::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + ConsoleGenerateStructureAction::writeAttributes(dos, numAttrs + 5); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); - dos->writeUTF(_toString(m_x)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); - dos->writeUTF(_toString(m_y)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); - dos->writeUTF(_toString(m_z)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_x); + dos->writeUTF(_toString(m_x)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_y); + dos->writeUTF(_toString(m_y)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_z); + dos->writeUTF(_toString(m_z)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_data); - dos->writeUTF(_toString(m_data)); - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_block); - dos->writeUTF(_toString(m_tile)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_data); + dos->writeUTF(_toString(m_data)); + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_block); + dos->writeUTF(_toString(m_tile)); } - -void XboxStructureActionPlaceBlock::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"x") == 0) - { - int value = _fromString(attributeValue); - m_x = value; - app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter x=%d\n",m_x); - } - else if(attributeName.compare(L"y") == 0) - { - int value = _fromString(attributeValue); - m_y = value; - app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter y=%d\n",m_y); - } - else if(attributeName.compare(L"z") == 0) - { - int value = _fromString(attributeValue); - m_z = value; - app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter z=%d\n",m_z); - } - else if(attributeName.compare(L"block") == 0) - { - int value = _fromString(attributeValue); - m_tile = value; - app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter block=%d\n",m_tile); - } - else if(attributeName.compare(L"data") == 0) - { - int value = _fromString(attributeValue); - m_data = value; - app.DebugPrintf("XboxStructureActionPlaceBlock: Adding parameter data=%d\n",m_data); - } - else - { - GameRuleDefinition::addAttribute(attributeName, attributeValue); - } +void XboxStructureActionPlaceBlock::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"x") == 0) { + int value = _fromString(attributeValue); + m_x = value; + app.DebugPrintf( + "XboxStructureActionPlaceBlock: Adding parameter x=%d\n", m_x); + } else if (attributeName.compare(L"y") == 0) { + int value = _fromString(attributeValue); + m_y = value; + app.DebugPrintf( + "XboxStructureActionPlaceBlock: Adding parameter y=%d\n", m_y); + } else if (attributeName.compare(L"z") == 0) { + int value = _fromString(attributeValue); + m_z = value; + app.DebugPrintf( + "XboxStructureActionPlaceBlock: Adding parameter z=%d\n", m_z); + } else if (attributeName.compare(L"block") == 0) { + int value = _fromString(attributeValue); + m_tile = value; + app.DebugPrintf( + "XboxStructureActionPlaceBlock: Adding parameter block=%d\n", + m_tile); + } else if (attributeName.compare(L"data") == 0) { + int value = _fromString(attributeValue); + m_data = value; + app.DebugPrintf( + "XboxStructureActionPlaceBlock: Adding parameter data=%d\n", + m_data); + } else { + GameRuleDefinition::addAttribute(attributeName, attributeValue); + } } -bool XboxStructureActionPlaceBlock::placeBlockInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) -{ - app.DebugPrintf("XboxStructureActionPlaceBlock - placing a block\n"); - structure->placeBlock(level,m_tile,m_data,m_x,m_y,m_z,chunkBB); - return true; +bool XboxStructureActionPlaceBlock::placeBlockInLevel(StructurePiece* structure, + Level* level, + BoundingBox* chunkBB) { + app.DebugPrintf("XboxStructureActionPlaceBlock - placing a block\n"); + structure->placeBlock(level, m_tile, m_data, m_x, m_y, m_z, chunkBB); + return true; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.h b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.h index 4101028a0..63a4b6754 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.h +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceBlock.h @@ -5,21 +5,25 @@ class StructurePiece; class Level; class BoundingBox; -class XboxStructureActionPlaceBlock : public ConsoleGenerateStructureAction -{ +class XboxStructureActionPlaceBlock : public ConsoleGenerateStructureAction { protected: - int m_x, m_y, m_z, m_tile, m_data; + int m_x, m_y, m_z, m_tile, m_data; + public: - XboxStructureActionPlaceBlock(); + XboxStructureActionPlaceBlock(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceBlock; } + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_PlaceBlock; + } - virtual int getEndX() { return m_x; } - virtual int getEndY() { return m_y; } - virtual int getEndZ() { return m_z; } + virtual int getEndX() { return m_x; } + virtual int getEndY() { return m_y; } + virtual int getEndZ() { return m_z; } - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); - bool placeBlockInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); + bool placeBlockInLevel(StructurePiece* structure, Level* level, + BoundingBox* chunkBB); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.cpp b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.cpp index 04606e7ca..ba7af8415 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.cpp @@ -7,93 +7,94 @@ #include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.h" #include "../../Minecraft.World/Headers/net.minecraft.world.inventory.h" -XboxStructureActionPlaceContainer::XboxStructureActionPlaceContainer() -{ - m_tile = Tile::chest_Id; +XboxStructureActionPlaceContainer::XboxStructureActionPlaceContainer() { + m_tile = Tile::chest_Id; } -XboxStructureActionPlaceContainer::~XboxStructureActionPlaceContainer() -{ - for(AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) - { - delete *it; - } +XboxStructureActionPlaceContainer::~XboxStructureActionPlaceContainer() { + for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); ++it) { + delete *it; + } } // 4J-JEV: Super class handles attr-facing fine. -//void XboxStructureActionPlaceContainer::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) - +// void XboxStructureActionPlaceContainer::writeAttributes(DataOutputStream +// *dos, unsigned int numAttrs) -void XboxStructureActionPlaceContainer::getChildren(std::vector *children) -{ - XboxStructureActionPlaceBlock::getChildren(children); - for(AUTO_VAR(it, m_items.begin()); it!=m_items.end(); it++) - children->push_back( *it ); +void XboxStructureActionPlaceContainer::getChildren( + std::vector* children) { + XboxStructureActionPlaceBlock::getChildren(children); + for (AUTO_VAR(it, m_items.begin()); it != m_items.end(); it++) + children->push_back(*it); } -GameRuleDefinition *XboxStructureActionPlaceContainer::addChild(ConsoleGameRules::EGameRuleType ruleType) -{ - GameRuleDefinition *rule = NULL; - if(ruleType == ConsoleGameRules::eGameRuleType_AddItem) - { - rule = new AddItemRuleDefinition(); - m_items.push_back((AddItemRuleDefinition *)rule); - } - else - { +GameRuleDefinition* XboxStructureActionPlaceContainer::addChild( + ConsoleGameRules::EGameRuleType ruleType) { + GameRuleDefinition* rule = NULL; + if (ruleType == ConsoleGameRules::eGameRuleType_AddItem) { + rule = new AddItemRuleDefinition(); + m_items.push_back((AddItemRuleDefinition*)rule); + } else { #ifndef _CONTENT_PACKAGE - wprintf(L"XboxStructureActionPlaceContainer: Attempted to add invalid child rule - %d\n", ruleType ); + wprintf( + L"XboxStructureActionPlaceContainer: Attempted to add invalid " + L"child rule - %d\n", + ruleType); #endif - } - return rule; + } + return rule; } -void XboxStructureActionPlaceContainer::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"facing") == 0) - { - int value = _fromString(attributeValue); - m_data = value; - app.DebugPrintf("XboxStructureActionPlaceContainer: Adding parameter facing=%d\n",m_data); - } - else - { - XboxStructureActionPlaceBlock::addAttribute(attributeName, attributeValue); - } +void XboxStructureActionPlaceContainer::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"facing") == 0) { + int value = _fromString(attributeValue); + m_data = value; + app.DebugPrintf( + "XboxStructureActionPlaceContainer: Adding parameter facing=%d\n", + m_data); + } else { + XboxStructureActionPlaceBlock::addAttribute(attributeName, + attributeValue); + } } -bool XboxStructureActionPlaceContainer::placeContainerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) -{ - int worldX = structure->getWorldX( m_x, m_z ); - int worldY = structure->getWorldY( m_y ); - int worldZ = structure->getWorldZ( m_x, m_z ); +bool XboxStructureActionPlaceContainer::placeContainerInLevel( + StructurePiece* structure, Level* level, BoundingBox* chunkBB) { + int worldX = structure->getWorldX(m_x, m_z); + int worldY = structure->getWorldY(m_y); + int worldZ = structure->getWorldZ(m_x, m_z); - if ( chunkBB->isInside( worldX, worldY, worldZ ) ) - { - if ( level->getTileEntity( worldX, worldY, worldZ ) != NULL ) - { - // Remove the current tile entity - level->removeTileEntity( worldX, worldY, worldZ ); - level->setTile( worldX, worldY, worldZ, 0 ); - } + if (chunkBB->isInside(worldX, worldY, worldZ)) { + if (level->getTileEntity(worldX, worldY, worldZ) != NULL) { + // Remove the current tile entity + level->removeTileEntity(worldX, worldY, worldZ); + level->setTile(worldX, worldY, worldZ, 0); + } - level->setTile( worldX, worldY, worldZ, m_tile ); - std::shared_ptr container = std::dynamic_pointer_cast(level->getTileEntity( worldX, worldY, worldZ )); - - app.DebugPrintf("XboxStructureActionPlaceContainer - placing a container at (%d,%d,%d)\n", worldX, worldY, worldZ); - if ( container != NULL ) - { - level->setData( worldX, worldY, worldZ, m_data); - // Add items - int slotId = 0; - for(AUTO_VAR(it, m_items.begin()); it != m_items.end() && (slotId < container->getContainerSize()); ++it, ++slotId ) - { - AddItemRuleDefinition *addItem = *it; + level->setTile(worldX, worldY, worldZ, m_tile); + std::shared_ptr container = + std::dynamic_pointer_cast( + level->getTileEntity(worldX, worldY, worldZ)); - addItem->addItemToContainer(container,slotId); - } - } - return true; - } - return false; + app.DebugPrintf( + "XboxStructureActionPlaceContainer - placing a container at " + "(%d,%d,%d)\n", + worldX, worldY, worldZ); + if (container != NULL) { + level->setData(worldX, worldY, worldZ, m_data); + // Add items + int slotId = 0; + for (AUTO_VAR(it, m_items.begin()); + it != m_items.end() && + (slotId < container->getContainerSize()); + ++it, ++slotId) { + AddItemRuleDefinition* addItem = *it; + + addItem->addItemToContainer(container, slotId); + } + } + return true; + } + return false; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.h b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.h index f9950e1ba..7d2265b98 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.h +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceContainer.h @@ -7,23 +7,29 @@ class StructurePiece; class Level; class BoundingBox; -class XboxStructureActionPlaceContainer : public XboxStructureActionPlaceBlock -{ +class XboxStructureActionPlaceContainer : public XboxStructureActionPlaceBlock { private: - std::vector m_items; + std::vector m_items; + public: - XboxStructureActionPlaceContainer(); - ~XboxStructureActionPlaceContainer(); + XboxStructureActionPlaceContainer(); + ~XboxStructureActionPlaceContainer(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceContainer; } - - virtual void getChildren(std::vector *children); - virtual GameRuleDefinition *addChild(ConsoleGameRules::EGameRuleType ruleType); - - // 4J-JEV: Super class handles attr-facing fine. - //virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttributes); - - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_PlaceContainer; + } - bool placeContainerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); + virtual void getChildren(std::vector* children); + virtual GameRuleDefinition* addChild( + ConsoleGameRules::EGameRuleType ruleType); + + // 4J-JEV: Super class handles attr-facing fine. + // virtual void writeAttributes(DataOutputStream *dos, unsigned int + // numAttributes); + + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); + + bool placeContainerInLevel(StructurePiece* structure, Level* level, + BoundingBox* chunkBB); }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.cpp b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.cpp index af33a418d..e129ef5e0 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.cpp +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.cpp @@ -5,65 +5,64 @@ #include "../../Minecraft.World/Headers/net.minecraft.world.level.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h" -XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner() -{ - m_tile = Tile::mobSpawner_Id; - m_entityId = L"Pig"; +XboxStructureActionPlaceSpawner::XboxStructureActionPlaceSpawner() { + m_tile = Tile::mobSpawner_Id; + m_entityId = L"Pig"; } -XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner() -{ +XboxStructureActionPlaceSpawner::~XboxStructureActionPlaceSpawner() {} + +void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream* dos, + unsigned int numAttrs) { + XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1); + + ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity); + dos->writeUTF(m_entityId); } -void XboxStructureActionPlaceSpawner::writeAttributes(DataOutputStream *dos, unsigned int numAttrs) -{ - XboxStructureActionPlaceBlock::writeAttributes(dos, numAttrs + 1); - - ConsoleGameRules::write(dos, ConsoleGameRules::eGameRuleAttr_entity); - dos->writeUTF(m_entityId); -} - -void XboxStructureActionPlaceSpawner::addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue) -{ - if(attributeName.compare(L"entity") == 0) - { - m_entityId = attributeValue; +void XboxStructureActionPlaceSpawner::addAttribute( + const std::wstring& attributeName, const std::wstring& attributeValue) { + if (attributeName.compare(L"entity") == 0) { + m_entityId = attributeValue; #ifndef _CONTENT_PACKAGE - wprintf(L"XboxStructureActionPlaceSpawner: Adding parameter entity=%ls\n",m_entityId.c_str()); + wprintf( + L"XboxStructureActionPlaceSpawner: Adding parameter entity=%ls\n", + m_entityId.c_str()); #endif - } - else - { - XboxStructureActionPlaceBlock::addAttribute(attributeName, attributeValue); - } + } else { + XboxStructureActionPlaceBlock::addAttribute(attributeName, + attributeValue); + } } -bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB) -{ - int worldX = structure->getWorldX( m_x, m_z ); - int worldY = structure->getWorldY( m_y ); - int worldZ = structure->getWorldZ( m_x, m_z ); +bool XboxStructureActionPlaceSpawner::placeSpawnerInLevel( + StructurePiece* structure, Level* level, BoundingBox* chunkBB) { + int worldX = structure->getWorldX(m_x, m_z); + int worldY = structure->getWorldY(m_y); + int worldZ = structure->getWorldZ(m_x, m_z); - if ( chunkBB->isInside( worldX, worldY, worldZ ) ) - { - if ( level->getTileEntity( worldX, worldY, worldZ ) != NULL ) - { - // Remove the current tile entity - level->removeTileEntity( worldX, worldY, worldZ ); - level->setTile( worldX, worldY, worldZ, 0 ); - } + if (chunkBB->isInside(worldX, worldY, worldZ)) { + if (level->getTileEntity(worldX, worldY, worldZ) != NULL) { + // Remove the current tile entity + level->removeTileEntity(worldX, worldY, worldZ); + level->setTile(worldX, worldY, worldZ, 0); + } - level->setTile( worldX, worldY, worldZ, m_tile ); - std::shared_ptr entity = std::dynamic_pointer_cast(level->getTileEntity( worldX, worldY, worldZ )); + level->setTile(worldX, worldY, worldZ, m_tile); + std::shared_ptr entity = + std::dynamic_pointer_cast( + level->getTileEntity(worldX, worldY, worldZ)); #ifndef _CONTENT_PACKAGE - wprintf(L"XboxStructureActionPlaceSpawner - placing a %ls spawner at (%d,%d,%d)\n", m_entityId.c_str(), worldX, worldY, worldZ); + wprintf( + L"XboxStructureActionPlaceSpawner - placing a %ls spawner at " + L"(%d,%d,%d)\n", + m_entityId.c_str(), worldX, worldY, worldZ); #endif - if( entity != NULL ) - { - entity->setEntityId(m_entityId); - } - return true; - } - return false; + if (entity != NULL) { + entity->setEntityId(m_entityId); + } + return true; + } + return false; } \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.h b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.h index 933a467c4..300066c22 100644 --- a/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.h +++ b/Minecraft.Client/Platform/Common/GameRules/XboxStructureActionPlaceSpawner.h @@ -7,18 +7,22 @@ class Level; class BoundingBox; class GRFObject; -class XboxStructureActionPlaceSpawner : public XboxStructureActionPlaceBlock -{ +class XboxStructureActionPlaceSpawner : public XboxStructureActionPlaceBlock { private: - std::wstring m_entityId; + std::wstring m_entityId; + public: - XboxStructureActionPlaceSpawner(); - ~XboxStructureActionPlaceSpawner(); + XboxStructureActionPlaceSpawner(); + ~XboxStructureActionPlaceSpawner(); - virtual ConsoleGameRules::EGameRuleType getActionType() { return ConsoleGameRules::eGameRuleType_PlaceSpawner; } - - virtual void writeAttributes(DataOutputStream *dos, unsigned int numAttrs); - virtual void addAttribute(const std::wstring &attributeName, const std::wstring &attributeValue); + virtual ConsoleGameRules::EGameRuleType getActionType() { + return ConsoleGameRules::eGameRuleType_PlaceSpawner; + } - bool placeSpawnerInLevel(StructurePiece *structure, Level *level, BoundingBox *chunkBB); + virtual void writeAttributes(DataOutputStream* dos, unsigned int numAttrs); + virtual void addAttribute(const std::wstring& attributeName, + const std::wstring& attributeValue); + + bool placeSpawnerInLevel(StructurePiece* structure, Level* level, + BoundingBox* chunkBB); }; \ No newline at end of file