1
0

Item frame maps (#5258)

+ Send map data when item frame spawns.
+ Add some casts to placate compiler warnings.

* size_t for array access.
* Mark chunk dirty when rotation or item in item frame is changed.
This commit is contained in:
KingCol13 2021-07-09 18:45:53 +01:00 committed by GitHub
parent 4ec44751e2
commit 68776c4d59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 22 additions and 12 deletions

View File

@ -455,7 +455,7 @@ static int tolua_cNoteEntity_SetPitch(lua_State * tolua_S)
tolua_error(LuaState, "invalid 'self' in function 'SetPitch'", nullptr);
}
Self->SetNote(Note % 25);
Self->SetNote(static_cast<unsigned char>(Note % 25));
LOGWARNING("Warning: 'cNoteEntity:SetPitch' function is deprecated. Please use 'cNoteEntity:SetNote' instead.");
LuaState.LogStackTrace(0);
return 1;

View File

@ -618,7 +618,7 @@ unsigned char cBlockHandler::ToolFortuneLevel(const cItem * a_Tool)
char cBlockHandler::FortuneDiscreteRandom(char a_MinDrop, char a_DefaultMax, unsigned char a_BonusMax, char a_DropCap)
{
// First sample the discrete random distribution.
char DropNum = GetRandomProvider().RandInt<char>(a_MinDrop, a_DefaultMax + a_BonusMax);
char DropNum = GetRandomProvider().RandInt<char>(a_MinDrop, static_cast<char>(a_DefaultMax + a_BonusMax));
// Then clamp to within range (clamp instead of min incase of overflow):
return std::clamp<char>(DropNum, a_MinDrop, a_DropCap);

View File

@ -4,6 +4,7 @@
#include "ItemFrame.h"
#include "Player.h"
#include "../ClientHandle.h"
#include "Chunk.h"
@ -26,7 +27,7 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
if (!m_Item.IsEmpty())
{
// Item not empty, rotate, clipping values to zero to three inclusive
// Item not empty, rotate, clipping values to zero to seven inclusive
m_ItemRotation++;
if (m_ItemRotation >= 8)
{
@ -46,6 +47,7 @@ void cItemFrame::OnRightClicked(cPlayer & a_Player)
}
GetWorld()->BroadcastEntityMetadata(*this); // Update clients
GetParentChunk()->MarkDirty(); // Mark chunk dirty to save rotation or item
}
@ -97,4 +99,13 @@ void cItemFrame::SpawnOn(cClientHandle & a_ClientHandle)
Super::SpawnOn(a_ClientHandle);
a_ClientHandle.SendSpawnEntity(*this);
a_ClientHandle.SendEntityMetadata(*this);
if (m_Item.m_ItemType == E_ITEM_MAP)
{
cMap * Map = GetWorld()->GetMapManager().GetMapData(static_cast<unsigned>(m_Item.m_ItemDamage));
if (Map != nullptr)
{
a_ClientHandle.SendMapData(*Map, 0, 0);
}
}
}

View File

@ -613,7 +613,7 @@ void cFinishGenTallGrass::GenFinish(cChunkDesc & a_ChunkDesc)
}
else
{
NIBBLETYPE meta = (m_Noise.IntNoise2DInt(xx * 50, zz * 50) / 7 % 2) + 1;
NIBBLETYPE meta = static_cast<NIBBLETYPE>((m_Noise.IntNoise2DInt(xx * 50, zz * 50) / 7 % 2) + 1);
a_ChunkDesc.SetBlockTypeMeta(x, y, z, E_BLOCK_TALL_GRASS, meta);
a_ChunkDesc.SetHeight(x, z, static_cast<HEIGHTTYPE>(y));
}

View File

@ -1,4 +1,3 @@
// IntGen.h
// Declares the cIntGen class and descendants for generating and filtering various 2D arrays of ints
@ -494,7 +493,7 @@ public:
if (IsBiomeOcean(above) || IsBiomeOcean(below) || IsBiomeOcean(left) || IsBiomeOcean(right))
{
// First convert the value to a regular biome (drop the M flag), then modulo by our biome count:
val = ToBeach[(val % 128) % ARRAYCOUNT(ToBeach)];
val = ToBeach[static_cast<size_t>((val % 128)) % ARRAYCOUNT(ToBeach)];
}
}
a_Values[x + z * SizeX] = val;

View File

@ -767,7 +767,7 @@ public:
if (IsBiomeOcean(above) || IsBiomeOcean(below) || IsBiomeOcean(left) || IsBiomeOcean(right))
{
// First convert the value to a regular biome (drop the M flag), then modulo by our biome count:
val = ToBeach[(val % 128) % ARRAYCOUNT(ToBeach)];
val = ToBeach[static_cast<size_t>(val % 128) % ARRAYCOUNT(ToBeach)];
}
}
a_Values[x + z * a_SizeX] = val;

View File

@ -672,7 +672,7 @@ NIBBLETYPE GetLogMetaFromDirection(NIBBLETYPE a_BlockMeta, Vector3d a_Direction)
void GetBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
{
HEIGHTTYPE Height = 5 + (a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq)) % 3);
HEIGHTTYPE Height = 5 + static_cast<HEIGHTTYPE>(a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq)) % 3);
// Prealloc, so that we don't realloc too often later:
a_LogBlocks.reserve(static_cast<size_t>(Height));
@ -839,7 +839,7 @@ void GetDarkoakTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetB
void GetTallBirchTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, sSetBlockVector & a_LogBlocks, sSetBlockVector & a_OtherBlocks)
{
HEIGHTTYPE Height = 9 + (a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq)) % 3);
HEIGHTTYPE Height = 9 + static_cast<HEIGHTTYPE>(a_Noise.IntNoise3DInt(a_BlockPos.addedX(64 * a_Seq)) % 3);
// Prealloc, so that we don't realloc too often later:
a_LogBlocks.reserve(static_cast<size_t>(Height));
@ -1078,7 +1078,7 @@ void GetLargeSpruceTreeImage(Vector3i a_BlockPos, cNoise & a_Noise, int a_Seq, s
for (int i = 0; i < LeavesRingCount; i++)
{
unsigned int Val = (a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * i)) / 23) % 8;
unsigned int Val = static_cast<unsigned int>(a_Noise.IntNoise3DInt(a_BlockPos.addedXZ(32 * a_Seq, 32 * i)) / 23) % 8;
if ((Val < 4) && RingRadius < 3)
{
RingRadius++;

View File

@ -770,7 +770,7 @@ void cItemGrid::GenerateRandomLootWithBooks(const cLootProbab * a_LootProbabs, s
// Choose the enchantments
cWeightedEnchantments Enchantments;
cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, 24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7);
cEnchantments::AddItemEnchantmentWeights(Enchantments, E_ITEM_BOOK, static_cast<unsigned>(24 + Noise.IntNoise2DInt(a_Seed, TotalProbab) % 7));
int NumEnchantments = Noise.IntNoise3DInt(TotalProbab, Rnd, a_Seed) % 5; // The number of enchantments this book wil get.
for (int j = 0; j <= NumEnchantments; j++)

View File

@ -77,7 +77,7 @@ private:
a_Rotation = (a_Rotation / 360) * 16;
return static_cast<char>(a_Rotation) % 16;
return static_cast<NIBBLETYPE>(a_Rotation) % 16;
}
} ;