1
0

Fix meta mirror (#3470)

This commit is contained in:
Mattes D 2016-12-09 12:29:04 +01:00 committed by GitHub
parent e8ea1f8cc3
commit e8fb85be88
4 changed files with 83 additions and 35 deletions

View File

@ -987,6 +987,24 @@ end;
function HandleGenRailsCmd(a_Split, a_Player)
local MAX_RAIL_META = 9
local pos = a_Player:GetPosition()
local ba = cBlockArea:new()
ba:Create(2 * MAX_RAIL_META + 3, 4, 3, cBlockArea.baTypes + cBlockArea.baMetas)
ba:FillRelCuboid(0, 2 * MAX_RAIL_META + 2, 0, 0, 0, 2, cBlockArea.baTypes, E_BLOCK_STONE)
ba:FillRelCuboid(0, 2 * MAX_RAIL_META + 2, 1, 3, 0, 2, cBlockArea.baTypes, E_BLOCK_AIR)
for x = 0, MAX_RAIL_META do
ba:SetRelBlockTypeMeta(2 * x + 1, 1, 1, E_BLOCK_RAIL, x)
end
ba:Write(a_Player:GetWorld(), pos:Floor())
return true
end
function HandleGetCustomNameCmd(a_Split, a_Player)
local item = a_Player:GetInventory():GetEquippedItem()
if (not(item.m_CustomName) or (item.m_CustomName == "")) then

View File

@ -100,6 +100,12 @@ g_PluginInfo =
Handler = HandleGCCmd,
HelpString = "Activates the Lua garbage collector"
},
["/genrails"] =
{
Permission = "debuggers",
Handler = HandleGenRailsCmd,
HelpString = "Generates rail blocks with all metas from current block towards X+",
},
["/getcustomname"] =
{
Permission = "debuggers",

View File

@ -1126,7 +1126,7 @@ void cBlockArea::MirrorXY(void)
int MaxZ = m_Size.z - 1;
for (int y = 0; y < m_Size.y; y++)
{
for (int z = 0; z < HalfZ; z++)
for (int z = 0; z <= HalfZ; z++)
{
for (int x = 0; x < m_Size.x; x++)
{
@ -1164,7 +1164,7 @@ void cBlockArea::MirrorXZ(void)
// We are guaranteed that both blocktypes and blockmetas exist; mirror both at the same time:
int HalfY = m_Size.y / 2;
int MaxY = m_Size.y - 1;
for (int y = 0; y < HalfY; y++)
for (int y = 0; y <= HalfY; y++)
{
for (int z = 0; z < m_Size.z; z++)
{
@ -1208,7 +1208,7 @@ void cBlockArea::MirrorYZ(void)
{
for (int z = 0; z < m_Size.z; z++)
{
for (int x = 0; x < HalfX; x++)
for (int x = 0; x <= HalfX; x++)
{
int Idx1 = MakeIndex(x, y, z);
int Idx2 = MakeIndex(MaxX - x, y, z);

View File

@ -524,6 +524,8 @@ public:
return a_Meta;
}
virtual NIBBLETYPE MetaRotateCW(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09.
@ -559,66 +561,88 @@ public:
return a_Meta;
}
virtual NIBBLETYPE MetaMirrorXY(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09.
if ((a_Meta < 0x06) || (a_Meta > 0x09))
// MirrorXY basically flips the ZP and ZM parts of the meta
if (m_BlockType == E_BLOCK_RAIL)
{
// Save powered rail flag.
NIBBLETYPE OtherMeta = a_Meta & 0x08;
// Mirrors according to table; 0x07 == 0111.
// Rails can either be flat (North / South) or Ascending (Asc. East)
switch (a_Meta & 0x07)
// Basic rails can have curves and thus their meta behaves differently from specialized rails:
switch (a_Meta)
{
case 0x05: return 0x04 + OtherMeta; // Asc. South -> Asc. North
case 0x04: return 0x05 + OtherMeta; // Asc. North -> Asc. South
case E_META_RAIL_ASCEND_XM: return E_META_RAIL_ASCEND_XM;
case E_META_RAIL_ASCEND_XP: return E_META_RAIL_ASCEND_XP;
case E_META_RAIL_ASCEND_ZM: return E_META_RAIL_ASCEND_ZP;
case E_META_RAIL_ASCEND_ZP: return E_META_RAIL_ASCEND_ZM;
case E_META_RAIL_CURVED_ZM_XM: return E_META_RAIL_CURVED_ZP_XM;
case E_META_RAIL_CURVED_ZM_XP: return E_META_RAIL_CURVED_ZP_XP;
case E_META_RAIL_CURVED_ZP_XM: return E_META_RAIL_CURVED_ZM_XM;
case E_META_RAIL_CURVED_ZP_XP: return E_META_RAIL_CURVED_ZM_XP;
case E_META_RAIL_XM_XP: return E_META_RAIL_XM_XP;
case E_META_RAIL_ZM_ZP: return E_META_RAIL_ZM_ZP;
}
}
else
{
switch (a_Meta)
// Specialized rails don't have curves, instead they use bit 0x08 as a flag
NIBBLETYPE flag = a_Meta & 0x08;
switch (a_Meta & 0x07)
{
// Corner Directions
case 0x06: return 0x09; // Northwest Cnr. -> Southwest Cnr.
case 0x07: return 0x08; // Northeast Cnr. -> Southeast Cnr.
case 0x08: return 0x07; // Southeast Cnr. -> Northeast Cnr.
case 0x09: return 0x06; // Southwest Cnr. -> Northwest Cnr.
case E_META_RAIL_ASCEND_XM: return flag | E_META_RAIL_ASCEND_XM;
case E_META_RAIL_ASCEND_XP: return flag | E_META_RAIL_ASCEND_XP;
case E_META_RAIL_ASCEND_ZM: return flag | E_META_RAIL_ASCEND_ZP;
case E_META_RAIL_ASCEND_ZP: return flag | E_META_RAIL_ASCEND_ZM;
case E_META_RAIL_XM_XP: return flag | E_META_RAIL_XM_XP;
case E_META_RAIL_ZM_ZP: return flag | E_META_RAIL_ZM_ZP;
}
}
// To avoid a compiler warning;
ASSERT(!"Unknown rail meta");
return a_Meta;
}
virtual NIBBLETYPE MetaMirrorYZ(NIBBLETYPE a_Meta) override
{
// Bit 0x08 is a flag for value in the range 0x00--0x05 and specifies direction for values withint 0x006--0x09.
if ((a_Meta < 0x06) || (a_Meta > 0x09))
// MirrorYZ basically flips the XP and XM parts of the meta
if (m_BlockType == E_BLOCK_RAIL)
{
// Save powered rail flag.
NIBBLETYPE OtherMeta = a_Meta & 0x08;
// Mirrors according to table; 0x07 == 0111.
// Rails can either be flat (North / South) or Ascending (Asc. East)
switch (a_Meta & 0x07)
// Basic rails can have curves and thus their meta behaves differently from specialized rails:
switch (a_Meta)
{
case 0x02: return 0x03 + OtherMeta; // Asc. East -> Asc. West
case 0x03: return 0x02 + OtherMeta; // Asc. West -> Asc. East
case E_META_RAIL_ASCEND_XM: return E_META_RAIL_ASCEND_XP;
case E_META_RAIL_ASCEND_XP: return E_META_RAIL_ASCEND_XM;
case E_META_RAIL_ASCEND_ZM: return E_META_RAIL_ASCEND_ZM;
case E_META_RAIL_ASCEND_ZP: return E_META_RAIL_ASCEND_ZP;
case E_META_RAIL_CURVED_ZM_XM: return E_META_RAIL_CURVED_ZM_XP;
case E_META_RAIL_CURVED_ZM_XP: return E_META_RAIL_CURVED_ZM_XM;
case E_META_RAIL_CURVED_ZP_XM: return E_META_RAIL_CURVED_ZP_XP;
case E_META_RAIL_CURVED_ZP_XP: return E_META_RAIL_CURVED_ZP_XM;
case E_META_RAIL_XM_XP: return E_META_RAIL_XM_XP;
case E_META_RAIL_ZM_ZP: return E_META_RAIL_ZM_ZP;
}
}
else
{
switch (a_Meta)
// Specialized rails don't have curves, instead they use bit 0x08 as a flag
NIBBLETYPE flag = a_Meta & 0x08;
switch (a_Meta & 0x07)
{
// Corner Directions
case 0x06: return 0x07; // Northwest Cnr. -> Northeast Cnr.
case 0x07: return 0x06; // Northeast Cnr. -> Northwest Cnr.
case 0x08: return 0x09; // Southeast Cnr. -> Southwest Cnr.
case 0x09: return 0x08; // Southwest Cnr. -> Southeast Cnr.
case E_META_RAIL_ASCEND_XM: return flag | E_META_RAIL_ASCEND_XP;
case E_META_RAIL_ASCEND_XP: return flag | E_META_RAIL_ASCEND_XM;
case E_META_RAIL_ASCEND_ZM: return flag | E_META_RAIL_ASCEND_ZM;
case E_META_RAIL_ASCEND_ZP: return flag | E_META_RAIL_ASCEND_ZP;
case E_META_RAIL_XM_XP: return flag | E_META_RAIL_XM_XP;
case E_META_RAIL_ZM_ZP: return flag | E_META_RAIL_ZM_ZP;
}
}
// To avoid a compiler warning;
ASSERT(!"Unknown rail meta");
return a_Meta;
}
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
{
UNUSED(a_Meta);