* Add Pig

This commit is contained in:
iProgramInCpp
2023-12-06 21:58:28 +02:00
parent 805087d36a
commit 3443349df0
19 changed files with 364 additions and 63 deletions

View File

@@ -721,60 +721,6 @@
<ClCompile Include="$(MC_ROOT)\source\client\model\QuadrupedModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\ChickenModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\CowModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\CreeperModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\PigModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SheepFurModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SheepModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SkeletonModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SpiderModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\ZombieModel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\ChickenRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\CowRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\CreeperRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\PigRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SheepFurRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SheepRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SkeletonRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SpiderRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\ZombieRenderer.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\gui\components\OptionList.cpp">
<Filter>Source Files\GUI\Components</Filter>
</ClCompile>
@@ -784,5 +730,59 @@
<ClCompile Include="$(MC_ROOT)\source\client\renderer\FoliageColor.cpp">
<Filter>Source Files\Renderer</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\CowModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\ChickenModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\CreeperModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\PigModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SheepFurModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SheepModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SkeletonModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\SpiderModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\model\ZombieModel.cpp">
<Filter>Source Files\Model</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\ZombieRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\ChickenRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\CowRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\CreeperRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\PigRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SheepFurRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SheepRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SkeletonRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\client\renderer\entity\SpiderRenderer.cpp">
<Filter>Source Files\Renderer\Entity</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@@ -340,6 +340,10 @@
<ClCompile Include="$(MC_ROOT)\source\world\entity\Monster.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\PathfinderMob.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\WaterAnimal.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Chicken.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Cow.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Creeper.cpp" />
<ClCompile Include="$(MC_ROOT)\source\world\entity\Pig.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Entity.hpp" />
@@ -443,6 +447,10 @@
<ClInclude Include="$(MC_ROOT)\source\world\entity\Monster.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\PathfinderMob.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\WaterAnimal.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Chicken.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Cow.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Creeper.hpp" />
<ClInclude Include="$(MC_ROOT)\source\world\entity\Pig.hpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -434,16 +434,28 @@
<ClCompile Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.cpp">
<Filter>Source Files\Level\Path</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\PathfinderMob.cpp">
<ClCompile Include="$(MC_ROOT)\source\world\entity\Animal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\world\entity\Monster.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\world\entity\PathfinderMob.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\world\entity\WaterAnimal.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="$(MC_ROOT)\source\world\entity\Cow.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\Animal.cpp">
<ClCompile Include="$(MC_ROOT)\source\world\entity\Chicken.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\Monster.cpp">
<ClCompile Include="$(MC_ROOT)\source\world\entity\Creeper.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
<ClCompile Include="..\..\..\..\source\world\entity\WaterAnimal.cpp">
<ClCompile Include="$(MC_ROOT)\source\world\entity\Pig.cpp">
<Filter>Source Files\Entity</Filter>
</ClCompile>
</ItemGroup>
@@ -739,16 +751,28 @@
<ClInclude Include="$(MC_ROOT)\source\world\level\path\BinaryHeap.hpp">
<Filter>Header Files\Level\Path</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\PathfinderMob.hpp">
<ClInclude Include="$(MC_ROOT)\source\world\entity\Animal.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Monster.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\world\entity\PathfinderMob.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\world\entity\WaterAnimal.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="$(MC_ROOT)\source\world\entity\Chicken.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\WaterAnimal.hpp">
<ClInclude Include="$(MC_ROOT)\source\world\entity\Creeper.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\Monster.hpp">
<ClInclude Include="$(MC_ROOT)\source\world\entity\Cow.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
<ClInclude Include="..\..\..\..\source\world\entity\Animal.hpp">
<ClInclude Include="$(MC_ROOT)\source\world\entity\Pig.hpp">
<Filter>Header Files\Entity</Filter>
</ClInclude>
</ItemGroup>

View File

@@ -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;
}

View File

@@ -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;
};

View File

View File

View File

View File

View File

View File

View 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;

View File

@@ -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();

View File

@@ -853,6 +853,11 @@ int Mob::getMaxHeadXRot()
return 10;
}
int Mob::getMaxHealth()
{
return 10;
}
float Mob::getSoundVolume()
{
return 1.0f;

View File

@@ -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();

View File

@@ -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;

View 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);
}

View 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);
};

View File

@@ -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;
}