mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-11 20:11:18 +03:00
* Add Pig
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
The following code is licensed under the BSD 1 clause license.
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
#include "Animal.hpp"
|
||||
#include "world/level/Level.hpp"
|
||||
|
||||
Animal::Animal(Level* pLevel) : PathfinderMob(pLevel)
|
||||
{
|
||||
field_BB4 = 0;
|
||||
m_age = 0;
|
||||
}
|
||||
|
||||
void Animal::aiStep()
|
||||
{
|
||||
int age = getAge();
|
||||
if (age < 0)
|
||||
setAge(age + 1);
|
||||
else if (age)
|
||||
setAge(age - 1);
|
||||
|
||||
Mob::aiStep();
|
||||
}
|
||||
|
||||
bool Animal::isBaby()
|
||||
{
|
||||
return getAge() < 0;
|
||||
}
|
||||
|
||||
bool Animal::canSpawn()
|
||||
{
|
||||
int x = Mth::floor(m_pos.x);
|
||||
int y = Mth::floor(m_hitbox.min.y);
|
||||
int z = Mth::floor(m_pos.z);
|
||||
|
||||
if (m_pLevel->getTile(x, y - 1, z) != Tile::grass->m_ID || m_pLevel->getRawBrightness(x, y, z) < 8)
|
||||
return false;
|
||||
|
||||
return PathfinderMob::canSpawn();
|
||||
}
|
||||
|
||||
Entity* Animal::findAttackTarget()
|
||||
{
|
||||
// Animals are passive mobs.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
int Animal::getAmbientSoundInterval()
|
||||
{
|
||||
return 240;
|
||||
}
|
||||
|
||||
int Animal::getCreatureBaseType()
|
||||
{
|
||||
return BASE_ANIMAL;
|
||||
}
|
||||
|
||||
float Animal::getWalkTargetValue(int x, int y, int z)
|
||||
{
|
||||
// Animals would rather walk on grass.
|
||||
if (m_pLevel->getTile(x, y - 1, z) == Tile::grass->m_ID)
|
||||
return 10.0f;
|
||||
|
||||
// Animals will avoid dark areas.
|
||||
return m_pLevel->getBrightness(x, y, z) - 0.5f;
|
||||
}
|
||||
|
||||
bool Animal::hurt(Entity* pCulprit, int damage)
|
||||
{
|
||||
// Run around erratically for three seconds.
|
||||
field_BA4 = 60;
|
||||
|
||||
m_pAttackTarget = nullptr;
|
||||
field_BB4 = 0;
|
||||
|
||||
return Mob::hurt(pCulprit, damage);
|
||||
}
|
||||
|
||||
bool Animal::removeWhenFarAway()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int Animal::getAge()
|
||||
{
|
||||
return m_age;
|
||||
}
|
||||
|
||||
void Animal::setAge(int age)
|
||||
{
|
||||
m_age = age;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
The following code is licensed under the BSD 1 clause license.
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "PathfinderMob.hpp"
|
||||
|
||||
class Animal : public PathfinderMob
|
||||
{
|
||||
public:
|
||||
Animal(Level* pLevel);
|
||||
// TODO: void addAdditonalSaveData(CompoundTag*) override;
|
||||
// TODO: void readAdditonalSaveData(CompoundTag*) override;
|
||||
void aiStep() override;
|
||||
bool isBaby() override;
|
||||
bool canSpawn() override;
|
||||
Entity* findAttackTarget() override;
|
||||
int getAmbientSoundInterval() override;
|
||||
int getCreatureBaseType() override;
|
||||
float getWalkTargetValue(int x, int y, int z) override;
|
||||
bool hurt(Entity* pCulprit, int damage) override;
|
||||
bool removeWhenFarAway() override;
|
||||
|
||||
int getAge();
|
||||
void setAge(int age);
|
||||
|
||||
private:
|
||||
int field_BB4;
|
||||
int m_age;
|
||||
};
|
||||
|
||||
0
source/world/entity/Chicken.cpp
Normal file
0
source/world/entity/Chicken.cpp
Normal file
0
source/world/entity/Chicken.hpp
Normal file
0
source/world/entity/Chicken.hpp
Normal file
0
source/world/entity/Cow.cpp
Normal file
0
source/world/entity/Cow.cpp
Normal file
0
source/world/entity/Cow.hpp
Normal file
0
source/world/entity/Cow.hpp
Normal file
0
source/world/entity/Creeper.cpp
Normal file
0
source/world/entity/Creeper.cpp
Normal file
0
source/world/entity/Creeper.hpp
Normal file
0
source/world/entity/Creeper.hpp
Normal file
@@ -1075,6 +1075,16 @@ int Entity::queryEntityRenderer()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Entity::getCreatureBaseType()
|
||||
{
|
||||
return BASE_NONE;
|
||||
}
|
||||
|
||||
int Entity::getEntityTypeId()
|
||||
{
|
||||
return TYPE_UNSAVED;
|
||||
}
|
||||
|
||||
int Entity::hashCode()
|
||||
{
|
||||
return m_EntityID;
|
||||
|
||||
@@ -41,6 +41,27 @@ enum eEntityRenderType
|
||||
RENDER_FALLING_TILE = 50,
|
||||
};
|
||||
|
||||
enum eEntityType
|
||||
{
|
||||
TYPE_UNSAVED,
|
||||
|
||||
TYPE_CHICKEN = 10,
|
||||
TYPE_COW,
|
||||
TYPE_PIG,
|
||||
TYPE_SHEEP,
|
||||
|
||||
TYPE_ZOMBIE = 32,
|
||||
|
||||
TYPE_ITEM = 64,
|
||||
};
|
||||
|
||||
enum eCreatureBaseType
|
||||
{
|
||||
BASE_NONE,
|
||||
BASE_MONSTER,
|
||||
BASE_ANIMAL,
|
||||
};
|
||||
|
||||
struct EntityPos
|
||||
{
|
||||
Vec3 m_pos;
|
||||
@@ -150,6 +171,8 @@ public:
|
||||
virtual void burn(int);
|
||||
virtual void lavaHurt();
|
||||
virtual int queryEntityRenderer();
|
||||
virtual int getCreatureBaseType();
|
||||
virtual int getEntityTypeId();
|
||||
|
||||
virtual bool isLocalPlayer();
|
||||
|
||||
|
||||
@@ -853,6 +853,11 @@ int Mob::getMaxHeadXRot()
|
||||
return 10;
|
||||
}
|
||||
|
||||
int Mob::getMaxHealth()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
float Mob::getSoundVolume()
|
||||
{
|
||||
return 1.0f;
|
||||
|
||||
@@ -71,6 +71,7 @@ public:
|
||||
virtual void jumpFromGround();
|
||||
virtual void updateAi();
|
||||
virtual int getMaxHeadXRot();
|
||||
virtual int getMaxHealth();
|
||||
virtual float getSoundVolume();
|
||||
virtual std::string getAmbientSound();
|
||||
virtual std::string getHurtSound();
|
||||
|
||||
@@ -31,7 +31,8 @@ public:
|
||||
void setPath(Path& path);
|
||||
bool isPathFinding();
|
||||
|
||||
private:
|
||||
protected:
|
||||
friend class Animal;
|
||||
Entity* m_pAttackTarget;
|
||||
bool field_BA0;
|
||||
int field_BA4;
|
||||
|
||||
65
source/world/entity/Pig.cpp
Normal file
65
source/world/entity/Pig.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
The following code is licensed under the BSD 1 clause license.
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
#include "Pig.hpp"
|
||||
|
||||
Pig::Pig(Level* pLevel) : Animal(pLevel)
|
||||
{
|
||||
field_C8 = RENDER_PIG;
|
||||
m_texture = "mob/pig.png";
|
||||
setSize(0.9f, 0.9f);
|
||||
// some dataitem stuff
|
||||
}
|
||||
|
||||
std::string Pig::getAmbientSound()
|
||||
{
|
||||
return "mob.pig";
|
||||
}
|
||||
|
||||
std::string Pig::getDeathSound()
|
||||
{
|
||||
return "mob.pigdeath";
|
||||
}
|
||||
|
||||
std::string Pig::getHurtSound()
|
||||
{
|
||||
return "mob.pig";
|
||||
}
|
||||
|
||||
int Pig::getEntityTypeId()
|
||||
{
|
||||
return TYPE_PIG;
|
||||
}
|
||||
|
||||
int Pig::getMaxHealth()
|
||||
{
|
||||
return 10;
|
||||
}
|
||||
|
||||
bool Pig::interact(Player* pPlayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int Pig::getDeathLoot()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Pig::hasSaddle()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void Pig::setSaddle(bool b)
|
||||
{
|
||||
}
|
||||
|
||||
Entity* Pig::getBreedOffspring(Animal* pOther)
|
||||
{
|
||||
return new Pig(m_pLevel);
|
||||
}
|
||||
28
source/world/entity/Pig.hpp
Normal file
28
source/world/entity/Pig.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
/********************************************************************
|
||||
Minecraft: Pocket Edition - Decompilation Project
|
||||
Copyright (C) 2023 iProgramInCpp
|
||||
|
||||
The following code is licensed under the BSD 1 clause license.
|
||||
SPDX-License-Identifier: BSD-1-Clause
|
||||
********************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "Animal.hpp"
|
||||
|
||||
class Pig : public Animal
|
||||
{
|
||||
public:
|
||||
Pig(Level* pLevel);
|
||||
|
||||
std::string getAmbientSound() override;
|
||||
std::string getDeathSound() override;
|
||||
std::string getHurtSound() override;
|
||||
int getDeathLoot() override;
|
||||
int getEntityTypeId() override;
|
||||
int getMaxHealth() override;
|
||||
bool interact(Player*) override;
|
||||
|
||||
bool hasSaddle();
|
||||
void setSaddle(bool b);
|
||||
Entity* getBreedOffspring(Animal* pOther);
|
||||
};
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "CameraItem.hpp"
|
||||
#include "world/level/Level.hpp"
|
||||
#include "world/entity/TripodCamera.hpp"
|
||||
#include "world/entity/Pig.hpp"
|
||||
#include "world/entity/Player.hpp"
|
||||
|
||||
CameraItem::CameraItem(int id) : Item(id)
|
||||
@@ -23,6 +24,12 @@ ItemInstance* CameraItem::use(ItemInstance* inst, Level* level, Player* player)
|
||||
return inst;
|
||||
#endif
|
||||
|
||||
/*
|
||||
Pig* pig = new Pig(level);
|
||||
pig->setPos(player->m_pos.x, player->m_pos.y, player->m_pos.z);
|
||||
level->addEntity(pig);
|
||||
*/
|
||||
|
||||
level->addEntity(new TripodCamera(level, player, player->m_pos.x, player->m_pos.y, player->m_pos.z));
|
||||
return inst;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user