diff options
| author | daoge <3523206925@qq.com> | 2026-03-03 03:04:10 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-03 03:04:10 +0800 |
| commit | b3feddfef372618c8a9d7a0abcaf18cfad866c18 (patch) | |
| tree | 267761c3bb39241ba5c347bfbe2254d06686e287 /Minecraft.World/Slime.cpp | |
| parent | 84c31a2331f7a0ec85b9d438992e244f60e5020f (diff) | |
feat: TU19 (Dec 2014) Features & Content (#155)
* try to resolve merge conflict
* feat: TU19 (Dec 2014) Features & Content (#32)
* December 2014 files
* Working release build
* Fix compilation issues
* Add sound to Windows64Media
* Add DLC content and force Tutorial DLC
* Revert "Add DLC content and force Tutorial DLC"
This reverts commit 97a43994725008e35fceb984d5549df9c8cea470.
* Disable broken light packing
* Disable breakpoint during DLC texture map load
Allows DLC loading but the DLC textures are still broken
* Fix post build not working
* ...
* fix vs2022 build
* fix cmake build
---------
Co-authored-by: Loki <lokirautio@gmail.com>
Diffstat (limited to 'Minecraft.World/Slime.cpp')
| -rw-r--r-- | Minecraft.World/Slime.cpp | 64 |
1 files changed, 39 insertions, 25 deletions
diff --git a/Minecraft.World/Slime.cpp b/Minecraft.World/Slime.cpp index 7941fbe0..eb80d09c 100644 --- a/Minecraft.World/Slime.cpp +++ b/Minecraft.World/Slime.cpp @@ -6,8 +6,10 @@ #include "net.minecraft.world.level.chunk.h" #include "net.minecraft.world.entity.h" #include "net.minecraft.world.item.h" +#include "net.minecraft.world.entity.ai.attributes.h" #include "net.minecraft.world.entity.item.h" #include "net.minecraft.world.entity.player.h" +#include "net.minecraft.world.entity.monster.h" #include "net.minecraft.world.damagesource.h" #include "com.mojang.nbt.h" #include "Slime.h" @@ -30,15 +32,13 @@ Slime::Slime(Level *level) : Mob( 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(); - - // 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 - health = getMaxHealth(); + registerAttributes(); + setHealth(getMaxHealth()); _init(); - this->textureIdx = TN_MOB_SLIME; // 4J was L"/mob/slime.png"; int size = 1 << (random->nextInt(3)); - this->heightOffset = 0; + heightOffset = 0; jumpDelay = random->nextInt(20) + 10; setSize(size); } @@ -53,18 +53,13 @@ void Slime::defineSynchedData() void Slime::setSize(int size) { entityData->set(ID_SIZE, (byte) size); - Mob::setSize(0.6f * size, 0.6f * size); - this->setPos(x, y, z); + setSize(0.6f * size, 0.6f * size); + setPos(x, y, z); + getAttribute(SharedMonsterAttributes::MAX_HEALTH)->setBaseValue(size * size); setHealth(getMaxHealth()); xpReward = size; } -int Slime::getMaxHealth() -{ - int size = getSize(); - return size * size; -} - int Slime::getSize() { return entityData->getByte(ID_SIZE); @@ -89,7 +84,7 @@ ePARTICLE_TYPE Slime::getParticleName() int Slime::getSquishSound() { - return eSoundType_MOB_SLIME; + return getSize() > 1 ? eSoundType_MOB_SLIME_BIG : eSoundType_MOB_SLIME; } void Slime::tick() @@ -102,7 +97,7 @@ void Slime::tick() squish = squish + (targetSquish - squish) * .5f; oSquish = squish; - bool wasOnGround = this->onGround; + bool wasOnGround = onGround; Mob::tick(); if (onGround && !wasOnGround) { @@ -118,7 +113,7 @@ void Slime::tick() if (doPlayLandSound()) { - level->playSound(shared_from_this(), getSquishSound(), getSoundVolume(), ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) / 0.8f); + playSound(getSquishSound(), getSoundVolume(), ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) / 0.8f); } targetSquish = -0.5f; } @@ -128,6 +123,12 @@ void Slime::tick() targetSquish = 1; } decreaseSquish(); + + if (level->isClientSide) + { + int size = getSize(); + setSize(0.6f * size, 0.6f * size); + } } void Slime::serverAiStep() @@ -148,7 +149,7 @@ void Slime::serverAiStep() jumping = true; if (doPlayJumpSound()) { - level->playSound(shared_from_this(), getSquishSound(), getSoundVolume(), ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) * 0.8f); + playSound(getSquishSound(), getSoundVolume(), ((random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f) * 0.8f); } // 4J Removed TU7 to bring forward change to fix lava slime render in MP @@ -211,12 +212,12 @@ void Slime::playerTouch(shared_ptr<Player> player) if (isDealsDamage()) { int size = getSize(); - if (canSee(player) && this->distanceToSqr(player) < (0.6 * size) * (0.6 * size)) + if (canSee(player) && distanceToSqr(player) < (0.6 * size) * (0.6 * size)) { DamageSource *damageSource = DamageSource::mobAttack( dynamic_pointer_cast<Mob>( shared_from_this() ) ); if (player->hurt(damageSource, getAttackDamage())) { - level->playSound(shared_from_this(), eSoundType_MOB_SLIME_ATTACK, 1, (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f); + playSound(eSoundType_MOB_SLIME_ATTACK, 1, (random->nextFloat() - random->nextFloat()) * 0.2f + 1.0f); } delete damageSource; } @@ -235,12 +236,12 @@ int Slime::getAttackDamage() int Slime::getHurtSound() { - return eSoundType_MOB_SLIME; + return getSize() > 1 ? eSoundType_MOB_SLIME_BIG : eSoundType_MOB_SLIME; } int Slime::getDeathSound() { - return eSoundType_MOB_SLIME; + return getSize() > 1 ? eSoundType_MOB_SLIME_BIG : eSoundType_MOB_SLIME; } int Slime::getDeathLoot() @@ -257,11 +258,24 @@ bool Slime::canSpawn() return false; } Random *lcr = lc->getRandom(987234911l); // 4J - separated out so we can delete - if ((getSize() == 1 || level->difficulty > Difficulty::PEACEFUL) && random->nextInt(10) == 0 && lcr->nextInt(10) == 0 && y < 40) + if ((getSize() == 1 || level->difficulty > Difficulty::PEACEFUL)) { - delete lcr; - return Mob::canSpawn(); + // spawn slime in swamplands at night + Biome *biome = level->getBiome(Mth::floor(x), Mth::floor(z)); + + if (biome == Biome::swampland && y > 50 && y < 70 && random->nextFloat() < 0.5f) + { + if (random->nextFloat() < level->getMoonBrightness() && level->getRawBrightness(Mth::floor(x), Mth::floor(y), Mth::floor(z)) <= random->nextInt(8)) + { + return Mob::canSpawn(); + } + } + if (random->nextInt(10) == 0 && lcr->nextInt(10) == 0 && y < 40) + { + return Mob::canSpawn(); + } } + delete lcr; return false; } @@ -278,7 +292,7 @@ int Slime::getMaxHeadXRot() bool Slime::doPlayJumpSound() { - return getSize() > 1; + return getSize() > 0; } bool Slime::doPlayLandSound() |
