Skip to content

Commit

Permalink
fix: fix Teleport.cpp
Browse files Browse the repository at this point in the history
fix: fix SimulatedPlayer.cpp
  • Loading branch information
ShrBox committed Feb 20, 2025
1 parent 0305ca5 commit 8ef6b3e
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 25 deletions.
29 changes: 15 additions & 14 deletions src/ll/core/command/Teleport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
#include "ll/api/command/CommandHandle.h"
#include "ll/api/command/CommandRegistrar.h"
#include "ll/api/i18n/I18n.h"
#include "ll/api/service/GamingStatus.h"
#include "ll/core/Config.h"

#include "mc/server/commands/CommandOrigin.h"
#include "mc/server/commands/CommandOutput.h"
#include "mc/server/commands/CommandPositionFloat.h"
#include "mc/server/commands/CommandSelector.h"
#include "mc/world/actor/Actor.h"
#include "mc/world/actor/ActorDefinitionIdentifier.h"
#include "mc/world/level/DimensionConversionData.h"
#include "mc/world/level/Level.h"
#include "mc/world/level/dimension/Dimension.h"
Expand Down Expand Up @@ -62,14 +62,13 @@ void registerTpdimCommand() {
return;
}
self->teleport(pos, param.dimension);
auto& dimNameMap = VanillaDimensions::DimensionMap();
std::string dimName;
if (dimNameMap.contains(param.dimension)) {
dimName = dimNameMap.at(param.dimension);
} else {
dimName = fmt::format("dimension.dimensionName{}", param.dimension.id);
}
output.success("Teleported {0} to {1} {2}"_tr(origin.getName(), dimName, pos.toString()));
output.success(
"Teleported {0} to {1} {2}"_tr(
origin.getName(),
VanillaDimensions::toString(param.dimension),
pos.toString()
)
);
});
cmd.overload<TpTarget>()
.required("victim")
Expand Down Expand Up @@ -98,11 +97,13 @@ void registerTpdimCommand() {
for (auto actor : victim) {
actor->teleport(pos, param.dimension);
}
output.success("Teleported {0} to {1} {2}"_tr(
CommandOutputParameter{victim}.mString,
VanillaDimensions::toString(param.dimension),
pos.toString()
));
output.success(
"Teleported {0} to {1} {2}"_tr(
CommandOutputParameter{victim}.mString,
VanillaDimensions::toString(param.dimension),
pos.toString()
)
);
});
}
} // namespace ll::command
40 changes: 34 additions & 6 deletions src/mc/server/SimulatedPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#include "ll/api/service/Bedrock.h"
#include "ll/api/utils/RandomUtils.h"
#include "mc/deps/core/string/HashedString.h"
#include "mc/deps/game_refs/OwnerPtr.h"
#include "mc/network/ServerNetworkHandler.h"
#include "mc/server/ServerLevel.h"
#include "mc/world/actor/player/Inventory.h"
#include "mc/world/actor/player/PlayerItemInUse.h"
#include "mc/world/level/BlockSource.h"
#include "mc/world/level/block/Block.h"
#include "mc/world/phys/HitResult.h"

optional_ref<SimulatedPlayer> SimulatedPlayer::create(
Expand All @@ -20,21 +23,46 @@ optional_ref<SimulatedPlayer> SimulatedPlayer::create(
if (!player) {
return nullptr;
}
player->postLoad(true);
player->getLevel().addUser(std::move(ownerPtr));
player->mInventory->mUnk53f793.as<std::unique_ptr<Inventory>>()->setupDefault();
player->mLevel->addUser(std::move(ownerPtr));
if (!pos) {
player->setLocalPlayerAsInitialized();
player->mUnk26a7dc.as<bool>() = true;
player->doInitialSpawn();
return player;
}
player->setRespawnReady(*pos + Vec3{0, 1.62001, 0});
player->mRespawnPositionCandidate = *pos + Vec3{0, 1.62001, 0};
player->mRespawnReady = true;
player->mRespawningFromTheEnd = false;
player->setRespawnPosition(*pos, dimId);
player->setLocalPlayerAsInitialized();
player->mUnk26a7dc.as<bool>() = true;
player->doInitialSpawn();
player->teleport(*pos, dimId, rotation);
return player;
}

bool SimulatedPlayer::simulateDestroyBlock(const BlockPos& pos, ScriptModuleMinecraft::ScriptFacing face) {
if (this->isAlive()) {
if (this->mDestroyingBlockPos->has_value() && this->mDestroyingBlockFace->has_value()) {
if (pos.x == this->mDestroyingBlockPos->value_or(BlockPos::ZERO()).x
&& pos.y == this->mDestroyingBlockPos->value_or(BlockPos::ZERO()).y
&& pos.z == this->mDestroyingBlockPos->value_or(BlockPos::ZERO()).z
&& (uchar)face == this->mDestroyingBlockFace->value()) {
return true;
}
this->simulateStopDestroyingBlock();
}

BlockLegacy const& block = this->getDimensionBlockSource().getBlock(pos).getLegacyBlock();

if (block.mayPick() && !this->mItemInUse->mUnkf0096a.as<ItemStack>().isNull()) {
this->mDestroyingBlockPos = pos;
this->mDestroyingBlockFace = (uchar)face;
return true;
}
}
return false;
}

bool SimulatedPlayer::simulateDestroyLookAt(float handLength) {

auto hitResult = traceRay(handLength, false);
Expand Down
14 changes: 9 additions & 5 deletions src/mc/server/SimulatedPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "mc/_HeaderOutputPredefine.h"
#include "mc/deps/core/math/Vec2.h"
#include "mc/deps/core/math/Vec3.h"
#include "mc/world/actor/player/PlayerInventory.h"

// auto generated inclusion list
#include "mc/common/SubClientId.h"
Expand All @@ -11,6 +12,7 @@
#include "mc/scripting/modules/minecraft/ScriptFacing.h"
#include "mc/server/ServerPlayer.h"
#include "mc/world/actor/ActorInitializationMethod.h"
#include "mc/world/actor/provider/SynchedActorDataAccess.h"
#include "mc/world/level/GameType.h"

// auto generated forward declare list
Expand Down Expand Up @@ -54,13 +56,15 @@ class SimulatedPlayer : public ::ServerPlayer {

[[nodiscard]] inline bool simulateSneaking() {
setSneaking(true);
return isSneaking();
return SynchedActorDataAccess::getActorFlag(getEntityContext(), ActorFlags::Sneaking);
}
[[nodiscard]] inline bool simulateStopSneaking() {
setSneaking(false);
return !isSneaking();
return !SynchedActorDataAccess::getActorFlag(getEntityContext(), ActorFlags::Sneaking);
}
inline bool simulateUseItem() { return simulateUseItemInSlot(getSelectedItemSlot()); }
inline bool simulateUseItem() { return simulateUseItemInSlot(mInventory->mUnkb0b19d.as<int>()); }

LLAPI bool simulateDestroyBlock(BlockPos const&, ScriptModuleMinecraft::ScriptFacing);

LLAPI bool simulateDestroyLookAt(float handLength = 5.5f);

Expand Down Expand Up @@ -143,8 +147,8 @@ class SimulatedPlayer : public ::ServerPlayer {

MCAPI void _addMoveComponent();

MCAPI ::ScriptModuleGameTest::ScriptNavigationResult _createNavigationResult(::NavigationComponent* navigation
) const;
MCAPI ::ScriptModuleGameTest::ScriptNavigationResult
_createNavigationResult(::NavigationComponent* navigation) const;

MCFOLD ::BlockSource& _getRegion();

Expand Down
12 changes: 12 additions & 0 deletions src/mc/world/level/dimension/VanillaDimensions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include "mc/world/level/dimension/VanillaDimensions.h"

std::string VanillaDimensions::toString(DimensionType const& dimension) {
auto& dimNameMap = VanillaDimensions::DimensionMap();
std::string dimName;
if (dimNameMap.contains(dimension)) {
dimName = dimNameMap.at(dimension);
} else {
dimName = fmt::format("dimension.dimensionName{}", dimension.id);
}
return dimName;
}
2 changes: 2 additions & 0 deletions src/mc/world/level/dimension/VanillaDimensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Vec3;
// clang-format on

class VanillaDimensions {
public:
LLNDAPI static std::string toString(DimensionType const& dimension);
public:
// static functions
// NOLINTBEGIN
Expand Down

0 comments on commit 8ef6b3e

Please sign in to comment.