aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.World/Slime.cpp
diff options
context:
space:
mode:
authorLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
committerLoki Rautio <lokirautio@gmail.com>2026-03-04 03:56:03 -0600
commit42aec6dac53dffa6afe072560a7e1d4986112538 (patch)
tree0836426857391df1b6a83f6368a183f83ec9b104 /Minecraft.World/Slime.cpp
parentc9d58eeac7c72f0b3038e084667b4d89a6249fce (diff)
parentef9b6fd500dfabd9463267b0dd9e29577eea8a2b (diff)
Merge branch 'main' into pr/win64-world-saves
# Conflicts: # Minecraft.Client/MinecraftServer.cpp # README.md
Diffstat (limited to 'Minecraft.World/Slime.cpp')
-rw-r--r--Minecraft.World/Slime.cpp64
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()