From e5cfe0cd96a67b493b91e7576ec0341452c23855 Mon Sep 17 00:00:00 2001 From: STRWarrior Date: Sat, 13 Jun 2015 14:57:51 +0200 Subject: Added a size check for portals. Made the portal size configurable Alpha-sorted SetXYZNetherPortalXYZ functions --- src/Blocks/BlockFire.h | 14 ++++++++++++++ src/Blocks/WorldInterface.h | 12 ++++++++++++ src/World.cpp | 4 ++++ src/World.h | 18 ++++++++++++++++++ 4 files changed, 48 insertions(+) (limited to 'src') diff --git a/src/Blocks/BlockFire.h b/src/Blocks/BlockFire.h index ec752885a..3f75455da 100644 --- a/src/Blocks/BlockFire.h +++ b/src/Blocks/BlockFire.h @@ -121,6 +121,20 @@ public: } } + int PortalHeight = MaxY - Y - 1; + int PortalWidth = XZP - XZM + 1; + if ((PortalHeight < a_WorldInterface.GetMinNetherPortalHeight()) || (PortalHeight > a_WorldInterface.GetMaxNetherPortalHeight())) + { + // The portal isn't high enough, or is too high + return; + } + + if ((PortalWidth < a_WorldInterface.GetMinNetherPortalWidth()) || (PortalWidth > a_WorldInterface.GetMaxNetherPortalWidth())) + { + // The portal isn't wide enough, or is too wide + return; + } + for (int Height = Y + 1; Height <= MaxY - 1; Height++) // Loop through boundary to set portal blocks { for (int Width = XZM; Width <= XZP; Width++) diff --git a/src/Blocks/WorldInterface.h b/src/Blocks/WorldInterface.h index 44c118195..826df7034 100644 --- a/src/Blocks/WorldInterface.h +++ b/src/Blocks/WorldInterface.h @@ -55,6 +55,18 @@ public: /** Returns true if it is raining, stormy or snowing at the specified location. This takes into account biomes. */ virtual bool IsWeatherWetAt(int a_BlockX, int a_BlockZ) = 0; + /** Returns or sets the minumim or maximum netherportal width */ + virtual int GetMinNetherPortalWidth(void) const = 0; + virtual int GetMaxNetherPortalWidth(void) const = 0; + virtual void SetMinNetherPortalWidth(int a_NewMinWidth) = 0; + virtual void SetMaxNetherPortalWidth(int a_NewMaxWidth) = 0; + + /** Returns or sets the minumim or maximum netherportal height */ + virtual int GetMinNetherPortalHeight(void) const = 0; + virtual int GetMaxNetherPortalHeight(void) const = 0; + virtual void SetMinNetherPortalHeight(int a_NewMinHeight) = 0; + virtual void SetMaxNetherPortalHeight(int a_NewMaxHeight) = 0; + /** Returns the world height at the specified coords; waits for the chunk to get loaded / generated */ virtual int GetHeight(int a_BlockX, int a_BlockZ) = 0; diff --git a/src/World.cpp b/src/World.cpp index f4fd696ee..71f4aeae3 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -464,6 +464,10 @@ void cWorld::Start(void) m_bCommandBlocksEnabled = IniFile.GetValueSetB("Mechanics", "CommandBlocksEnabled", false); m_bEnabledPVP = IniFile.GetValueSetB("Mechanics", "PVPEnabled", true); m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true); + m_MinNetherPortalWidth = IniFile.GetValueSetI("Mechanics", "MinNetherPortalWidth", 2); + m_MaxNetherPortalWidth = IniFile.GetValueSetI("Mechanics", "MaxNetherPortalWidth", 21); + m_MinNetherPortalHeight = IniFile.GetValueSetI("Mechanics", "MinNetherPortalHeight", 3); + m_MaxNetherPortalHeight = IniFile.GetValueSetI("Mechanics", "MaxNetherPortalHeight", 21); m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true); m_IsDaylightCycleEnabled = IniFile.GetValueSetB("General", "IsDaylightCycleEnabled", true); int GameMode = IniFile.GetValueSetI("General", "Gamemode", (int)m_GameMode); diff --git a/src/World.h b/src/World.h index 2ea89f338..99570369b 100644 --- a/src/World.h +++ b/src/World.h @@ -713,6 +713,18 @@ public: AString GetLinkedOverworldName(void) const { return m_LinkedOverworldName; } void SetLinkedOverworldName(const AString & a_Name) { m_LinkedOverworldName = a_Name; } + /** Returns or sets the minumim or maximum netherportal width */ + virtual int GetMinNetherPortalWidth(void) const override { return m_MinNetherPortalWidth; } + virtual int GetMaxNetherPortalWidth(void) const override { return m_MaxNetherPortalWidth; } + virtual void SetMinNetherPortalWidth(int a_NewMinWidth) override { m_MinNetherPortalWidth = a_NewMinWidth; } + virtual void SetMaxNetherPortalWidth(int a_NewMaxWidth) override { m_MaxNetherPortalWidth = a_NewMaxWidth; } + + /** Returns or sets the minumim or maximum netherportal height */ + virtual int GetMinNetherPortalHeight(void) const override { return m_MinNetherPortalHeight; } + virtual int GetMaxNetherPortalHeight(void) const override { return m_MaxNetherPortalHeight; } + virtual void SetMinNetherPortalHeight(int a_NewMinHeight) override { m_MinNetherPortalHeight = a_NewMinHeight; } + virtual void SetMaxNetherPortalHeight(int a_NewMaxHeight) override { m_MaxNetherPortalHeight = a_NewMaxHeight; } + // tolua_end /** Saves all chunks immediately. Dangerous interface, may deadlock, use QueueSaveAllChunks() instead */ @@ -942,6 +954,12 @@ private: double m_SpawnY; double m_SpawnZ; + // Variables defining the minimum and maximum size for a nether portal + int m_MinNetherPortalWidth; + int m_MaxNetherPortalWidth; + int m_MinNetherPortalHeight; + int m_MaxNetherPortalHeight; + bool m_BroadcastDeathMessages; bool m_BroadcastAchievementMessages; -- cgit v1.2.3