1
0

Configurable portals

This commit is contained in:
Tiger Wang 2014-06-04 20:00:55 +01:00
parent 74cd4f5521
commit ccbf6cc446
4 changed files with 83 additions and 14 deletions

View File

@ -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;
}
}

View File

@ -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;

View File

@ -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();

View File

@ -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;