Files
LegacyRenouveau/Minecraft.World/Zombie.h
T
Anaël d8d65bcd49 game loop: Refactor the tooltips loop
Moved the whole logic to a new file (TooltipManager.cpp), and rewrote most of the logic to profit from object oriented programming. The side-effect is that the changes are scattered across entities, tiles and items because moving everything to OOP requires to add the tooltip to every .cpp file for every tile/item/entities (or their class, on plants for example which all use the tooltip IDS_TOOLTIPS_PLANT)

The issue with the default tooltips loop written by 4J is that:

    Its running in the main Minecraft::tick loop and is more than a thousand lines long, polluting the function.
    Not using C++'s full potential with object oriented programming, 4J decided to use a big switch case (probably because it could run better on hardware without branch prediction like the WiiU or Xbox 360 ?)
    And seems to be better off in its own file than in the main Minecraft.cpp file
2026-10-04 20:54:24 +02:00

116 lines
2.9 KiB
C++

#pragma once
using namespace std;
#include "Monster.h"
#include "SharedConstants.h"
#include "MobGroupData.h"
class Zombie : public Monster
{
private:
static const int VILLAGER_CONVERSION_WAIT_MIN = SharedConstants::TICKS_PER_SECOND * 60 * 3;
static const int VILLAGER_CONVERSION_WAIT_MAX = SharedConstants::TICKS_PER_SECOND * 60 * 5;
protected:
static Attribute *SPAWN_REINFORCEMENTS_CHANCE;
private:
static AttributeModifier *SPEED_MODIFIER_BABY;
static const int DATA_BABY_ID = 12;
static const int DATA_VILLAGER_ID = 13;
static const int DATA_CONVERTING_ID = 14;
public:
static const float ZOMBIE_LEADER_CHANCE;
static const int REINFORCEMENT_ATTEMPTS = 50;
static const int REINFORCEMENT_RANGE_MAX = 40;
static const int REINFORCEMENT_RANGE_MIN = 7;
private:
int villagerConversionTime;
public:
static const int MAX_SPECIAL_BLOCKS_COUNT = 14;
static const int SPECIAL_BLOCK_RADIUS = 4;
public:
eINSTANCEOF GetType() { return eTYPE_ZOMBIE; }
static Entity *create(Level *level) { return new Zombie(level); }
Zombie(Level *level);
protected:
virtual void registerAttributes();
virtual void defineSynchedData();
public:
virtual int getArmorValue();
protected:
virtual bool useNewAi();
public:
virtual bool isBaby();
virtual void setBaby(bool baby);
virtual bool isVillager();
virtual void setVillager(bool villager);
virtual void aiStep();
virtual bool hurt(DamageSource *source, float dmg);
virtual void tick();
virtual bool doHurtTarget(shared_ptr<Entity> target);
virtual void updateSize(bool isBaby);
protected:
virtual int getAmbientSound();
virtual int getHurtSound();
virtual int getDeathSound();
virtual int getDeathLoot();
virtual void playStepSound(int xt, int yt, int zt, int t);
public:
virtual MobType getMobType();
protected:
virtual void dropRareDeathLoot(int rareLootLevel);
virtual void populateDefaultEquipmentSlots();
public:
virtual void addAdditonalSaveData(CompoundTag *tag);
virtual void readAdditionalSaveData(CompoundTag *tag);
virtual void killed(shared_ptr<LivingEntity> mob);
virtual MobGroupData *finalizeMobSpawn(MobGroupData *groupData, int extraData = 0); // 4J Added extraData param
virtual bool mobInteract(shared_ptr<Player> player);
protected:
virtual void startConverting(int time);
public:
virtual void handleEntityEvent(byte id);
protected:
virtual bool removeWhenFarAway();
public:
virtual bool isConverting();
virtual int getAttackTooltipId(std::shared_ptr<Player> player);
virtual int getInteractTooltipId(Level *level,
std::shared_ptr<Player> player,
std::shared_ptr<ItemInstance> heldItem);
protected:
virtual void finishConversion();
virtual int getConversionProgress();
private:
class ZombieGroupData : public MobGroupData
{
public:
bool isBaby;
bool isVillager;
ZombieGroupData(bool baby, bool villager);
};
};