Project modernization (#630)
* Fixed boats falling and a TP glitch #266 * Replaced every C-style cast with C++ ones * Replaced every C-style cast with C++ ones * Fixed boats falling and a TP glitch #266 * Updated NULL to nullptr and fixing some type issues * Modernized and fixed a few bugs - Replaced most instances of `NULL` with `nullptr`. - Replaced most `shared_ptr(new ...)` with `make_shared`. - Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances. * Fixing more conflicts * Replace int loops with size_t and start work on overrides
This commit is contained in:
@@ -43,7 +43,7 @@ void Mob::_init()
|
||||
lookingAt = nullptr;
|
||||
lookTime = 0;
|
||||
target = nullptr;
|
||||
sensing = NULL;
|
||||
sensing = nullptr;
|
||||
|
||||
equipment = ItemInstanceArray(5);
|
||||
dropChances = floatArray(5);
|
||||
@@ -58,7 +58,7 @@ void Mob::_init()
|
||||
|
||||
_isLeashed = false;
|
||||
leashHolder = nullptr;
|
||||
leashInfoTag = NULL;
|
||||
leashInfoTag = nullptr;
|
||||
}
|
||||
|
||||
Mob::Mob( Level* level) : LivingEntity(level)
|
||||
@@ -87,16 +87,16 @@ Mob::Mob( Level* level) : LivingEntity(level)
|
||||
|
||||
Mob::~Mob()
|
||||
{
|
||||
if(lookControl != NULL) delete lookControl;
|
||||
if(moveControl != NULL) delete moveControl;
|
||||
if(jumpControl != NULL) delete jumpControl;
|
||||
if(bodyControl != NULL) delete bodyControl;
|
||||
if(navigation != NULL) delete navigation;
|
||||
if(sensing != NULL) delete sensing;
|
||||
if(lookControl != nullptr) delete lookControl;
|
||||
if(moveControl != nullptr) delete moveControl;
|
||||
if(jumpControl != nullptr) delete jumpControl;
|
||||
if(bodyControl != nullptr) delete bodyControl;
|
||||
if(navigation != nullptr) delete navigation;
|
||||
if(sensing != nullptr) delete sensing;
|
||||
|
||||
if(leashInfoTag != NULL) delete leashInfoTag;
|
||||
if(leashInfoTag != nullptr) delete leashInfoTag;
|
||||
|
||||
if(equipment.data != NULL) delete [] equipment.data;
|
||||
if(equipment.data != nullptr) delete [] equipment.data;
|
||||
delete [] dropChances.data;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ void Mob::ate()
|
||||
void Mob::defineSynchedData()
|
||||
{
|
||||
LivingEntity::defineSynchedData();
|
||||
entityData->define(DATA_CUSTOM_NAME_VISIBLE, (byte) 0);
|
||||
entityData->define(DATA_CUSTOM_NAME_VISIBLE, static_cast<byte>(0));
|
||||
entityData->define(DATA_CUSTOM_NAME, L"");
|
||||
}
|
||||
|
||||
@@ -196,7 +196,7 @@ int Mob::getExperienceReward(shared_ptr<Player> killedBy)
|
||||
ItemInstanceArray slots = getEquipmentSlots();
|
||||
for (int i = 0; i < slots.length; i++)
|
||||
{
|
||||
if (slots[i] != NULL && dropChances[i] <= 1)
|
||||
if (slots[i] != nullptr && dropChances[i] <= 1)
|
||||
{
|
||||
result += 1 + random->nextInt(3);
|
||||
}
|
||||
@@ -280,7 +280,7 @@ void Mob::addAdditonalSaveData(CompoundTag *entityTag)
|
||||
for (int i = 0; i < equipment.length; i++)
|
||||
{
|
||||
CompoundTag *tag = new CompoundTag();
|
||||
if (equipment[i] != NULL) equipment[i]->save(tag);
|
||||
if (equipment[i] != nullptr) equipment[i]->save(tag);
|
||||
gear->add(tag);
|
||||
}
|
||||
entityTag->put(L"Equipment", gear);
|
||||
@@ -296,7 +296,7 @@ void Mob::addAdditonalSaveData(CompoundTag *entityTag)
|
||||
|
||||
// leash info
|
||||
entityTag->putBoolean(L"Leashed", _isLeashed);
|
||||
if (leashHolder != NULL)
|
||||
if (leashHolder != nullptr)
|
||||
{
|
||||
CompoundTag *leashTag = new CompoundTag(L"Leash");
|
||||
if ( leashHolder->instanceof(eTYPE_LIVINGENTITY) )
|
||||
@@ -347,7 +347,7 @@ void Mob::readAdditionalSaveData(CompoundTag *tag)
|
||||
_isLeashed = tag->getBoolean(L"Leashed");
|
||||
if (_isLeashed && tag->contains(L"Leash"))
|
||||
{
|
||||
leashInfoTag = (CompoundTag *)tag->getCompound(L"Leash")->copy();
|
||||
leashInfoTag = static_cast<CompoundTag *>(tag->getCompound(L"Leash")->copy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -372,7 +372,7 @@ void Mob::aiStep()
|
||||
for (auto& it : *entities)
|
||||
{
|
||||
shared_ptr<ItemEntity> entity = dynamic_pointer_cast<ItemEntity>(it);
|
||||
if (entity->removed || entity->getItem() == NULL) continue;
|
||||
if (entity->removed || entity->getItem() == nullptr) continue;
|
||||
shared_ptr<ItemInstance> item = entity->getItem();
|
||||
int slot = getEquipmentSlotForItem(item);
|
||||
|
||||
@@ -381,17 +381,17 @@ void Mob::aiStep()
|
||||
bool replace = true;
|
||||
shared_ptr<ItemInstance> current = getCarried(slot);
|
||||
|
||||
if (current != NULL)
|
||||
if (current != nullptr)
|
||||
{
|
||||
if (slot == SLOT_WEAPON)
|
||||
{
|
||||
WeaponItem *newWeapon = dynamic_cast<WeaponItem *>(item->getItem());
|
||||
WeaponItem *oldWeapon = dynamic_cast<WeaponItem *>(current->getItem());
|
||||
if ( newWeapon != NULL && oldWeapon == NULL)
|
||||
if ( newWeapon != nullptr && oldWeapon == nullptr)
|
||||
{
|
||||
replace = true;
|
||||
}
|
||||
else if (newWeapon != NULL && oldWeapon != NULL)
|
||||
else if (newWeapon != nullptr && oldWeapon != nullptr)
|
||||
{
|
||||
if (newWeapon->getTierDamage() == oldWeapon->getTierDamage())
|
||||
{
|
||||
@@ -411,11 +411,11 @@ void Mob::aiStep()
|
||||
{
|
||||
ArmorItem *newArmor = dynamic_cast<ArmorItem *>(item->getItem());
|
||||
ArmorItem *oldArmor = dynamic_cast<ArmorItem *>(current->getItem());
|
||||
if (newArmor != NULL && oldArmor == NULL)
|
||||
if (newArmor != nullptr && oldArmor == nullptr)
|
||||
{
|
||||
replace = true;
|
||||
}
|
||||
else if (newArmor != NULL && oldArmor != NULL)
|
||||
else if (newArmor != nullptr && oldArmor != nullptr)
|
||||
{
|
||||
if (newArmor->defense == oldArmor->defense)
|
||||
{
|
||||
@@ -435,7 +435,7 @@ void Mob::aiStep()
|
||||
|
||||
if (replace)
|
||||
{
|
||||
if (current != NULL && random->nextFloat() - 0.1f < dropChances[slot])
|
||||
if (current != nullptr && random->nextFloat() - 0.1f < dropChances[slot])
|
||||
{
|
||||
spawnAtLocation(current, 0);
|
||||
}
|
||||
@@ -470,7 +470,7 @@ void Mob::checkDespawn()
|
||||
return;
|
||||
}
|
||||
shared_ptr<Entity> player = level->getNearestPlayer(shared_from_this(), -1);
|
||||
if (player != NULL)
|
||||
if (player != nullptr)
|
||||
{
|
||||
double xd = player->x - x;
|
||||
double yd = player->y - y;
|
||||
@@ -547,7 +547,7 @@ void Mob::serverAiStep()
|
||||
if (random->nextFloat() < 0.02f)
|
||||
{
|
||||
shared_ptr<Player> player = level->getNearestPlayer(shared_from_this(), lookDistance);
|
||||
if (player != NULL)
|
||||
if (player != nullptr)
|
||||
{
|
||||
lookingAt = player;
|
||||
lookTime = 10 + random->nextInt(20);
|
||||
@@ -558,9 +558,9 @@ void Mob::serverAiStep()
|
||||
}
|
||||
}
|
||||
|
||||
if (lookingAt != NULL)
|
||||
if (lookingAt != nullptr)
|
||||
{
|
||||
lookAt(lookingAt, 10.0f, (float) getMaxHeadXRot());
|
||||
lookAt(lookingAt, 10.0f, static_cast<float>(getMaxHeadXRot()));
|
||||
if (lookTime-- <= 0 || lookingAt->removed || lookingAt->distanceToSqr(shared_from_this()) > lookDistance * lookDistance)
|
||||
{
|
||||
lookingAt = nullptr;
|
||||
@@ -605,15 +605,15 @@ void Mob::lookAt(shared_ptr<Entity> e, float yMax, float xMax)
|
||||
|
||||
double sd = Mth::sqrt(xd * xd + zd * zd);
|
||||
|
||||
float yRotD = (float) (atan2(zd, xd) * 180 / PI) - 90;
|
||||
float xRotD = (float) -(atan2(yd, sd) * 180 / PI);
|
||||
float yRotD = static_cast<float>(atan2(zd, xd) * 180 / PI) - 90;
|
||||
float xRotD = static_cast<float>(-(atan2(yd, sd) * 180 / PI));
|
||||
xRot = rotlerp(xRot, xRotD, xMax);
|
||||
yRot = rotlerp(yRot, yRotD, yMax);
|
||||
}
|
||||
|
||||
bool Mob::isLookingAtAnEntity()
|
||||
{
|
||||
return lookingAt != NULL;
|
||||
return lookingAt != nullptr;
|
||||
}
|
||||
|
||||
shared_ptr<Entity> Mob::getLookingAt()
|
||||
@@ -658,8 +658,8 @@ int Mob::getMaxSpawnClusterSize()
|
||||
|
||||
int Mob::getMaxFallDistance()
|
||||
{
|
||||
if (getTarget() == NULL) return 3;
|
||||
int sacrifice = (int) (getHealth() - (getMaxHealth() * 0.33f));
|
||||
if (getTarget() == nullptr) return 3;
|
||||
int sacrifice = static_cast<int>(getHealth() - (getMaxHealth() * 0.33f));
|
||||
sacrifice -= (3 - level->difficulty) * 4;
|
||||
if (sacrifice < 0) sacrifice = 0;
|
||||
return sacrifice + 3;
|
||||
@@ -697,7 +697,7 @@ void Mob::dropEquipment(bool byPlayer, int playerBonusLevel)
|
||||
shared_ptr<ItemInstance> item = getCarried(slot);
|
||||
bool preserve = dropChances[slot] > 1;
|
||||
|
||||
if (item != NULL && (byPlayer || preserve) && random->nextFloat() - playerBonusLevel * 0.01f < dropChances[slot])
|
||||
if (item != nullptr && (byPlayer || preserve) && random->nextFloat() - playerBonusLevel * 0.01f < dropChances[slot])
|
||||
{
|
||||
if (!preserve && item->isDamageableItem())
|
||||
{
|
||||
@@ -726,10 +726,10 @@ void Mob::populateDefaultEquipmentSlots()
|
||||
{
|
||||
shared_ptr<ItemInstance> item = getArmor(i);
|
||||
if (i < 3 && random->nextFloat() < partialChance) break;
|
||||
if (item == NULL)
|
||||
if (item == nullptr)
|
||||
{
|
||||
Item *equip = getEquipmentForSlot(i + 1, armorType);
|
||||
if (equip != NULL) setEquippedSlot(i + 1, shared_ptr<ItemInstance>(new ItemInstance(equip)));
|
||||
if (equip != nullptr) setEquippedSlot(i + 1, std::make_shared<ItemInstance>(equip));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -743,7 +743,7 @@ int Mob::getEquipmentSlotForItem(shared_ptr<ItemInstance> item)
|
||||
}
|
||||
|
||||
ArmorItem *armorItem = dynamic_cast<ArmorItem *>(item->getItem());
|
||||
if (armorItem != NULL)
|
||||
if (armorItem != nullptr)
|
||||
{
|
||||
switch (armorItem->slot)
|
||||
{
|
||||
@@ -791,23 +791,23 @@ Item *Mob::getEquipmentForSlot(int slot, int type)
|
||||
if (type == 4) return Item::boots_diamond;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void Mob::populateDefaultEquipmentEnchantments()
|
||||
{
|
||||
float difficulty = level->getDifficulty(x, y, z);
|
||||
|
||||
if (getCarriedItem() != NULL && random->nextFloat() < MAX_ENCHANTED_WEAPON_CHANCE * difficulty) {
|
||||
EnchantmentHelper::enchantItem(random, getCarriedItem(), (int) (5 + difficulty * random->nextInt(18)));
|
||||
if (getCarriedItem() != nullptr && random->nextFloat() < MAX_ENCHANTED_WEAPON_CHANCE * difficulty) {
|
||||
EnchantmentHelper::enchantItem(random, getCarriedItem(), static_cast<int>(5 + difficulty * random->nextInt(18)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
shared_ptr<ItemInstance> item = getArmor(i);
|
||||
if (item != NULL && random->nextFloat() < MAX_ENCHANTED_ARMOR_CHANCE * difficulty)
|
||||
if (item != nullptr && random->nextFloat() < MAX_ENCHANTED_ARMOR_CHANCE * difficulty)
|
||||
{
|
||||
EnchantmentHelper::enchantItem(random, item, (int) (5 + difficulty * random->nextInt(18)));
|
||||
EnchantmentHelper::enchantItem(random, item, static_cast<int>(5 + difficulty * random->nextInt(18)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -865,7 +865,7 @@ bool Mob::hasCustomName()
|
||||
|
||||
void Mob::setCustomNameVisible(bool visible)
|
||||
{
|
||||
entityData->set(DATA_CUSTOM_NAME_VISIBLE, visible ? (byte) 1 : (byte) 0);
|
||||
entityData->set(DATA_CUSTOM_NAME_VISIBLE, visible ? static_cast<byte>(1) : static_cast<byte>(0));
|
||||
}
|
||||
|
||||
bool Mob::isCustomNameVisible()
|
||||
@@ -908,7 +908,7 @@ bool Mob::interact(shared_ptr<Player> player)
|
||||
}
|
||||
|
||||
shared_ptr<ItemInstance> itemstack = player->inventory->getSelected();
|
||||
if (itemstack != NULL)
|
||||
if (itemstack != nullptr)
|
||||
{
|
||||
// it's inconvenient to have the leash code here, but it's because
|
||||
// the mob.interact(player) method has priority over
|
||||
@@ -953,7 +953,7 @@ bool Mob::mobInteract(shared_ptr<Player> player)
|
||||
|
||||
void Mob::tickLeash()
|
||||
{
|
||||
if (leashInfoTag != NULL)
|
||||
if (leashInfoTag != nullptr)
|
||||
{
|
||||
restoreLeashFromSave();
|
||||
}
|
||||
@@ -962,7 +962,7 @@ void Mob::tickLeash()
|
||||
return;
|
||||
}
|
||||
|
||||
if (leashHolder == NULL || leashHolder->removed)
|
||||
if (leashHolder == nullptr || leashHolder->removed)
|
||||
{
|
||||
dropLeash(true, true);
|
||||
return;
|
||||
@@ -981,9 +981,9 @@ void Mob::dropLeash(bool synch, bool createItemDrop)
|
||||
}
|
||||
|
||||
ServerLevel *serverLevel = dynamic_cast<ServerLevel *>(level);
|
||||
if (!level->isClientSide && synch && serverLevel != NULL)
|
||||
if (!level->isClientSide && synch && serverLevel != nullptr)
|
||||
{
|
||||
serverLevel->getTracker()->broadcast(shared_from_this(), shared_ptr<SetEntityLinkPacket>(new SetEntityLinkPacket(SetEntityLinkPacket::LEASH, shared_from_this(), nullptr)));
|
||||
serverLevel->getTracker()->broadcast(shared_from_this(), std::make_shared<SetEntityLinkPacket>(SetEntityLinkPacket::LEASH, shared_from_this(), nullptr));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1011,14 +1011,14 @@ void Mob::setLeashedTo(shared_ptr<Entity> holder, bool synch)
|
||||
ServerLevel *serverLevel = dynamic_cast<ServerLevel *>(level);
|
||||
if (!level->isClientSide && synch && serverLevel)
|
||||
{
|
||||
serverLevel->getTracker()->broadcast(shared_from_this(), shared_ptr<SetEntityLinkPacket>( new SetEntityLinkPacket(SetEntityLinkPacket::LEASH, shared_from_this(), leashHolder)));
|
||||
serverLevel->getTracker()->broadcast(shared_from_this(), std::make_shared<SetEntityLinkPacket>(SetEntityLinkPacket::LEASH, shared_from_this(), leashHolder));
|
||||
}
|
||||
}
|
||||
|
||||
void Mob::restoreLeashFromSave()
|
||||
{
|
||||
// after being added to the world, attempt to recreate leash bond
|
||||
if (_isLeashed && leashInfoTag != NULL)
|
||||
if (_isLeashed && leashInfoTag != nullptr)
|
||||
{
|
||||
if (leashInfoTag->contains(L"UUID"))
|
||||
{
|
||||
@@ -1043,7 +1043,7 @@ void Mob::restoreLeashFromSave()
|
||||
int z = leashInfoTag->getInt(L"Z");
|
||||
|
||||
shared_ptr<LeashFenceKnotEntity> activeKnot = LeashFenceKnotEntity::findKnotAt(level, x, y, z);
|
||||
if (activeKnot == NULL)
|
||||
if (activeKnot == nullptr)
|
||||
{
|
||||
activeKnot = LeashFenceKnotEntity::createAndAddKnot(level, x, y, z);
|
||||
}
|
||||
@@ -1055,7 +1055,7 @@ void Mob::restoreLeashFromSave()
|
||||
dropLeash(false, true);
|
||||
}
|
||||
}
|
||||
leashInfoTag = NULL;
|
||||
leashInfoTag = nullptr;
|
||||
}
|
||||
|
||||
// 4J added so we can not render mobs before their chunks are loaded - to resolve bug 10327 :Gameplay: NPCs can spawn over chunks that have not yet been streamed and display jitter.
|
||||
|
||||
Reference in New Issue
Block a user