Skip to content

Commit

Permalink
fix: fix faulty off-hand behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
futrime committed Oct 22, 2023
1 parent a872cc9 commit d0ccf9a
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [2.3.1] - 2023-10-22

### Fixed

- Faulty off-hand beharivors.

## [2.3.0] - 2023-10-18

### Changed

- Adapt to BDS 1.20.31 and LiteLoaderBDS 2.16.2.

[Unreleased]: https://github.com/Futrime/CSharpProjectTemplate/compare/v2.3.0...HEAD
[Unreleased]: https://github.com/Futrime/CSharpProjectTemplate/compare/v2.3.1...HEAD
[2.3.1]: https://github.com/Futrime/CSharpProjectTemplate/compare/v2.3.0...v2.3.1
[2.3.0]: https://github.com/Futrime/CSharpProjectTemplate/releases/tag/v2.3.0
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ lip install github.com/tooth-hub/movinglight

## Usage

### How To Switch Item To Off-Hand
- Take the item and try to break the block.
To put a light source item to your off-hand, just grab it in your main hand and swing your arm.

### Configuration File

### Configuration file
```json5
// Generally speaking, you don't need to modify them.
{
Expand Down
1 change: 1 addition & 0 deletions include/light_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <llapi/utils/CsLock.h>

#include <llapi/mc/BlockSource.hpp>
#include <llapi/mc/Dimension.hpp>
#include <llapi/mc/HashedString.hpp>
#include <llapi/mc/Tick.hpp>

Expand Down
3 changes: 1 addition & 2 deletions src/hook.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <llapi/HookAPI.h>
#include <llapi/LoggerAPI.h>

#include <llapi/mc/Block.hpp>
#include <llapi/mc/Player.hpp>
Expand All @@ -11,7 +12,6 @@ extern Config config;
extern LightManager lightManager;

// Remove

TInstanceHook(ItemActor*, "??_EItemActor@@UEAAPEAXI@Z", ItemActor, char a2) {
lightManager.clear((identity_t)this);
return original(this, a2);
Expand All @@ -23,7 +23,6 @@ TInstanceHook(void, "??1Player@@UEAA@XZ", Player) {
}

// Tick

TInstanceHook(void, "?normalTick@Player@@UEAAXXZ", Player) {
original(this);
if (!config.isEnabled() || !hasDimension()) return;
Expand Down
10 changes: 6 additions & 4 deletions src/light_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ extern Config config;

LightManager::LightManager() noexcept {
Schedule::repeat([this] { _runBadAreaJanitor(); }, 20);
Event::PlayerDestroyBlockEvent::subscribe(
[](const Event::PlayerDestroyBlockEvent& ev) -> bool {
Event::PlayerSwingEvent::subscribe(
[](const Event::PlayerSwingEvent& ev) -> bool {
if (!config.isEnabled()) {
return true;
}
Expand All @@ -30,16 +30,18 @@ LightManager::LightManager() noexcept {
return true;
}
auto newHand = mainHand.clone_s();
newHand->set(1);
// newHand->;
if (config.isLightSource(newHand->getFullNameHash()) &&
pl->getOffhandSlot().isNull()) {
pl->getInventory().removeItem_s(pl->getSelectedItemSlot(),
mainHand.getCount());
pl->getInventory().removeItem_s(pl->getSelectedItemSlot(), 1);
pl->setOffhandSlot(*newHand);
pl->sendInventory(mainHand);
return false;
}
return true;
});

Event::ConsoleCmdEvent::subscribe(
[this](const Event::ConsoleCmdEvent& ev) -> bool {
if (ev.mCommand == "stop") {
Expand Down
22 changes: 7 additions & 15 deletions src/plugin.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <llapi/EventAPI.h>
#include <llapi/LoggerAPI.h>

#include <filesystem>
Expand All @@ -12,17 +13,12 @@ LightManager lightManager;

Logger logger("MovingLight");

ll::Version PLUGIN_VERSION{2, 1, 2, ll::Version::Release};

void PluginMain() {
logger.info("loaded, ver " + PLUGIN_VERSION.toString() +
", author: redbeanw.");
}
ll::Version PLUGIN_VERSION{2, 3, 1, ll::Version::Release};

void PluginInit() {
if (!std::filesystem::exists(DATA_PATH)) {
logger.warn(
"Could not find the directory for the configuration file, creating...");
"No configuration file found, creating a new one with default values.");
std::filesystem::create_directory(DATA_PATH);
}

Expand All @@ -31,13 +27,9 @@ void PluginInit() {
// Register plugin to LL.

ll::registerPlugin(
"MovingLight", "Items always emit light~", PLUGIN_VERSION,
"MovingLight",
"Enabling you to hold a light source in your hand and move it around",
PLUGIN_VERSION,
{{"Author", "RedbeanW"},
{"Github", "https://github.com/Redbeanw44602/MovingLight"}});

Event::ServerStartedEvent::subscribe(
[](Event::ServerStartedEvent ev) -> bool {
PluginMain();
return true;
});
{"Github", "https://github.com/LiteLDev/MovingLight"}});
}

0 comments on commit d0ccf9a

Please sign in to comment.