mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 22:53:37 +00:00
# Conflicts: # Minecraft.Client/Network/PlayerChunkMap.cpp # Minecraft.Client/Network/PlayerList.cpp # Minecraft.Client/Network/ServerChunkCache.cpp # Minecraft.Client/Platform/Common/Consoles_App.cpp # Minecraft.Client/Platform/Common/DLC/DLCManager.cpp # Minecraft.Client/Platform/Common/GameRules/LevelGenerationOptions.cpp # Minecraft.Client/Platform/Common/GameRules/LevelRuleset.cpp # Minecraft.Client/Platform/Common/Tutorial/Tutorial.cpp # Minecraft.Client/Platform/Common/Tutorial/TutorialTask.cpp # Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp # Minecraft.Client/Platform/Common/UI/UIComponent_Panorama.cpp # Minecraft.Client/Platform/Common/UI/UIController.cpp # Minecraft.Client/Platform/Common/UI/UIController.h # Minecraft.Client/Platform/Extrax64Stubs.cpp # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Input.h # Minecraft.Client/Platform/Windows64/4JLibs/inc/4J_Storage.h # Minecraft.Client/Player/EntityTracker.cpp # Minecraft.Client/Player/ServerPlayer.cpp # Minecraft.Client/Rendering/EntityRenderers/PlayerRenderer.cpp # Minecraft.Client/Textures/Packs/DLCTexturePack.cpp # Minecraft.Client/Textures/Stitching/StitchedTexture.cpp # Minecraft.Client/Textures/Stitching/TextureMap.cpp # Minecraft.Client/Textures/Textures.cpp # Minecraft.World/Blocks/NotGateTile.cpp # Minecraft.World/Blocks/PressurePlateTile.cpp # Minecraft.World/Blocks/TileEntities/PotionBrewing.cpp # Minecraft.World/Enchantments/EnchantmentHelper.cpp # Minecraft.World/Entities/HangingEntity.cpp # Minecraft.World/Entities/LeashFenceKnotEntity.cpp # Minecraft.World/Entities/LivingEntity.cpp # Minecraft.World/Entities/Mobs/Boat.cpp # Minecraft.World/Entities/Mobs/Minecart.cpp # Minecraft.World/Entities/Mobs/Witch.cpp # Minecraft.World/Entities/SyncedEntityData.cpp # Minecraft.World/Items/LeashItem.cpp # Minecraft.World/Items/PotionItem.cpp # Minecraft.World/Level/BaseMobSpawner.cpp # Minecraft.World/Level/CustomLevelSource.cpp # Minecraft.World/Level/Level.cpp # Minecraft.World/Level/Storage/DirectoryLevelStorage.cpp # Minecraft.World/Level/Storage/McRegionLevelStorage.cpp # Minecraft.World/Level/Storage/RegionFileCache.cpp # Minecraft.World/Player/Player.cpp # Minecraft.World/WorldGen/Biomes/BiomeCache.cpp # Minecraft.World/WorldGen/Features/RandomScatteredLargeFeature.cpp # Minecraft.World/WorldGen/Layers/BiomeOverrideLayer.cpp
108 lines
3.7 KiB
C++
108 lines
3.7 KiB
C++
#include "../../Minecraft.World/Platform/stdafx.h"
|
|
#include "../../Minecraft.World/Util/StringHelpers.h"
|
|
#include "../../Minecraft.World/Headers/net.minecraft.world.item.h"
|
|
#include "CompoundGameRuleDefinition.h"
|
|
#include "ConsoleGameRules.h"
|
|
|
|
CompoundGameRuleDefinition::CompoundGameRuleDefinition() {
|
|
m_lastRuleStatusChanged = nullptr;
|
|
}
|
|
|
|
CompoundGameRuleDefinition::~CompoundGameRuleDefinition() {
|
|
for (auto it = m_children.begin(); it != m_children.end(); ++it) {
|
|
delete (*it);
|
|
}
|
|
}
|
|
|
|
void CompoundGameRuleDefinition::getChildren(
|
|
std::vector<GameRuleDefinition*>* children) {
|
|
GameRuleDefinition::getChildren(children);
|
|
for (auto it = m_children.begin(); it != m_children.end(); it++)
|
|
children->push_back(*it);
|
|
}
|
|
|
|
GameRuleDefinition* CompoundGameRuleDefinition::addChild(
|
|
ConsoleGameRules::EGameRuleType ruleType) {
|
|
GameRuleDefinition* rule = nullptr;
|
|
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 "
|
|
L"- %d\n",
|
|
ruleType);
|
|
#endif
|
|
}
|
|
if (rule != nullptr) m_children.push_back(rule);
|
|
return rule;
|
|
}
|
|
|
|
void CompoundGameRuleDefinition::populateGameRule(
|
|
GameRulesInstance::EGameRulesInstanceType type, GameRule* rule) {
|
|
GameRule* newRule = nullptr;
|
|
int i = 0;
|
|
for (auto 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;
|
|
|
|
// Somehow add the newRule to the current rule
|
|
rule->setParameter(L"rule" + _toString<int>(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 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<ItemInstance> item) {
|
|
bool statusChanged = false;
|
|
for (auto 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> player) {
|
|
for (auto it = m_children.begin(); it != m_children.end(); ++it) {
|
|
(*it)->postProcessPlayer(player);
|
|
}
|
|
} |