generated from LiteLDev/liteloaderbds-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
669 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "PlayerState.h" | ||
#include "utils/Serialize.h" | ||
#include "worldedit/WorldEdit.h" | ||
|
||
namespace we { | ||
|
||
PlayerState::PlayerState(mce::UUID const& uuid) : uuid(uuid) {} | ||
|
||
void PlayerState::setMainPosInternal() { | ||
if (mainPos) { | ||
auto& we = WorldEdit::getInstance(); | ||
mainPos->geo = we.getGeo().box( | ||
mainPos->data.dim, | ||
AABB{mainPos->data.pos}.shrink(-0.07), | ||
we.getConfig().colors.main_hand_color | ||
); | ||
} | ||
} | ||
void PlayerState::setVicePosInternal() { | ||
if (vicePos) { | ||
auto& we = WorldEdit::getInstance(); | ||
vicePos->geo = we.getGeo().box( | ||
vicePos->data.dim, | ||
AABB{vicePos->data.pos}.shrink(-0.07), | ||
we.getConfig().colors.off_hand_color | ||
); | ||
} | ||
} | ||
Region& PlayerState::getOrCreateRegion(WithDim<BlockPos> const& v) { | ||
if (!region || region->getDim() != v.dim) { | ||
region = | ||
Region::create(regionType.value_or(config.default_region_type), v.dim, v.pos); | ||
regionType = region->getType(); | ||
mDirty = true; | ||
} | ||
return *region; | ||
} | ||
bool PlayerState::setMainPos(WithDim<BlockPos> const& v) { | ||
if (auto& r = getOrCreateRegion(v); r.setMainPos(v.pos)) { | ||
mainPos.emplace(v); | ||
setMainPosInternal(); | ||
if (r.needResetVice()) { | ||
vicePos.reset(); | ||
} | ||
mDirty = true; | ||
return true; | ||
} | ||
return false; | ||
} | ||
bool PlayerState::setVicePos(WithDim<BlockPos> const& v) { | ||
if (getOrCreateRegion(v).setVicePos(v.pos)) { | ||
vicePos.emplace(v); | ||
setVicePosInternal(); | ||
mDirty = true; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void PlayerState::serialize(CompoundTag& nbt) const { | ||
if (mainPos) doSerialize(mainPos->data, nbt["mainPos"]); | ||
if (vicePos) doSerialize(vicePos->data, nbt["vicePos"]); | ||
if (regionType) doSerialize(*regionType, nbt["regionType"]); | ||
if (region) region->serialize(nbt["region"].emplace<CompoundTag>()); | ||
} | ||
void PlayerState::deserialize(CompoundTag const& nbt) { | ||
if (nbt.contains("mainPos")) { | ||
mainPos.emplace(); | ||
ll::reflection::deserialize(mainPos->data, nbt["mainPos"]); | ||
setMainPosInternal(); | ||
} | ||
if (nbt.contains("vicePos")) { | ||
vicePos.emplace(); | ||
ll::reflection::deserialize(vicePos->data, nbt["vicePos"]); | ||
setVicePosInternal(); | ||
} | ||
if (nbt.contains("regionType")) { | ||
ll::reflection::deserialize(*regionType, nbt["regionType"]); | ||
} | ||
if (nbt.contains("region")) { | ||
region = Region::create(nbt["region"].get<CompoundTag>()); | ||
} | ||
} | ||
} // namespace we |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#pragma once | ||
|
||
#include "region/Region.h" | ||
#include "Config.h" | ||
|
||
#include <mc/deps/core/mce/UUID.h> | ||
#include <mc/world/level/Tick.h> | ||
|
||
namespace we { | ||
class PlayerStateManager; | ||
class PlayerState { | ||
friend PlayerStateManager; | ||
std::atomic_bool mutable mDirty; | ||
std::atomic<std::chrono::system_clock::time_point> mutable lastUsedTime; | ||
|
||
std::atomic<Tick> mutable lastLeftClick; | ||
std::atomic<Tick> mutable lastRightClick; | ||
|
||
mce::UUID uuid; | ||
|
||
std::optional<WithGeo<WithDim<BlockPos>>> mainPos; | ||
std::optional<WithGeo<WithDim<BlockPos>>> vicePos; | ||
|
||
std::optional<RegionType> regionType; | ||
std::shared_ptr<Region> region; | ||
|
||
void setMainPosInternal(); | ||
void setVicePosInternal(); | ||
|
||
Region& getOrCreateRegion(WithDim<BlockPos> const&); | ||
|
||
public: | ||
Config::PlayerConfig config; | ||
|
||
bool dirty() const { return mDirty; } | ||
|
||
PlayerState(mce::UUID const& uuid); | ||
|
||
bool setMainPos(WithDim<BlockPos> const&); | ||
bool setVicePos(WithDim<BlockPos> const&); | ||
|
||
void serialize(CompoundTag&) const; | ||
void deserialize(CompoundTag const&); | ||
}; | ||
} // namespace we |
Oops, something went wrong.