TU19: merge Minecraft.Client/Player

This commit is contained in:
Tropical
2026-03-21 22:03:18 -05:00
parent 3f143811e3
commit a493e42532
16 changed files with 1364 additions and 948 deletions

View File

@@ -12,6 +12,13 @@
#include "../../Minecraft.World/Headers/net.minecraft.world.effect.h"
#include "../../Minecraft.World/Level/LevelData.h"
#include "../../Minecraft.World/Headers/net.minecraft.world.entity.item.h"
#include "../Input/Input.h"
#include "../Rendering/LevelRenderer.h"
// 4J added for testing
#ifdef STRESS_TEST_MOVE
volatile bool stressTestEnabled = true;
#endif
MultiplayerLocalPlayer::MultiplayerLocalPlayer(Minecraft* minecraft,
Level* level, User* user,
@@ -30,11 +37,11 @@ MultiplayerLocalPlayer::MultiplayerLocalPlayer(Minecraft* minecraft,
this->connection = connection;
}
bool MultiplayerLocalPlayer::hurt(DamageSource* source, int dmg) {
bool MultiplayerLocalPlayer::hurt(DamageSource* source, float dmg) {
return false;
}
void MultiplayerLocalPlayer::heal(int heal) {}
void MultiplayerLocalPlayer::heal(float heal) {}
void MultiplayerLocalPlayer::tick() {
// 4J Added
@@ -57,14 +64,31 @@ void MultiplayerLocalPlayer::tick() {
if (!level->hasChunkAt(Mth::floor(x), 0, Mth::floor(z))) return;
double tempX = x, tempY = y, tempZ = z;
LocalPlayer::tick();
// 4J added for testing
#ifdef STRESS_TEST_MOVE
if (stressTestEnabled) {
StressTestMove(&tempX, &tempY, &tempZ);
}
#endif
// if( !minecraft->localgameModes[m_iPad]->isTutorial() ||
// minecraft->localgameModes[m_iPad]->getTutorial()->canMoveToPosition(tempX,
// tempY, tempZ, x, y, z) )
if (minecraft->localgameModes[m_iPad]->getTutorial()->canMoveToPosition(
tempX, tempY, tempZ, x, y, z)) {
sendPosition();
if (isRiding()) {
connection->send(
std::shared_ptr<MovePlayerPacket>(new MovePlayerPacket::Rot(
yRot, xRot, onGround, abilities.flying)));
connection->send(
std::shared_ptr<PlayerInputPacket>(new PlayerInputPacket(
xxa, yya, input->jumping, input->sneaking)));
} else {
sendPosition();
}
} else {
// app.Debugprintf("Cannot move to position (%f, %f, %f), falling back
// to (%f, %f, %f)\n", x, y, z, tempX, y, tempZ);
@@ -189,7 +213,8 @@ void MultiplayerLocalPlayer::respawn() {
new ClientCommandPacket(ClientCommandPacket::PERFORM_RESPAWN)));
}
void MultiplayerLocalPlayer::actuallyHurt(DamageSource* source, int dmg) {
void MultiplayerLocalPlayer::actuallyHurt(DamageSource* source, float dmg) {
if (isInvulnerable()) return;
setHealth(getHealth() - dmg);
}
@@ -216,7 +241,8 @@ void MultiplayerLocalPlayer::onEffectAdded(MobEffectInstance* effect) {
Player::onEffectAdded(effect);
}
void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect) {
void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect,
bool doRefreshAttributes) {
Minecraft* pMinecraft = Minecraft::GetInstance();
if (pMinecraft->localgameModes[m_iPad] != NULL) {
TutorialMode* gameMode =
@@ -224,7 +250,7 @@ void MultiplayerLocalPlayer::onEffectUpdated(MobEffectInstance* effect) {
Tutorial* tutorial = gameMode->getTutorial();
tutorial->onEffectChanged(MobEffect::effects[effect->getId()]);
}
Player::onEffectUpdated(effect);
Player::onEffectUpdated(effect, doRefreshAttributes);
}
void MultiplayerLocalPlayer::onEffectRemoved(MobEffectInstance* effect) {
@@ -241,11 +267,16 @@ void MultiplayerLocalPlayer::onEffectRemoved(MobEffectInstance* effect) {
void MultiplayerLocalPlayer::closeContainer() {
connection->send(std::shared_ptr<ContainerClosePacket>(
new ContainerClosePacket(containerMenu->containerId)));
clientSideCloseContainer();
}
// close the container without sending a packet to the server
void MultiplayerLocalPlayer::clientSideCloseContainer() {
inventory->setCarried(nullptr);
LocalPlayer::closeContainer();
}
void MultiplayerLocalPlayer::hurtTo(int newHealth,
void MultiplayerLocalPlayer::hurtTo(float newHealth,
ETelemetryChallenges damageSource) {
if (flashOnSetHealth) {
LocalPlayer::hurtTo(newHealth, damageSource);
@@ -283,11 +314,30 @@ void MultiplayerLocalPlayer::onUpdateAbilities() {
bool MultiplayerLocalPlayer::isLocalPlayer() { return true; }
void MultiplayerLocalPlayer::sendRidingJump() {
connection->send(
std::shared_ptr<PlayerCommandPacket>(new PlayerCommandPacket(
shared_from_this(), PlayerCommandPacket::RIDING_JUMP,
(int)(getJumpRidingScale() * 100.0f))));
}
void MultiplayerLocalPlayer::sendOpenInventory() {
connection->send(
std::shared_ptr<PlayerCommandPacket>(new PlayerCommandPacket(
shared_from_this(), PlayerCommandPacket::OPEN_INVENTORY)));
}
void MultiplayerLocalPlayer::ride(std::shared_ptr<Entity> e) {
bool wasRiding = riding != NULL;
LocalPlayer::ride(e);
bool isRiding = riding != NULL;
// 4J Added
if (wasRiding && !isRiding) {
setSneaking(false);
input->sneaking = false;
}
if (isRiding) {
ETelemetryChallenges eventType = eTelemetryChallenges_Unknown;
if (this->riding != NULL) {
@@ -301,8 +351,6 @@ void MultiplayerLocalPlayer::ride(std::shared_ptr<Entity> e) {
case eTYPE_PIG:
eventType = eTelemetryInGame_Ride_Pig;
break;
default:
break;
};
}
TelemetryManager->RecordEnemyKilledOrOvercome(GetXboxPad(), 0, y, 0, 0,
@@ -320,12 +368,7 @@ void MultiplayerLocalPlayer::ride(std::shared_ptr<Entity> e) {
gameMode->getTutorial()->changeTutorialState(
e_Tutorial_State_Gameplay);
} else if (!wasRiding && isRiding) {
if (std::dynamic_pointer_cast<Minecart>(e) != NULL)
gameMode->getTutorial()->changeTutorialState(
e_Tutorial_State_Riding_Minecart);
else if (std::dynamic_pointer_cast<Boat>(e) != NULL)
gameMode->getTutorial()->changeTutorialState(
e_Tutorial_State_Riding_Boat);
gameMode->getTutorial()->onRideEntity(e);
}
}
}
@@ -363,3 +406,78 @@ void MultiplayerLocalPlayer::setAndBroadcastCustomCape(std::uint32_t capeId) {
shared_from_this(), TextureChangePacket::e_TextureChange_Cape,
app.GetPlayerCapeName(GetXboxPad()))));
}
// 4J added for testing. This moves the player in a repeated sequence of 2
// modes: Mode 0 - teleports to random location in the world, and waits for the
// number of chunks that are fully loaded/created to have setting for 2 seconds
// before changing to mode 1 Mode 1 - picks a random direction to move in for
// 200 ticks (~10 seconds), repeating for a total of 2000 ticks, before cycling
// back to mode 0 Whilst carrying out this movement pattern, this calls
// checkAllPresentChunks which checks the integrity of all currently
// loaded/created chunks round the player.
#ifdef STRESS_TEST_MOVE
void MultiplayerLocalPlayer::StressTestMove(double* tempX, double* tempY,
double* tempZ) {
static volatile int64_t lastChangeTime = 0;
static volatile int64_t lastTeleportTime = 0;
static int lastCount = 0;
static int stressTestCount = 0;
const int dirChangeTickCount = 200;
int64_t currentTime = System::currentTimeMillis();
bool faultFound = false;
int count = Minecraft::GetInstance()->levelRenderer->checkAllPresentChunks(
&faultFound);
/*
if( faultFound )
{
app.DebugPrintf("Fault found\n");
stressTestEnabled = false;
}
*/
if (count != lastCount) {
lastChangeTime = currentTime;
lastCount = count;
}
static float angle = 30.0;
static float dx = cos(30.0);
static float dz = sin(30.0);
#if 0
if( ( stressTestCount % dirChangeTickCount) == 0 )
{
int angledeg = rand() % 360;
angle = (((double)angledeg) / 360.0 ) * ( 2.0 * 3.141592654 );
dx = cos(angle);
dz = sin(angle);
}
#endif
float nx = x + (dx * 1.2);
float nz = z + (dz * 1.2);
float ny = y;
if (ny < 140.0f) ny += 0.5f;
if (nx > 2539.0) {
nx = 2539.0;
dx = -dx;
}
if (nz > 2539.0) {
nz = 2539.0;
dz = -dz;
}
if (nx < -2550.0) {
nx = -2550.0;
dx = -dx;
}
if (nz < -2550.0) {
nz = -2550.0;
dz = -dz;
}
absMoveTo(nx, ny, nz, yRot, xRot);
stressTestCount++;
}
#endif