summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-04 21:00:55 +0200
committerTiger Wang <ziwei.tiger@hotmail.co.uk>2014-06-04 21:00:55 +0200
commitccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6 (patch)
tree8b43dbe42d077c95b12171e7229ab99c32759e1a
parentSuggestions (diff)
downloadcuberite-ccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6.tar
cuberite-ccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6.tar.gz
cuberite-ccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6.tar.bz2
cuberite-ccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6.tar.lz
cuberite-ccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6.tar.xz
cuberite-ccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6.tar.zst
cuberite-ccbf6cc446ad67fbba8163d4d4d61456c1ba0bc6.zip
-rw-r--r--src/Entities/Entity.cpp45
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/World.cpp26
-rw-r--r--src/World.h24
4 files changed, 83 insertions, 14 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index 16264a608..7d9c10ec6 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -1042,6 +1042,11 @@ void cEntity::DetectCacti(void)
void cEntity::DetectPortal()
{
+ if (!GetWorld()->AreNetherPortalsEnabled() && !GetWorld()->AreEndPortalsEnabled())
+ {
+ return;
+ }
+
int X = POSX_TOINT, Y = POSY_TOINT, Z = POSZ_TOINT;
if ((Y > 0) && (Y < cChunkDef::Height))
{
@@ -1049,11 +1054,18 @@ void cEntity::DetectPortal()
{
case E_BLOCK_NETHER_PORTAL:
{
+ if (!GetWorld()->AreNetherPortalsEnabled())
+ {
+ return;
+ }
+
switch (GetWorld()->GetDimension())
{
case dimNether:
{
- AString OverworldName = GetWorld()->GetName().substr(0, GetWorld()->GetName().size() - 7);
+ cIniFile OwnIni; OwnIni.ReadFile(GetWorld()->GetIniFileName());
+ AString OverworldName = OwnIni.GetValue("General", "OverworldName", cRoot::Get()->GetDefaultWorld()->GetName());
+
cFile::CreateFolder(FILE_IO_PREFIX + OverworldName);
cIniFile File;
File.ReadFile(OverworldName + "/world.ini");
@@ -1065,14 +1077,14 @@ void cEntity::DetectPortal()
}
case dimOverworld:
{
- AString NetherWorldName = GetWorld()->GetName() + "_nether";
- cFile::CreateFolder(FILE_IO_PREFIX + NetherWorldName);
+ cFile::CreateFolder(FILE_IO_PREFIX + GetWorld()->GetNetherWorldName());
cIniFile File;
- File.ReadFile(NetherWorldName + "/world.ini");
+ File.ReadFile(GetWorld()->GetNetherWorldName() + "/world.ini");
File.SetValue("General", "Dimension", "Nether");
- File.WriteFile(NetherWorldName + "/world.ini");
+ File.SetValue("General", "OverworldName", GetWorld()->GetName());
+ File.WriteFile(GetWorld()->GetNetherWorldName() + "/world.ini");
- MoveToWorld(NetherWorldName, cRoot::Get()->CreateAndInitializeWorld(NetherWorldName));
+ MoveToWorld(GetWorld()->GetNetherWorldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetNetherWorldName()));
break;
}
default: break;
@@ -1081,11 +1093,18 @@ void cEntity::DetectPortal()
}
case E_BLOCK_END_PORTAL:
{
+ if (!GetWorld()->AreEndPortalsEnabled())
+ {
+ return;
+ }
+
switch (GetWorld()->GetDimension())
{
case dimEnd:
{
- AString OverworldName = GetWorld()->GetName().substr(0, GetWorld()->GetName().size() - 4);
+ cIniFile OwnIni; OwnIni.ReadFile(GetWorld()->GetIniFileName());
+ AString OverworldName = OwnIni.GetValue("General", "OverworldName", cRoot::Get()->GetDefaultWorld()->GetName());
+
cFile::CreateFolder(FILE_IO_PREFIX + OverworldName);
cIniFile File;
File.ReadFile(OverworldName + "/world.ini");
@@ -1103,14 +1122,14 @@ void cEntity::DetectPortal()
}
case dimOverworld:
{
- AString EndWorldName = GetWorld()->GetName() + "_end";
- cFile::CreateFolder(FILE_IO_PREFIX + EndWorldName);
+ cFile::CreateFolder(FILE_IO_PREFIX + GetWorld()->GetEndWorldName());
cIniFile File;
- File.ReadFile(EndWorldName + "/world.ini");
+ File.ReadFile(GetWorld()->GetEndWorldName() + "/world.ini");
File.SetValue("General", "Dimension", "End");
- File.WriteFile(EndWorldName + "/world.ini");
+ File.SetValue("General", "OverworldName", GetWorld()->GetName());
+ File.WriteFile(GetWorld()->GetEndWorldName() + "/world.ini");
- MoveToWorld(EndWorldName, cRoot::Get()->CreateAndInitializeWorld(EndWorldName));
+ MoveToWorld(GetWorld()->GetEndWorldName(), cRoot::Get()->CreateAndInitializeWorld(GetWorld()->GetEndWorldName()));
break;
}
default: break;
@@ -1133,7 +1152,7 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, cWorld * a_World)
World = cRoot::Get()->GetWorld(a_WorldName);
if (World == NULL)
{
- LOG("%s: Couldn't find world \"%s\".", __FUNCTION__, a_WorldName);
+ LOG("%s: Couldn't find world \"%s\".", __FUNCTION__, a_WorldName.c_str());
return false;
}
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index 8e4c89f68..eebc9ecf9 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -1610,7 +1610,7 @@ bool cPlayer::MoveToWorld(const AString & a_WorldName, cWorld * a_World)
{
GetClientHandle()->SendPlayerMoveLook();
GetClientHandle()->SendHealth();
- GetClientHandle()->SendWholeInventory((cWindow &)GetInventory());
+ GetClientHandle()->SendWholeInventory(*GetWindow());
}
return true;
diff --git a/src/World.cpp b/src/World.cpp
index 66aca83ef..345c894eb 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -66,6 +66,9 @@ const int TIME_NIGHT_END = 22812;
const int TIME_SUNRISE = 23999;
const int TIME_SPAWN_DIVISOR = 148;
+#define DEFAULT_NETHER_NAME GetName() + "_nether"
+#define DEFAULT_END_NAME GetName() + "_end"
+
@@ -566,6 +569,14 @@ void cWorld::Start(void)
m_bUseChatPrefixes = IniFile.GetValueSetB("Mechanics", "UseChatPrefixes", true);
m_VillagersShouldHarvestCrops = IniFile.GetValueSetB("Monsters", "VillagersShouldHarvestCrops", true);
int GameMode = IniFile.GetValueSetI("General", "Gamemode", (int)m_GameMode);
+
+ if ((GetDimension() != dimNether) && (GetDimension() != dimEnd))
+ {
+ m_bNetherPortalsEnabled = IniFile.GetValueSetB("General", "NetherPortalsEnabled", true);
+ m_NetherWorldName = IniFile.GetValueSet("General", "NetherWorldName", DEFAULT_NETHER_NAME);
+ m_bEndPortalsEnabled = IniFile.GetValueSetB("General", "EndPortalsEnabled", true);
+ m_EndWorldName = IniFile.GetValueSet("General", "EndWorldName", DEFAULT_END_NAME);
+ }
// Adjust the enum-backed variables into their respective bounds:
m_GameMode = (eGameMode) Clamp(GameMode, (int)gmSurvival, (int)gmAdventure);
@@ -734,6 +745,21 @@ void cWorld::Stop(void)
} // for itr - m_Clients[]
m_Clients.clear();
}
+
+ // Write settings to file; these are all plugin changeable values - keep updated!
+ cIniFile IniFile;
+ IniFile.ReadFile(m_IniFileName);
+ if ((GetDimension() != dimNether) && (GetDimension() != dimEnd))
+ {
+ IniFile.SetValueB("General", "NetherPortalsEnabled", m_bNetherPortalsEnabled);
+ IniFile.SetValue("General", "NetherWorldName", m_NetherWorldName);
+ IniFile.SetValueB("General", "EndPortalsEnabled", m_bEndPortalsEnabled);
+ IniFile.SetValue("General", "EndWorldName", m_EndWorldName);
+ }
+ IniFile.SetValueI("Physics", "TNTShrapnelLevel", (int)m_TNTShrapnelLevel);
+ IniFile.SetValueB("Mechanics", "CommandBlocksEnabled", m_bCommandBlocksEnabled);
+ IniFile.SetValueB("Mechanics", "UseChatPrefixes", m_bUseChatPrefixes);
+ IniFile.WriteFile(m_IniFileName);
m_TickThread.Stop();
m_Lighting.Stop();
diff --git a/src/World.h b/src/World.h
index e72675194..7b87a76ac 100644
--- a/src/World.h
+++ b/src/World.h
@@ -624,6 +624,18 @@ public:
bool ShouldUseChatPrefixes(void) const { return m_bUseChatPrefixes; }
void SetShouldUseChatPrefixes(bool a_Flag) { m_bUseChatPrefixes = a_Flag; }
+
+ bool AreNetherPortalsEnabled(void) const { return m_bNetherPortalsEnabled; }
+ void SetNetherPortalsEnabled(bool a_Flag) { m_bNetherPortalsEnabled = a_Flag; }
+
+ bool AreEndPortalsEnabled(void) const { return m_bEndPortalsEnabled; }
+ void SetEndPortalsEnabled(bool a_Flag) { m_bEndPortalsEnabled = a_Flag; }
+
+ AString GetNetherWorldName(void) const { return m_NetherWorldName; }
+ void SetNetherWorldName(const AString & a_Name) { m_NetherWorldName = a_Name; }
+
+ AString GetEndWorldName(void) const { return m_EndWorldName; }
+ void SetEndWorldName(const AString & a_Name) { m_EndWorldName = a_Name; }
// tolua_end
@@ -886,6 +898,18 @@ private:
See the eShrapnelLevel enumeration for details
*/
eShrapnelLevel m_TNTShrapnelLevel;
+
+ /** Whether nether portals teleport entities */
+ bool m_bNetherPortalsEnabled;
+
+ /** Whether end portals teleport entities */
+ bool m_bEndPortalsEnabled;
+
+ /** Name of the nether world */
+ AString m_NetherWorldName;
+
+ /** Name of the end world */
+ AString m_EndWorldName;
cChunkGenerator m_Generator;