1
0

cBlockArea: Write all present data types by default (#4252)

cBlockArea::Write now defaults to use GetDataTypes() instead of assuming all data types are present.
Fixes cuberite/WorldEdit#130
This commit is contained in:
peterbell10 2018-07-19 22:36:46 +01:00 committed by GitHub
parent 2431b077cd
commit 211cec621e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 15 deletions

View File

@ -1898,7 +1898,7 @@ return
Type = "boolean",
},
},
Notes = "Writes the area into World at the specified coords, returns true if successful. baTypes and baMetas are written.",
Notes = "Writes the area into World at the specified coords, returns true if successful. All present data types are written.",
},
{
Params =
@ -1952,7 +1952,7 @@ return
Type = "boolean",
},
},
Notes = "Writes the area into World at the specified coords, returns true if successful. baTypes and baMetas are written.",
Notes = "Writes the area into World at the specified coords, returns true if successful. All present data types are written.",
},
{
Params =

View File

@ -700,20 +700,23 @@ static int tolua_cBlockArea_Write(lua_State * a_LuaState)
// Check and get the overloaded params:
Vector3i coords;
int dataTypes = cBlockArea::baTypes | cBlockArea::baMetas | cBlockArea::baBlockEntities;
int dataTypes = 0;
auto dataTypesIdx = readVector3iOverloadParams(L, 3, coords, "coords");
L.GetStackValues(dataTypesIdx, dataTypes);
auto HasDataTypes = L.GetStackValues(dataTypesIdx, dataTypes);
// Check the dataType parameter validity:
if (!cBlockArea::IsValidDataTypeCombination(dataTypes))
if (HasDataTypes)
{
return L.ApiParamError("Invalid datatype combination (%d).", dataTypes);
}
if ((self->GetDataTypes() & dataTypes) != dataTypes)
{
return L.ApiParamError("Requesting datatypes not present in the cBlockArea. Got only 0x%02x, requested 0x%02x",
self->GetDataTypes(), dataTypes
);
if (!cBlockArea::IsValidDataTypeCombination(dataTypes))
{
return L.ApiParamError("Invalid datatype combination (%d).", dataTypes);
}
if ((self->GetDataTypes() & dataTypes) != dataTypes)
{
return L.ApiParamError("Requesting datatypes not present in the cBlockArea. Got only 0x%02x, requested 0x%02x",
self->GetDataTypes(), dataTypes
);
}
}
// Check and adjust the coord params:
@ -735,7 +738,14 @@ static int tolua_cBlockArea_Write(lua_State * a_LuaState)
}
// Do the actual write:
L.Push(self->Write(*world, coords, dataTypes));
if (HasDataTypes)
{
L.Push(self->Write(*world, coords, dataTypes));
}
else
{
L.Push(self->Write(*world, coords));
}
return 1;
}

View File

@ -120,11 +120,27 @@ public:
/** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all.
Doesn't wake up the simulators. */
bool Write(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas | baBlockEntities);
bool Write(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes);
/** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all.
Doesn't wake up the simulators. */
bool Write(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes = baTypes | baMetas | baBlockEntities);
bool Write(cForEachChunkProvider & a_ForEachChunkProvider, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ)
{
// Write all available data
return Write(a_ForEachChunkProvider, a_MinBlockX, a_MinBlockY, a_MinBlockZ, GetDataTypes());
}
/** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all.
Doesn't wake up the simulators. */
bool Write(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_MinCoords, int a_DataTypes);
/** Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all.
Doesn't wake up the simulators. */
bool Write(cForEachChunkProvider & a_ForEachChunkProvider, const Vector3i & a_MinCoords)
{
// Write all available data
return Write(a_ForEachChunkProvider, a_MinCoords.x, a_MinCoords.y, a_MinCoords.z, GetDataTypes());
}
// tolua_begin