2026-03-01 12:16:08 +08:00
# include "stdafx.h"
# include "net.minecraft.world.level.h"
# include "net.minecraft.world.level.tile.h"
# include "net.minecraft.world.item.h"
# include "net.minecraft.world.entity.player.h"
# include "net.minecraft.world.entity.item.h"
# include "..\Minecraft.Client\Textures.h"
# include "MushroomCow.h"
# include "MobCategory.h"
# include "AABB.h"
MushroomCow : : MushroomCow ( Level * level ) : Cow ( level )
{
2026-03-03 03:04:10 +08:00
// 4J Stu - This function call had to be moved here from the Entity ctor to ensure that
// the derived version of the function is called
this - > defineSynchedData ( ) ;
setHealth ( getMaxHealth ( ) ) ;
2026-03-01 12:16:08 +08:00
this - > setSize ( 0.9f , 1.3f ) ;
}
2026-03-03 03:04:10 +08:00
bool MushroomCow : : mobInteract ( shared_ptr < Player > player )
2026-03-01 12:16:08 +08:00
{
2026-03-02 17:37:16 +07:00
shared_ptr < ItemInstance > item = player - > inventory - > getSelected ( ) ;
2026-03-01 12:16:08 +08:00
if ( item ! = NULL & & item - > id = = Item : : bowl_Id & & getAge ( ) > = 0 )
{
2026-03-02 17:37:16 +07:00
if ( item - > count = = 1 )
2026-03-01 12:16:08 +08:00
{
2026-03-02 17:37:16 +07:00
player - > inventory - > setItem ( player - > inventory - > selected , shared_ptr < ItemInstance > ( new ItemInstance ( Item : : mushroomStew ) ) ) ;
2026-03-01 12:16:08 +08:00
return true ;
}
2026-03-02 17:37:16 +07:00
if ( player - > inventory - > add ( shared_ptr < ItemInstance > ( new ItemInstance ( Item : : mushroomStew ) ) ) & & ! player - > abilities . instabuild )
2026-03-01 12:16:08 +08:00
{
player - > inventory - > removeItem ( player - > inventory - > selected , 1 ) ;
return true ;
}
2026-03-03 03:04:10 +08:00
}
// 4J: Do not allow shearing if we can't create more cows
if ( item ! = NULL & & item - > id = = Item : : shears_Id & & getAge ( ) > = 0 & & level - > canCreateMore ( eTYPE_COW , Level : : eSpawnType_Breed ) )
2026-03-01 12:16:08 +08:00
{
remove ( ) ;
level - > addParticle ( eParticleType_largeexplode , x , y + bbHeight / 2 , z , 0 , 0 , 0 ) ;
if ( ! level - > isClientSide )
{
remove ( ) ;
2026-03-02 17:37:16 +07:00
shared_ptr < Cow > cow = shared_ptr < Cow > ( new Cow ( level ) ) ;
2026-03-01 12:16:08 +08:00
cow - > moveTo ( x , y , z , yRot , xRot ) ;
cow - > setHealth ( getHealth ( ) ) ;
cow - > yBodyRot = yBodyRot ;
level - > addEntity ( cow ) ;
for ( int i = 0 ; i < 5 ; i + + )
{
2026-03-03 03:04:10 +08:00
level - > addEntity ( shared_ptr < ItemEntity > ( new ItemEntity ( level , x , y + bbHeight , z , shared_ptr < ItemInstance > ( new ItemInstance ( Tile : : mushroom_red ) ) ) ) ) ;
2026-03-01 12:16:08 +08:00
}
2026-03-03 03:04:10 +08:00
return true ;
2026-03-01 12:16:08 +08:00
}
return true ;
}
2026-03-03 03:04:10 +08:00
return Cow : : mobInteract ( player ) ;
2026-03-01 12:16:08 +08:00
}
// 4J - added so that mushroom cows have more of a chance of spawning, they can now spawn on mycelium as well as grass - seems a bit odd that they don't already really
bool MushroomCow : : canSpawn ( )
{
int xt = Mth : : floor ( x ) ;
int yt = Mth : : floor ( bb - > y0 ) ;
int zt = Mth : : floor ( z ) ;
return ( level - > getTile ( xt , yt - 1 , zt ) = = Tile : : grass_Id | | level - > getTile ( xt , yt - 1 , zt ) = = Tile : : mycel_Id ) & & level - > getDaytimeRawBrightness ( xt , yt , zt ) > 8 & & PathfinderMob : : canSpawn ( ) ;
}
2026-03-02 17:37:16 +07:00
shared_ptr < AgableMob > MushroomCow : : getBreedOffspring ( shared_ptr < AgableMob > target )
2026-03-01 12:16:08 +08:00
{
// 4J - added limit to number of animals that can be bred
if ( level - > canCreateMore ( GetType ( ) , Level : : eSpawnType_Breed ) )
{
2026-03-02 17:37:16 +07:00
return shared_ptr < MushroomCow > ( new MushroomCow ( level ) ) ;
2026-03-01 12:16:08 +08:00
}
else
{
return nullptr ;
}
}