Skip to content

Commit

Permalink
fix: fix Player/Entity::isOnHotBlock
Browse files Browse the repository at this point in the history
feat(tests): add player attributes test
  • Loading branch information
ShrBox committed Jan 29, 2025
1 parent 2f6e4a4 commit 8973686
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 14 deletions.
3 changes: 2 additions & 1 deletion src/legacy/api/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "mc/world/phys/AABB.h"
#include "mc/world/phys/HitResult.h"
#include "mc/world/level/biome/Biome.h"
#include "mc/entity/components/IsOnHotBlockFlagComponent.h"

#include <climits>
#include <memory>
Expand Down Expand Up @@ -292,7 +293,7 @@ Local<Value> EntityClass::isOnHotBlock() {
Actor* entity = get();
if (!entity) return Local<Value>();

return Boolean::newBoolean(false); // TODO: check IsOnHotBlockTest to get the correct value
return Boolean::newBoolean(entity->getEntityContext().hasComponent<IsOnHotBlockFlagComponent>());
}
CATCH("Fail in isOnHotBlock!")
}
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/api/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
#include "mc/world/level/biome/Biome.h"
#include "mc/world/level/material/Material.h"
#include "mc/world/scores/Objective.h"
#include "mc/entity/components/IsOnHotBlockFlagComponent.h"

#include <algorithm>
#include <climits>
Expand Down Expand Up @@ -1235,7 +1236,7 @@ Local<Value> PlayerClass::isOnHotBlock() {
return Local<Value>();
}

return Boolean::newBoolean(false); // TODO: check IsOnHotBlockTest to get the correct value
return Boolean::newBoolean(player->getEntityContext().hasComponent<IsOnHotBlockFlagComponent>());
}
CATCH("Fail in isOnHotBlock!")
}
Expand Down
81 changes: 69 additions & 12 deletions src/tests/LSETests/PlayerTests.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,83 @@
export function TestPlayer(players) {
for (let player of players) {
GetFromViewVector(player)
PrintPlayerAttributes(player)
}
}

function GetFromViewVector(player) {
let en = player.getEntityFromViewVector(5.25)
let en = player.getEntityFromViewVector(5.25);
if (en) {
logger.info(`Entity: ${en.name}`)
let bl = player.getBlockFromViewVector(true, false, player.distanceTo(en), false)
if (bl) {
logger.info(`Block: ${bl.name} ${bl.pos}`)
} else {
logger.info(`No block found`)
}
logger.info(`Entity looking at: ${en.name}`);
logBlock(player.getBlockFromViewVector(true, false, player.distanceTo(en), false));
} else {
logger.info(`No entity found`)
let bl = player.getBlockFromViewVector(true, false, 5.25, false)
logger.info(`No entity looking at found`);
logBlock(player.getBlockFromViewVector(true, false, 5.25, false));
}

function logBlock(bl) {
if (bl) {
logger.info(`Block: ${bl.name} ${bl.pos}`)
logger.info(`Block looking at: ${bl.name} ${bl.pos}`);
} else {
logger.info(`No block found`)
logger.info(`No Block looking at found`);
}
}
}

function PrintPlayerAttributes(player) {
logger.info(`Name: ${player.name}`);
logger.info(`Position: ${player.pos}`);
logger.info(`Feet Position: ${player.feetPos}`);
logger.info(`Block Position: ${player.blockPos}`);
logger.info(`Last Death Position: ${player.lastDeathPos}`);
logger.info(`Real Name: ${player.realName}`);
logger.info(`XUID: ${player.xuid}`);
logger.info(`UUID: ${player.uuid}`);
logger.info(`Permission Level: ${player.permLevel}`);
logger.info(`Game Mode: ${player.gameMode}`);
logger.info(`Can Sleep: ${player.canSleep}`);
logger.info(`Can Fly: ${player.canFly}`);
logger.info(`Can Be Seen On Map: ${player.canBeSeenOnMap}`);
logger.info(`Can Freeze: ${player.canFreeze}`);
logger.info(`Can See Daylight: ${player.canSeeDaylight}`);
logger.info(`Can Show Name Tag: ${player.canShowNameTag}`);
logger.info(`Can Start Sleep In Bed: ${player.canStartSleepInBed}`);
logger.info(`Can Pickup Items: ${player.canPickupItems}`);
logger.info(`Max Health: ${player.maxHealth}`);
logger.info(`Health: ${player.health}`);
logger.info(`In Air: ${player.inAir}`);
logger.info(`In Water: ${player.inWater}`);
logger.info(`In Lava: ${player.inLava}`);
logger.info(`In Rain: ${player.inRain}`);
logger.info(`In Snow: ${player.inSnow}`);
logger.info(`In Wall: ${player.inWall}`);
logger.info(`In Water Or Rain: ${player.inWaterOrRain}`);
logger.info(`In World: ${player.inWorld}`);
logger.info(`In Clouds: ${player.inClouds}`);
logger.info(`Speed: ${player.speed}`);
logger.info(`Direction: ${player.direction}`);
logger.info(`Unique ID: ${player.uniqueId}`);
logger.info(`Language Code: ${player.langCode}`);
logger.info(`Is Loading: ${player.isLoading}`);
logger.info(`Is Invisible: ${player.isInvisible}`);
logger.info(`Is Inside Portal: ${player.isInsidePortal}`);
logger.info(`Is Hurt: ${player.isHurt}`);
logger.info(`Is Trusting: ${player.isTrusting}`);
logger.info(`Is Touching Damage Block: ${player.isTouchingDamageBlock}`);
logger.info(`Is Hungry: ${player.isHungry}`);
logger.info(`Is On Fire: ${player.isOnFire}`);
logger.info(`Is On Ground: ${player.isOnGround}`);
logger.info(`Is On Hot Block: ${player.isOnHotBlock}`);
logger.info(`Is Trading: ${player.isTrading}`);
logger.info(`Is Adventure: ${player.isAdventure}`);
logger.info(`Is Gliding: ${player.isGliding}`);
logger.info(`Is Survival: ${player.isSurvival}`);
logger.info(`Is Spectator: ${player.isSpectator}`);
logger.info(`Is Riding: ${player.isRiding}`);
logger.info(`Is Dancing: ${player.isDancing}`);
logger.info(`Is Creative: ${player.isCreative}`);
logger.info(`Is Flying: ${player.isFlying}`);
logger.info(`Is Sleeping: ${player.isSleeping}`);
logger.info(`Is Moving: ${player.isMoving}`);
logger.info(`Is Sneaking: ${player.isSneaking}`);
}

0 comments on commit 8973686

Please sign in to comment.