Files
neoLegacy/Minecraft.World/Sheep.cpp
T
Tranqlmao 9abd52985e TU53 + Bug Fixes (Many)
Patch Notes:
Blocks
+ Colored shulker boxes
+ Concrete powder
+ Concrete
+ Glazed terracotta
Items
+ Shulker shell
+ Iron nugget
UI Changes
+ Added Custom Controls to Keyboard & Mouse, as well as Controller
+ Added Custom SuperFlat
+ Added Edit Server Menu
+ Added Firework Crafting
Feature Changes
+ Host Options
+ Added Pick Block
+ Added off-hand slot for maps and arrows.
Bug Fixes & changes
+ TU47: Banner hitbox wrong (and inventory model fixed)
+ TU47/48: Ice not melting properly
+ TU48: Dead bushes not dropping sticks
+ TU48: Guardians and polar bears not dropping cooked fish when on fire
+ TU48: Bonus chest missing saplings and seeds
+ TU48: Frosted ice obtainable
+ TU48: Hoppers not collecting items
+ TU48: Wither skeletons spawning in 2-high gaps
+ TU48: End crystals exploding with “TNT Explodes” off
+ TU48: Tamed ocelots staying hostile
+ TU48: Signs not placing on tall grass
+ TU51: Skeleton hitbox wrong
+ TU53: Fall damage in shallow water
+ TU53: Squids not spawning in man-made pools
+ Elytra has been improved to be more accurate to the source material
+ Removed Spectral Arrow from crafting
+ Fixed several broken item descriptions
+ You can no longer cook Pufferfish or Clownfish
+ Fixed scaling issue with paperdoll and chat
+ Iron and gold armor can now be smelted into nuggets.
+ More items can now be used as fuel in a furnace.
+ Using a firework rocket while gliding with elytra will now give the player a boost.
+ Changed the color of dyes, wool, carpets, and banners.
+ Reordered all colored blocks and items in the Creative inventory. Banners now have the same order of colors as all other colored blocks and items.
+ Fishing rods can now hook on entities without causing knockback or pseudo-damage.
+ Fixed banner crafting
+ Fixed Map colors for certain blocks
+ Fixed Path block height
+ Fixed String block issues
+ Fixed Item frame culling.
+ Fixed Tutorial world NBT/Block State issues
+ Fixed World Slider
+ Fixed Enderman AI
+ Fixed Player animation bug
+ HUD Flash text changes
+ Generation accuracy changes
+ Many other small accuracy changes and fixes
2026-11-24 13:44:06 -05:00

389 lines
10 KiB
C++

#include "stdafx.h"
#include "com.mojang.nbt.h"
#include "net.minecraft.world.level.tile.h"
#include "net.minecraft.world.phys.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.item.crafting.h"
#include "net.minecraft.world.inventory.h"
#include "net.minecraft.world.entity.ai.attributes.h"
#include "net.minecraft.world.entity.ai.goal.h"
#include "net.minecraft.world.entity.ai.navigation.h"
#include "net.minecraft.world.entity.h"
#include "net.minecraft.world.entity.item.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.global.h"
#include "net.minecraft.world.entity.player.h"
#include "net.minecraft.world.entity.monster.h"
#include "Sheep.h"
#include "../Minecraft.Client/Textures.h"
#include "MobCategory.h"
#include "GenericStats.h"
#include "ColoredTile.h"
const float Sheep::COLOR[Sheep::COLOR_LENGTH][3] =
{
{ 0.9765f, 1.0000f, 0.9961f }, // white
{ 0.9765f, 0.5020f, 0.1137f }, // orange
{ 0.7804f, 0.3059f, 0.7412f }, // magenta
{ 0.2275f, 0.7020f, 0.8549f }, // light blue
{ 0.9961f, 0.8471f, 0.2392f }, // yellow
{ 0.5020f, 0.7804f, 0.1216f }, // light green
{ 0.9529f, 0.5451f, 0.6667f }, // pink
{ 0.2784f, 0.3098f, 0.3216f }, // gray
{ 0.6157f, 0.6157f, 0.5922f }, // silver
{ 0.0863f, 0.6118f, 0.6118f }, // cyan
{ 0.5373f, 0.1961f, 0.7216f }, // purple
{ 0.2353f, 0.2667f, 0.6667f }, // blue
{ 0.5137f, 0.3294f, 0.1961f }, // brown
{ 0.3686f, 0.4863f, 0.0863f }, // green
{ 0.6902f, 0.1804f, 0.1490f }, // red
{ 0.1137f, 0.1137f, 0.1294f }, // black
};
Sheep::Sheep(Level *level) : Animal( level )
{
// 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();
registerAttributes();
setHealth(getMaxHealth());
setSize(0.9f, 1.3f);
eatAnimationTick = 0;
eatTileGoal = new EatTileGoal(this);
getNavigation()->setAvoidWater(true);
goalSelector.addGoal(0, new FloatGoal(this));
goalSelector.addGoal(1, new PanicGoal(this, 1.25));
goalSelector.addGoal(2, new BreedGoal(this, 1.0));
goalSelector.addGoal(3, new TemptGoal(this, 1.1, Item::wheat_Id, false));
goalSelector.addGoal(4, new FollowParentGoal(this, 1.1));
goalSelector.addGoal(5, eatTileGoal, false);
goalSelector.addGoal(6, new RandomStrollGoal(this, 1.0));
goalSelector.addGoal(7, new LookAtPlayerGoal(this, typeid(Player), 6));
goalSelector.addGoal(8, new RandomLookAroundGoal(this));
container = std::make_shared<CraftingContainer>(new SheepContainer(), 2, 1);
container->setItem(0, std::make_shared<ItemInstance>(Item::dye, 1, 0));
container->setItem(1, std::make_shared<ItemInstance>(Item::dye, 1, 0));
}
bool Sheep::useNewAi()
{
return true;
}
void Sheep::newServerAiStep()
{
eatAnimationTick = eatTileGoal->getEatAnimationTick();
Animal::newServerAiStep();
}
void Sheep::aiStep()
{
if (level->isClientSide) eatAnimationTick = max(0, eatAnimationTick - 1);
Animal::aiStep();
}
void Sheep::registerAttributes()
{
Animal::registerAttributes();
getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(8);
getAttribute(SharedMonsterAttributes::MOVEMENT_SPEED)->setBaseValue(0.23f);
}
void Sheep::defineSynchedData()
{
Animal::defineSynchedData();
// sheared and color share a byte
entityData->define(DATA_WOOL_ID, static_cast<byte>(0)); //was new Byte((byte), 0)
}
void Sheep::dropDeathLoot(bool wasKilledByPlayer, int playerBonusLevel)
{
const int colorData = getColor();
const int dyeAuxValue = ColoredTile::getItemAuxValueForTileData(colorData);
const std::wstring colorName = DyePowderItem::COLOR_TEXTURES[dyeAuxValue];
const std::string tableName = "entities/sheep/" + std::string(colorName.begin(), colorName.end()) ;
LootTableManager &lootTables = LootTableManager::Get();
if (!lootTables.HasLoadedTables())
{
lootTables.LoadFromDisk();
}
const LootTableDefinition *table = lootTables.GetTable(tableName);
if (table != nullptr)
{
const std::vector<LootTableDropResult> drops = lootTables.ResolveDrops(
tableName,
wasKilledByPlayer,
playerBonusLevel,
[this](int maxExclusive) -> int { return random->nextInt(maxExclusive); },
isOnFire());
if (!drops.empty())
{
for (std::vector<LootTableDropResult>::const_iterator it = drops.begin(); it != drops.end(); ++it)
{
shared_ptr<ItemInstance> item = std::make_shared<ItemInstance>(it->itemId, it->count, it->data);
spawnAtLocation(item, 0.0f);
}
return;
}
}
/*
if(!isSheared())
{
// killing a non-sheared sheep will drop a single block of cloth
spawnAtLocation(std::make_shared<ItemInstance>(Tile::wool_Id, 1, getColor()), 0.0f);
}
int count = random->nextInt(2) + 1 + random->nextInt(1 + playerBonusLevel);
for (int i = 0; i < count; i++)
{
if (isOnFire())
{
spawnAtLocation(Item::cooked_mutton_Id, 1);
}
else
{
spawnAtLocation(Item::mutton_Id, 1);
}
}
*/
}
int Sheep::getDeathLoot()
{
return Tile::wool_Id;
}
void Sheep::handleEntityEvent(byte id)
{
if (id == EntityEvent::EAT_GRASS)
{
eatAnimationTick = EAT_ANIMATION_TICKS;
}
else
{
Animal::handleEntityEvent(id);
}
}
float Sheep::getHeadEatPositionScale(float a)
{
if (eatAnimationTick <= 0)
{
return 0;
}
if (eatAnimationTick >= 4 && eatAnimationTick <= (EAT_ANIMATION_TICKS - 4))
{
return 1;
}
if (eatAnimationTick < 4)
{
return (static_cast<float>(eatAnimationTick) - a) / 4.0f;
}
return -(static_cast<float>(eatAnimationTick - EAT_ANIMATION_TICKS) - a) / 4.0f;
}
float Sheep::getHeadEatAngleScale(float a)
{
if (eatAnimationTick > 4 && eatAnimationTick <= (EAT_ANIMATION_TICKS - 4))
{
float scale = (static_cast<float>(eatAnimationTick - 4) - a) / static_cast<float>(EAT_ANIMATION_TICKS - 8);
return PI * .20f + PI * .07f * Mth::sin(scale * 28.7f);
}
if (eatAnimationTick > 0)
{
return PI * .20f;
}
return ((xRot / (180.0f / PI)));
}
bool Sheep::mobInteract(shared_ptr<Player> player)
{
shared_ptr<ItemInstance> item = player->inventory->getSelected();
// 4J-JEV: Fix for #88212,
// Untrusted players shouldn't be able to sheer sheep.
if (!player->isAllowedToInteract( shared_from_this() ))
return false; //Animal::interact(player);
if (item != nullptr && item->id == Item::shears->id && !isSheared() && !isBaby())
{
if (!level->isClientSide)
{
setSheared(true);
int count = 1 + random->nextInt(3);
for (int i = 0; i < count; i++)
{
shared_ptr<ItemEntity> ie = spawnAtLocation(std::make_shared<ItemInstance>(Tile::wool_Id, 1, getColor()), 1.0f);
ie->yd += random->nextFloat() * 0.05f;
ie->xd += (random->nextFloat() - random->nextFloat()) * 0.1f;
ie->zd += (random->nextFloat() - random->nextFloat()) * 0.1f;
}
player->awardStat( GenericStats::shearedEntity(eTYPE_SHEEP), GenericStats::param_shearedEntity(eTYPE_SHEEP) );
}
item->hurtAndBreak(1, player);
playSound(eSoundType_MOB_SHEEP_SHEAR, 1, 1);
}
return Animal::mobInteract(player);
}
void Sheep::addAdditonalSaveData(CompoundTag *tag)
{
Animal::addAdditonalSaveData(tag);
tag->putBoolean(L"Sheared", isSheared());
tag->putByte(L"Color", static_cast<byte>(getColor()));
}
void Sheep::readAdditionalSaveData(CompoundTag *tag)
{
Animal::readAdditionalSaveData(tag);
setSheared(tag->getBoolean(L"Sheared"));
setColor((int) tag->getByte(L"Color"));
}
int Sheep::getAmbientSound()
{
return eSoundType_MOB_SHEEP_AMBIENT;
}
int Sheep::getHurtSound()
{
return eSoundType_MOB_SHEEP_AMBIENT;
}
int Sheep::getDeathSound()
{
return eSoundType_MOB_SHEEP_AMBIENT;
}
void Sheep::playStepSound(int xt, int yt, int zt, int t)
{
playSound(eSoundType_MOB_SHEEP_STEP, 0.15f, 1);
}
int Sheep::getColor()
{
return (entityData->getByte(DATA_WOOL_ID) & 0x0f);
}
void Sheep::setColor(int color)
{
byte current = entityData->getByte(DATA_WOOL_ID);
entityData->set(DATA_WOOL_ID, static_cast<byte>((current & 0xf0) | (color & 0x0f)));
}
bool Sheep::isSheared()
{
return (entityData->getByte(DATA_WOOL_ID) & 0x10) != 0;
}
void Sheep::setSheared(bool value)
{
byte current = entityData->getByte(DATA_WOOL_ID);
if (value)
{
entityData->set(DATA_WOOL_ID, static_cast<byte>(current | 0x10));
}
else
{
entityData->set(DATA_WOOL_ID, static_cast<byte>(current & ~0x10));
}
}
int Sheep::getSheepColor(Random *random)
{
int nextInt = random->nextInt(100);
if (nextInt < 5)
{
return 15 - DyePowderItem::BLACK;
}
if (nextInt < 10)
{
return 15 - DyePowderItem::GRAY;
}
if (nextInt < 15)
{
return 15 - DyePowderItem::SILVER;
}
if (nextInt < 18)
{
return 15 - DyePowderItem::BROWN;
}
if (random->nextInt(500) == 0) return 15 - DyePowderItem::PINK;
return 0; // white
}
shared_ptr<AgableMob> Sheep::getBreedOffspring(shared_ptr<AgableMob> target)
{
// 4J - added limit to number of animals that can be bred
if( level->canCreateMore( GetType(), Level::eSpawnType_Breed) )
{
shared_ptr<Sheep> otherSheep = dynamic_pointer_cast<Sheep>( target );
shared_ptr<Sheep> sheep = std::make_shared<Sheep>(level);
int color = getOffspringColor(dynamic_pointer_cast<Animal>(shared_from_this()), otherSheep);
sheep->setColor(15 - color);
return sheep;
}
else
{
return nullptr;
}
}
void Sheep::ate()
{
setSheared(false);
if (isBaby())
{
// remove a minute from aging
ageUp(60);
}
}
MobGroupData *Sheep::finalizeMobSpawn(MobGroupData *groupData, int extraData /*= 0*/) // 4J Added extraData param
{
groupData = Animal::finalizeMobSpawn(groupData);
setColor(getSheepColor(level->random));
return groupData;
}
int Sheep::getOffspringColor(shared_ptr<Animal> animal, shared_ptr<Animal> partner)
{
int parent1DyeColor = getDyeColor(animal);
int parent2DyeColor = getDyeColor(partner);
container->getItem(0)->setAuxValue(parent1DyeColor);
container->getItem(1)->setAuxValue(parent2DyeColor);
shared_ptr<ItemInstance> instance = Recipes::getInstance()->getItemFor(container, animal->level);
int color = 0;
if (instance != nullptr && instance->getItem()->id == Item::dye_Id)
{
color = instance->getAuxValue();
}
else
{
color = level->random->nextBoolean() ? parent1DyeColor : parent2DyeColor;
}
return color;
}
int Sheep::getDyeColor(shared_ptr<Animal> animal)
{
return 15 - dynamic_pointer_cast<Sheep>(animal)->getColor();
}