Skip to content

Commit 4582414

Browse files
committed
fix: fix onDropItem #110
1 parent 0f54950 commit 4582414

File tree

11 files changed

+61
-15
lines changed

11 files changed

+61
-15
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.7.3] - 2024-05-01
9+
10+
### Fixed
11+
12+
- Fix getRespawnPosition [#115]
13+
- Fix onDropItem [#110]
14+
815
## [0.7.2] - 2024-04-29
916

1017
### Fixed
@@ -324,7 +331,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
324331
[#101]: https://github.com/LiteLDev/LegacyScriptEngine/issues/101
325332
[#102]: https://github.com/LiteLDev/LegacyScriptEngine/issues/102
326333
[#104]: https://github.com/LiteLDev/LegacyScriptEngine/issues/104
334+
[#110]: https://github.com/LiteLDev/LegacyScriptEngine/issues/110
335+
[#115]: https://github.com/LiteLDev/LegacyScriptEngine/issues/115
327336

337+
[0.7.3]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.7.2...v0.7.3
338+
[0.7.2]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.7.1...v0.7.2
328339
[0.7.1]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.7.0...v0.7.1
329340
[0.7.0]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.6.4...v0.7.0
330341
[0.6.4]: https://github.com/LiteLDev/LegacyScriptEngine/compare/v0.6.3...v0.6.4

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"type": "native",
55
"description": "A plugin engine for running LLSE plugins on LeviLamina",
66
"author": "LiteLDev",
7-
"version": "0.7.2",
7+
"version": "0.7.3",
88
"dependencies": [
99
{
1010
"name": "LegacyMoney"

src/legacy/api/EntityAPI.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "ll/api/service/Bedrock.h"
1515
#include "mc/common/HitDetection.h"
1616
#include "mc/dataloadhelper/DataLoadHelper.h"
17+
#include "mc/deps/core/string/HashedString.h"
1718
#include "mc/entity/utilities/ActorDamageCause.h"
1819
#include "mc/entity/utilities/ActorType.h"
1920
#include "mc/enums/FacingID.h"
@@ -24,6 +25,7 @@
2425
#include "mc/world/level/block/Block.h"
2526

2627
#include <magic_enum.hpp>
28+
#include <mc/deps/core/string/HashedString.h>
2729
#include <mc/entity/EntityContext.h>
2830
#include <mc/entity/utilities/ActorEquipment.h>
2931
#include <mc/entity/utilities/ActorMobilityUtils.h>
@@ -1458,7 +1460,7 @@ Local<Value> EntityClass::getBiomeId() {
14581460
Actor* actor = get();
14591461
if (!actor) return Local<Value>();
14601462
auto& bio = actor->getDimensionBlockSource().getBiome(actor->getFeetBlockPos());
1461-
return Number::newNumber(bio.getId());
1463+
return Number::newNumber(ll::memory::dAccess<int>(&bio, 0x80));
14621464
}
14631465
CATCH("Fail in getBiomeId!");
14641466
}
@@ -1468,7 +1470,7 @@ Local<Value> EntityClass::getBiomeName() {
14681470
Actor* actor = get();
14691471
if (!actor) return Local<Value>();
14701472
auto& bio = actor->getDimensionBlockSource().getBiome(actor->getFeetBlockPos());
1471-
return String::newString(bio.getName().getString());
1473+
return String::newString(ll::memory::dAccess<HashedString>(&bio, 0x08).getString());
14721474
}
14731475
CATCH("Fail in getBiomeName!");
14741476
}

src/legacy/api/PlayerAPI.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,7 @@ Local<Value> PlayerClass::getBiomeId() {
34683468
Player* player = get();
34693469
if (!player) return Local<Value>();
34703470
Biome& bio = player->getDimensionBlockSource().getBiome(player->getFeetBlockPos());
3471-
return Number::newNumber(bio.getId());
3471+
return Number::newNumber(ll::memory::dAccess<int>(&bio, 0x80));
34723472
}
34733473
CATCH("Fail in getBiomeId!");
34743474
}
@@ -3478,7 +3478,7 @@ Local<Value> PlayerClass::getBiomeName() {
34783478
Player* player = get();
34793479
if (!player) return Local<Value>();
34803480
Biome& bio = player->getDimensionBlockSource().getBiome(player->getFeetBlockPos());
3481-
return String::newString(bio.getName().getString());
3481+
return String::newString(ll::memory::dAccess<HashedString>(&bio, 0x08).getString());
34823482
}
34833483
CATCH("Fail in getBiomeName!");
34843484
}

src/legacy/events/EventHooks.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "mc/server/commands/CommandOrigin.h"
1212
#include "mc/server/commands/CommandOriginType.h"
1313
#include "mc/world/ActorUniqueID.h"
14+
#include "mc/world/containers/ContainerID.h"
15+
#include "mc/world/inventory/transaction/InventorySource.h"
1416
#include "mc/world/scores/ScoreInfo.h"
1517

1618
#include <ll/api/memory/Hook.h>
@@ -28,6 +30,7 @@
2830
#include <mc/world/actor/player/Player.h>
2931
#include <mc/world/containers/models/LevelContainerModel.h>
3032
#include <mc/world/events/EventResult.h>
33+
#include <mc/world/inventory/transaction/ComplexInventoryTransaction.h>
3134
#include <mc/world/item/BucketItem.h>
3235
#include <mc/world/item/CrossbowItem.h>
3336
#include <mc/world/item/ItemInstance.h>
@@ -84,7 +87,7 @@ LL_TYPE_INSTANCE_HOOK(
8487
}
8588

8689
LL_TYPE_INSTANCE_HOOK(
87-
PlayerDropItemHook,
90+
PlayerDropItemHook1,
8891
HookPriority::Normal,
8992
Player,
9093
"?drop@Player@@UEAA_NAEBVItemStack@@_N@Z",
@@ -104,6 +107,33 @@ LL_TYPE_INSTANCE_HOOK(
104107
return origin(item, randomly);
105108
}
106109

110+
LL_TYPE_INSTANCE_HOOK(
111+
PlayerDropItemHook2,
112+
HookPriority::Normal,
113+
ComplexInventoryTransaction,
114+
"?handle@ComplexInventoryTransaction@@UEBA?AW4InventoryTransactionError@@AEAVPlayer@@_N@Z",
115+
InventoryTransactionError,
116+
Player& player,
117+
bool isSenderAuthority
118+
) {
119+
if (type == ComplexInventoryTransaction::Type::NormalTransaction) {
120+
IF_LISTENED(EVENT_TYPES::onDropItem) {
121+
InventorySource source(InventorySourceType::ContainerInventory, ContainerID::Inventory);
122+
auto& actions = data.getActions(source);
123+
if (actions.size() == 1) {
124+
CallEventRtnValue(
125+
EVENT_TYPES::onDropItem,
126+
InventoryTransactionError::NoError,
127+
PlayerClass::newPlayer(&player),
128+
ItemClass::newItem(&const_cast<ItemStack&>(player.getInventory().getItem(actions[0].mSlot)), false)
129+
);
130+
}
131+
}
132+
IF_LISTENED_END(EVENT_TYPES::onDropItem);
133+
}
134+
return origin(player, isSenderAuthority);
135+
}
136+
107137
LL_TYPE_INSTANCE_HOOK(
108138
PlayerOpenContainerHook,
109139
HookPriority::Normal,
@@ -1008,7 +1038,10 @@ LL_TYPE_INSTANCE_HOOK(
10081038
}
10091039

10101040
void PlayerStartDestroyBlock() { PlayerStartDestroyHook::hook(); }
1011-
void PlayerDropItem() { PlayerDropItemHook::hook(); }
1041+
void PlayerDropItem() {
1042+
PlayerDropItemHook1::hook();
1043+
PlayerDropItemHook2::hook();
1044+
}
10121045
void PlayerOpenContainerEvent() { PlayerOpenContainerHook::hook(); }
10131046
void PlayerCloseContainerEvent() {
10141047
PlayerCloseContainerHook1::hook();

tooth.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "github.com/LiteLDev/LegacyScriptEngine",
4-
"version": "0.7.2",
4+
"version": "0.7.3",
55
"info": {
66
"name": "LegacyScriptEngine",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",
@@ -12,7 +12,7 @@
1212
]
1313
},
1414
"dependencies": {
15-
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.7.2",
16-
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.7.2"
15+
"gitea.litebds.com/LiteLDev/legacy-script-engine-lua": "0.7.3",
16+
"gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs": "0.7.3"
1717
}
1818
}

tooth.lua.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-lua",
4-
"version": "0.7.2",
4+
"version": "0.7.3",
55
"info": {
66
"name": "LegacyScriptEngine with Lua backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.nodejs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-nodejs",
4-
"version": "0.7.2",
4+
"version": "0.7.3",
55
"info": {
66
"name": "LegacyScriptEngine with NodeJs backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.python.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-python",
4-
"version": "0.7.2",
4+
"version": "0.7.3",
55
"info": {
66
"name": "LegacyScriptEngine with Python backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

tooth.quickjs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"format_version": 2,
33
"tooth": "gitea.litebds.com/LiteLDev/legacy-script-engine-quickjs",
4-
"version": "0.7.2",
4+
"version": "0.7.3",
55
"info": {
66
"name": "LegacyScriptEngine with QuickJs backend",
77
"description": "A plugin engine for running LLSE plugins on LeviLamina",

0 commit comments

Comments
 (0)