fix: change player map icon to random select

This commit is contained in:
kuwacom 2026-03-14 01:30:54 +09:00
parent 20c2e4653a
commit fa70698546

View file

@ -12,6 +12,28 @@
const int MapItemSavedData::END_PORTAL_DECORATION_KEY = -1; const int MapItemSavedData::END_PORTAL_DECORATION_KEY = -1;
namespace
{
// Valid player icon slots in mapicons.png/additionalmapicons.png.
// Keep to these slots so we never sample placeholder entries.
static const char PLAYER_MAP_ICON_SLOTS[] = { 0, 1, 2, 3, 8, 9, 10, 11 };
static char getRandomPlayerMapIcon(const shared_ptr<Player>& player)
{
// use seed bit shift random
unsigned int seed = static_cast<unsigned int>(player->entityId);
seed ^= static_cast<unsigned int>(player->getPlayerIndex() * 0x9E3779B9u);
seed ^= (seed >> 16);
seed *= 0x7FEB352Du;
seed ^= (seed >> 15);
seed *= 0x846CA68Bu;
seed ^= (seed >> 16);
return PLAYER_MAP_ICON_SLOTS[seed % (sizeof(PLAYER_MAP_ICON_SLOTS) / sizeof(PLAYER_MAP_ICON_SLOTS[0]))];
}
}
// 4J added entityId param // 4J added entityId param
MapItemSavedData::MapDecoration::MapDecoration(char img, char x, char y, char rot, int entityId, bool visible) MapItemSavedData::MapDecoration::MapDecoration(char img, char x, char y, char rot, int entityId, bool visible)
{ {
@ -423,16 +445,14 @@ void MapItemSavedData::tickCarriedBy(shared_ptr<Player> player, shared_ptr<ItemI
// 4J Stu - As we have added new icons for players on a new row below // 4J Stu - As we have added new icons for players on a new row below
// other icons used in Java we need to move our index to the next row // other icons used in Java we need to move our index to the next row
imgIndex = static_cast<int>(decorationPlayer->getPlayerIndex()); imgIndex = getRandomPlayerMapIcon(decorationPlayer);
if(imgIndex>3) imgIndex += 4;
} }
#ifdef _LARGE_WORLDS #ifdef _LARGE_WORLDS
else //if (abs(xd) < MAP_SIZE * 5 && abs(yd) < MAP_SIZE * 5) else //if (abs(xd) < MAP_SIZE * 5 && abs(yd) < MAP_SIZE * 5)
{ {
// 4J Stu - As we have added new icons for players on a new row below // 4J Stu - As we have added new icons for players on a new row below
// other icons used in Java we need to move our index to the next row // other icons used in Java we need to move our index to the next row
imgIndex = static_cast<int>(decorationPlayer->getPlayerIndex()); imgIndex = getRandomPlayerMapIcon(decorationPlayer);
if(imgIndex>3) imgIndex += 4;
imgIndex += 16; // Add 16 to indicate that it's on the next texture imgIndex += 16; // Add 16 to indicate that it's on the next texture
rot = 0; rot = 0;