CPU Overhead Optimization,Pathfinding and Entity Optimizations

- Cache shared_from_this() in serverAiStep
- Reduce shared_ptr overhead in entities
- Add shadow tile cache to optimize entity shadow rendering
This commit is contained in:
starseed12345 2026-03-09 17:42:49 +01:00
parent bda3b1078a
commit 41b734ebdb
43 changed files with 100 additions and 61 deletions

View file

@ -7,6 +7,6 @@ private:
static ResourceLocation ARROW_LOCATION; static ResourceLocation ARROW_LOCATION;
public: public:
virtual void render(shared_ptr<Entity> _arrow, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _arrow, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -10,7 +10,7 @@ class BatRenderer : public MobRenderer
public: public:
BatRenderer(); BatRenderer();
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
protected: protected:
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);

View file

@ -10,6 +10,6 @@ private:
public: public:
BlazeRenderer(); BlazeRenderer();
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -11,6 +11,6 @@ protected:
public: public:
BoatRenderer(); BoatRenderer();
virtual void render(shared_ptr<Entity> boat, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> boat, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -8,7 +8,7 @@ private:
public: public:
ChickenRenderer(Model *model, float shadow); ChickenRenderer(Model *model, float shadow);
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
protected: protected:

View file

@ -9,6 +9,6 @@ private:
public: public:
CowRenderer(Model *model, float shadow); CowRenderer(Model *model, float shadow);
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -4,6 +4,6 @@
class DefaultRenderer : public EntityRenderer class DefaultRenderer : public EntityRenderer
{ {
public: public:
virtual void render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob) { return nullptr; }; virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob) { return nullptr; };
}; };

View file

@ -13,6 +13,6 @@ private:
public: public:
EnderCrystalRenderer(); EnderCrystalRenderer();
virtual void render(shared_ptr<Entity> _crystal, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _crystal, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -25,7 +25,7 @@ protected:
virtual void renderModel(shared_ptr<LivingEntity> _mob, float wp, float ws, float bob, float headRotMinusBodyRot, float headRotx, float scale); virtual void renderModel(shared_ptr<LivingEntity> _mob, float wp, float ws, float bob, float headRotMinusBodyRot, float headRotx, float scale);
public: public:
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
protected: protected:

View file

@ -15,7 +15,7 @@ private:
public: public:
EndermanRenderer(); EndermanRenderer();
void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
void additionalRendering(shared_ptr<LivingEntity> _mob, float a); void additionalRendering(shared_ptr<LivingEntity> _mob, float a);

View file

@ -295,6 +295,11 @@ void EntityRenderDispatcher::render(shared_ptr<Entity> entity, double x, double
} }
} }
void EntityRenderDispatcher::beginFrame()
{
shadowTileCache.clear();
}
double EntityRenderDispatcher::distanceToSqr(double x, double y, double z) double EntityRenderDispatcher::distanceToSqr(double x, double y, double z)
{ {
double xd = x - xPlayer; double xd = x - xPlayer;

View file

@ -17,6 +17,29 @@ private:
public: public:
static EntityRenderDispatcher *instance; static EntityRenderDispatcher *instance;
struct ShadowTileKey
{
int x, y, z;
bool operator==(const ShadowTileKey &o) const
{
return x == o.x && y == o.y && z == o.z;
}
};
struct ShadowTileKeyHash
{
size_t operator()(const ShadowTileKey &k) const
{
return ((size_t)k.x * 73856093) ^ ((size_t)k.y * 19349663) ^ ((size_t)k.z * 83492791);
}
};
struct ShadowTileValue
{
int tileid;
int brightness;
};
private: private:
Font *font; Font *font;
@ -39,11 +62,13 @@ private:
EntityRenderDispatcher(); EntityRenderDispatcher();
public: public:
unordered_map<ShadowTileKey, ShadowTileValue, ShadowTileKeyHash> shadowTileCache;
void beginFrame();
EntityRenderer *getRenderer(eINSTANCEOF e); EntityRenderer *getRenderer(eINSTANCEOF e);
EntityRenderer *getRenderer(shared_ptr<Entity> e); EntityRenderer *getRenderer(shared_ptr<Entity> e);
void prepare(Level *level, Textures *textures, Font *font, shared_ptr<LivingEntity> player, shared_ptr<LivingEntity> crosshairPickMob, Options *options, float a); void prepare(Level *level, Textures *textures, Font *font, shared_ptr<LivingEntity> player, shared_ptr<LivingEntity> crosshairPickMob, Options *options, float a);
void render(shared_ptr<Entity> entity, float a); void render(const shared_ptr<Entity> entity, float a);
void render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a, bool bItemFrame = false, bool bRenderPlayerShadow = true); void render(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a, bool bItemFrame = false, bool bRenderPlayerShadow = true);
void setLevel(Level *level); void setLevel(Level *level);
double distanceToSqr(double x, double y, double z); double distanceToSqr(double x, double y, double z);
Font *getFont(); Font *getFont();

View file

@ -202,18 +202,26 @@ void EntityRenderer::renderShadow(shared_ptr<Entity> e, double x, double y, doub
double xo = x - ex; double xo = x - ex;
double yo = y - ey; double yo = y - ey;
double zo = z - ez; double zo = z - ez;
auto &cache = entityRenderDispatcher->shadowTileCache;
Tesselator *tt = Tesselator::getInstance(); Tesselator *tt = Tesselator::getInstance();
tt->begin(); tt->begin();
for (int xt = x0; xt <= x1; xt++) for (int xt = x0; xt <= x1; xt++)
for (int yt = y0; yt <= y1; yt++) for (int yt = y0; yt <= y1; yt++)
for (int zt = z0; zt <= z1; zt++) for (int zt = z0; zt <= z1; zt++)
{ {
int t = level->getTile(xt, yt - 1, zt); EntityRenderDispatcher::ShadowTileKey key = { xt, yt, zt };
if (t > 0 && level->getRawBrightness(xt, yt, zt) > 3) auto it = cache.find(key);
if (it == cache.end())
{ {
renderTileShadow(Tile::tiles[t], x, y + e->getShadowHeightOffs() + fYLocalPlayerShadowOffset, z, xt, yt , zt, pow, r, xo, yo + e->getShadowHeightOffs() + fYLocalPlayerShadowOffset, zo); EntityRenderDispatcher::ShadowTileValue val;
} val.tileid = level->getTile(xt, yt - 1, zt);
val.brightness = (val.tileid > 0) ? level->getRawBrightness(xt, yt, zt) : 0;
it = cache.emplace(key, val).first;
}
if (it->second.tileid > 0 && it->second.brightness > 3)
{
renderTileShadow(Tile::tiles[it->second.tileid], x, y + e->getShadowHeightOffs() + fYLocalPlayerShadowOffset, z, xt, yt, zt, pow, r, xo, yo + e->getShadowHeightOffs() + fYLocalPlayerShadowOffset, zo);
}
} }
tt->end(); tt->end();

View file

@ -42,7 +42,7 @@ public:
EntityRenderer(); // 4J - added EntityRenderer(); // 4J - added
virtual ~EntityRenderer(); virtual ~EntityRenderer();
public: public:
virtual void render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a) = 0; virtual void render(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a) = 0;
protected: protected:
virtual void bindTexture(shared_ptr<Entity> entity); virtual void bindTexture(shared_ptr<Entity> entity);
virtual void bindTexture(ResourceLocation *location); virtual void bindTexture(ResourceLocation *location);
@ -61,7 +61,7 @@ public:
static void renderFlat(AABB *bb); static void renderFlat(AABB *bb);
static void renderFlat(float x0, float y0, float z0, float x1, float y1, float z1); static void renderFlat(float x0, float y0, float z0, float x1, float y1, float z1);
virtual void init(EntityRenderDispatcher *entityRenderDispatcher); virtual void init(EntityRenderDispatcher *entityRenderDispatcher);
virtual void postRender(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a, bool bRenderPlayerShadow); virtual void postRender(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a, bool bRenderPlayerShadow);
virtual Font *getFont(); virtual Font *getFont();
virtual void registerTerrainTextures(IconRegister *iconRegister); virtual void registerTerrainTextures(IconRegister *iconRegister);

View file

@ -9,7 +9,7 @@ private:
public: public:
ExperienceOrbRenderer(); ExperienceOrbRenderer();
virtual void render(shared_ptr<Entity> _orb, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _orb, double x, double y, double z, float rot, float a);
void blit(int x, int y, int sx, int sy, int w, int h); void blit(int x, int y, int sx, int sy, int w, int h);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);

View file

@ -9,6 +9,6 @@ private:
public: public:
FallingTileRenderer(); FallingTileRenderer();
virtual void render(shared_ptr<Entity> _tile, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _tile, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -9,7 +9,7 @@ private:
public: public:
FireballRenderer(float scale); FireballRenderer(float scale);
virtual void render(shared_ptr<Entity> _fireball, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _fireball, double x, double y, double z, float rot, float a);
private: private:
// 4J Added override // 4J Added override

View file

@ -7,6 +7,6 @@ private:
static ResourceLocation PARTICLE_LOCATION; static ResourceLocation PARTICLE_LOCATION;
public: public:
virtual void render(shared_ptr<Entity> _hook, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _hook, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -30,7 +30,7 @@ public:
protected: protected:
virtual void createArmorParts(); virtual void createArmorParts();
virtual int prepareArmor(shared_ptr<LivingEntity> _mob, int layer, float a); virtual int prepareArmor(shared_ptr<LivingEntity> _mob, int layer, float a);
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
virtual void prepareCarriedItem(shared_ptr<Entity> mob, shared_ptr<ItemInstance> item); virtual void prepareCarriedItem(shared_ptr<Entity> mob, shared_ptr<ItemInstance> item);
virtual void additionalRendering(shared_ptr<LivingEntity> mob, float a); virtual void additionalRendering(shared_ptr<LivingEntity> mob, float a);

View file

@ -9,7 +9,7 @@ private:
public: public:
void registerTerrainTextures(IconRegister *iconRegister); void registerTerrainTextures(IconRegister *iconRegister);
virtual void render(shared_ptr<Entity> _itemframe, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _itemframe, double x, double y, double z, float rot, float a);
private: private:
void drawFrame(shared_ptr<ItemFrame> itemFrame); void drawFrame(shared_ptr<ItemFrame> itemFrame);

View file

@ -11,7 +11,7 @@ private:
public: public:
ItemSpriteRenderer(Item *sourceItem, int sourceItemAuxValue = 0); ItemSpriteRenderer(Item *sourceItem, int sourceItemAuxValue = 0);
//ItemSpriteRenderer(Item *icon); //ItemSpriteRenderer(Item *icon);
virtual void render(shared_ptr<Entity> e, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> e, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
private: private:

View file

@ -12,7 +12,7 @@ private:
public: public:
LeashKnotRenderer(); LeashKnotRenderer();
~LeashKnotRenderer(); ~LeashKnotRenderer();
virtual void render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a);
protected: protected:
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity);

View file

@ -540,6 +540,7 @@ void LevelRenderer::renderEntities(Vec3 *cam, Culler *culler, float a)
TileEntityRenderDispatcher::xOff = (player->xOld + (player->x - player->xOld) * a); TileEntityRenderDispatcher::xOff = (player->xOld + (player->x - player->xOld) * a);
TileEntityRenderDispatcher::yOff = (player->yOld + (player->y - player->yOld) * a); TileEntityRenderDispatcher::yOff = (player->yOld + (player->y - player->yOld) * a);
TileEntityRenderDispatcher::zOff = (player->zOld + (player->z - player->zOld) * a); TileEntityRenderDispatcher::zOff = (player->zOld + (player->z - player->zOld) * a);
EntityRenderDispatcher::instance->beginFrame();
mc->gameRenderer->turnOnLightLayer(a); // 4J - brought forward from 1.8.2 mc->gameRenderer->turnOnLightLayer(a); // 4J - brought forward from 1.8.2

View file

@ -4,5 +4,5 @@
class LightningBoltRenderer : public EntityRenderer class LightningBoltRenderer : public EntityRenderer
{ {
public: public:
virtual void render(shared_ptr<Entity> bolt, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> bolt, double x, double y, double z, float rot, float a);
}; };

View file

@ -20,7 +20,7 @@ protected:
public: public:
LivingEntityRenderer(Model *model, float shadow); LivingEntityRenderer(Model *model, float shadow);
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
virtual void setArmor(Model *armor); virtual void setArmor(Model *armor);
private: private:

View file

@ -14,7 +14,7 @@ protected:
public: public:
MinecartRenderer(); MinecartRenderer();
virtual void render(shared_ptr<Entity> _cart, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _cart, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
protected: protected:

View file

@ -13,7 +13,7 @@ class MobRenderer : public LivingEntityRenderer
{ {
public: public:
MobRenderer(Model *model, float shadow); MobRenderer(Model *model, float shadow);
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
protected: protected:
virtual bool shouldShowName(shared_ptr<LivingEntity> mob); virtual bool shouldShowName(shared_ptr<LivingEntity> mob);

View file

@ -9,7 +9,7 @@ private:
public: public:
MushroomCowRenderer(Model *model, float shadow); MushroomCowRenderer(Model *model, float shadow);
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
protected: protected:
virtual void additionalRendering(shared_ptr<LivingEntity> _mob, float a); virtual void additionalRendering(shared_ptr<LivingEntity> _mob, float a);

View file

@ -11,7 +11,7 @@ private:
public: public:
OcelotRenderer(Model *model, float shadow); OcelotRenderer(Model *model, float shadow);
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
protected: protected:
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity);

View file

@ -12,7 +12,7 @@ private:
public: public:
PaintingRenderer(); // 4J -added PaintingRenderer(); // 4J -added
virtual void render(shared_ptr<Entity> _painting, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _painting, double x, double y, double z, float rot, float a);
private: private:
void renderPainting(shared_ptr<Painting> painting, int w, int h, int uo, int vo); void renderPainting(shared_ptr<Painting> painting, int w, int h, int uo, int vo);

View file

@ -14,6 +14,6 @@ protected:
virtual int prepareArmor(shared_ptr<LivingEntity> _pig, int layer, float a); virtual int prepareArmor(shared_ptr<LivingEntity> _pig, int layer, float a);
public: public:
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -30,7 +30,7 @@ protected:
virtual void prepareSecondPassArmor(shared_ptr<LivingEntity> mob, int layer, float a); virtual void prepareSecondPassArmor(shared_ptr<LivingEntity> mob, int layer, float a);
public: public:
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
protected: protected:
virtual void additionalRendering(shared_ptr<LivingEntity> _mob, float a); virtual void additionalRendering(shared_ptr<LivingEntity> _mob, float a);

View file

@ -14,6 +14,6 @@ protected:
virtual int prepareArmor(shared_ptr<LivingEntity> _sheep, int layer, float a); virtual int prepareArmor(shared_ptr<LivingEntity> _sheep, int layer, float a);
public: public:
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -16,7 +16,7 @@ protected:
float getFlipDegrees(shared_ptr<LivingEntity> spider); float getFlipDegrees(shared_ptr<LivingEntity> spider);
public: public:
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
protected: protected:

View file

@ -8,7 +8,7 @@ private:
public: public:
SquidRenderer(Model *model, float shadow); SquidRenderer(Model *model, float shadow);
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
protected: protected:
virtual void setupRotations(shared_ptr<LivingEntity> _mob, float bob, float bodyRot, float a); virtual void setupRotations(shared_ptr<LivingEntity> _mob, float bob, float bodyRot, float a);

View file

@ -8,6 +8,6 @@ private:
public: public:
TntRenderer(); TntRenderer();
virtual void render(shared_ptr<Entity> _tnt, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _tnt, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
}; };

View file

@ -12,7 +12,7 @@ private:
public: public:
VillagerGolemRenderer(); VillagerGolemRenderer();
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> mob);
protected: protected:

View file

@ -18,7 +18,7 @@ protected:
public: public:
VillagerRenderer(); VillagerRenderer();
virtual void render(shared_ptr<Entity> mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> _mob); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> _mob);
protected: protected:

View file

@ -11,7 +11,7 @@ private:
public: public:
WitchRenderer(); WitchRenderer();
virtual void render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a);
protected: protected:
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity);

View file

@ -14,7 +14,7 @@ private:
public: public:
WitherBossRenderer(); WitherBossRenderer();
virtual void render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity);
protected: protected:

View file

@ -13,7 +13,7 @@ private:
public: public:
WitherSkullRenderer(); WitherSkullRenderer();
void render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a); void render(const shared_ptr<Entity> entity, double x, double y, double z, float rot, float a);
ResourceLocation *getTextureLocation(shared_ptr<Entity> entity); ResourceLocation *getTextureLocation(shared_ptr<Entity> entity);
private: private:

View file

@ -31,7 +31,7 @@ protected:
virtual int prepareArmor(shared_ptr<LivingEntity> _mob, int layer, float a); virtual int prepareArmor(shared_ptr<LivingEntity> _mob, int layer, float a);
public: public:
virtual void render(shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a); virtual void render(const shared_ptr<Entity> _mob, double x, double y, double z, float rot, float a);
virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity); virtual ResourceLocation *getTextureLocation(shared_ptr<Entity> entity);
protected: protected:

View file

@ -40,6 +40,7 @@ PathfinderMob::~PathfinderMob()
void PathfinderMob::serverAiStep() void PathfinderMob::serverAiStep()
{ {
auto self = shared_from_this();
if (fleeTime > 0) if (fleeTime > 0)
{ {
if (--fleeTime == 0) if (--fleeTime == 0)
@ -56,14 +57,14 @@ void PathfinderMob::serverAiStep()
attackTarget = findAttackTarget(); attackTarget = findAttackTarget();
if (attackTarget != nullptr) if (attackTarget != nullptr)
{ {
setPath(level->findPath(shared_from_this(), attackTarget, maxDist, true, false, false, true)); // 4J - changed to setPath from path = setPath(level->findPath(self, attackTarget, maxDist, true, false, false, true)); // 4J - changed to setPath from path =
} }
} }
else else
{ {
if (attackTarget->isAlive()) if (attackTarget->isAlive())
{ {
float d = attackTarget->distanceTo(shared_from_this()); float d = attackTarget->distanceTo(self);
if (canSee(attackTarget)) if (canSee(attackTarget))
{ {
checkHurtTarget(attackTarget, d); checkHurtTarget(attackTarget, d);
@ -86,7 +87,7 @@ void PathfinderMob::serverAiStep()
if (!holdGround && (attackTarget != nullptr && (path == nullptr || random->nextInt(20) == 0))) if (!holdGround && (attackTarget != nullptr && (path == nullptr || random->nextInt(20) == 0)))
{ {
setPath(level->findPath(shared_from_this(), attackTarget, maxDist, true, false, false, true));// 4J - changed to setPath from path = setPath(level->findPath(self, attackTarget, maxDist, true, false, false, true));// 4J - changed to setPath from path =
} }
else if (!holdGround && ((path == nullptr && (random->nextInt(180) == 0) || fleeTime > 0) || (random->nextInt(120) == 0 || fleeTime > 0))) else if (!holdGround && ((path == nullptr && (random->nextInt(180) == 0) || fleeTime > 0) || (random->nextInt(120) == 0 || fleeTime > 0)))
{ {
@ -111,18 +112,17 @@ void PathfinderMob::serverAiStep()
considerForExtraWandering( isDespawnProtected() ); considerForExtraWandering( isDespawnProtected() );
int yFloor = Mth::floor(bb->y0 + 0.5f); int yFloor = Mth::floor(bb->y0 + 0.5f);
xRot = 0;
if (path == nullptr || random->nextInt(100) == 0)
{
this->Mob::serverAiStep();
setPath(nullptr); // 4J - changed to setPath from path =
return;
}
bool inWater = isInWater(); bool inWater = isInWater();
bool inLava = isInLava(); bool inLava = isInLava();
xRot = 0;
if (path == nullptr || random->nextInt(100) == 0)
{
this->Mob::serverAiStep();
setPath(nullptr);// 4J - changed to setPath from path =
return;
}
Vec3 *target = path->currentPos(shared_from_this()); Vec3 *target = path->currentPos(self);
double r = bbWidth * 2; double r = bbWidth * 2;
while (target != nullptr && target->distanceToSqr(x, target->y, z) < r * r) while (target != nullptr && target->distanceToSqr(x, target->y, z) < r * r)
{ {
@ -132,7 +132,7 @@ void PathfinderMob::serverAiStep()
target = nullptr; target = nullptr;
setPath(nullptr); // 4J - changed to setPath from path = setPath(nullptr); // 4J - changed to setPath from path =
} }
else target = path->currentPos(shared_from_this()); else target = path->currentPos(self);
} }
jumping = false; jumping = false;
@ -221,7 +221,7 @@ void PathfinderMob::findRandomStrollLocation(int quadrant/*=-1*/) // 4J - added
} }
if (hasBest) if (hasBest)
{ {
setPath(level->findPath(shared_from_this(), xBest, yBest, zBest, 10, true, false, false, true)); // 4J - changed to setPath from path = setPath(level->findPath(shared_from_this(), xBest, yBest, zBest, 10, true, false, false, true)); // 4J - changed to setPath from path =
} }
} }