Skip to content

Commit 359783f

Browse files
committed
Adapte for 1.21.60-2
1 parent 31dee98 commit 359783f

File tree

13 files changed

+353
-145
lines changed

13 files changed

+353
-145
lines changed

Diff for: src/coral_fans/commands/Func.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ void registerFuncCommand(CommandPermissionLevel permission) {
6969
.execute([](CommandOrigin const&, CommandOutput& output, ll::command::RuntimeCommand const& self) {
7070
bool isopen = self["isopen"].get<ll::command::ParamKind::Bool>();
7171
if (coral_fans::mod().getConfigDb()->set("functions.global.droppernocost", isopen ? "true" : "false")) {
72-
coral_fans::functions::droppernocost::droppernocostHook(isopen);
72+
coral_fans::functions::droppernocostHook(isopen);
7373
output.success("command.func.droppernocost.success"_tr(isopen ? "true" : "false"));
7474
} else output.error("command.func.droppernocost.error"_tr());
7575
});
76-
coral_fans::functions::droppernocost::droppernocostHook(
76+
coral_fans::functions::droppernocostHook(
7777
coral_fans::mod().getConfigDb()->get("functions.global.droppernocost") == "true"
7878
);
7979

Diff for: src/coral_fans/commands/Tick.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
#include "coral_fans/base/Mod.h"
21
#include "coral_fans/base/MySchedule.h"
32
#include "ll/api/command/CommandHandle.h"
43
#include "ll/api/command/CommandRegistrar.h"
54
#include "ll/api/command/runtime/ParamKind.h"
65
#include "ll/api/command/runtime/RuntimeCommand.h"
76
#include "ll/api/command/runtime/RuntimeOverload.h"
87
#include "ll/api/i18n/I18n.h"
9-
#include "ll/api/io/Logger.h"
108
#include "ll/api/service/Bedrock.h"
119
#include "mc/server/commands/CommandOutput.h"
1210
#include "mc/server/commands/CommandPermissionLevel.h"
1311
#include "mc/server/commands/CommandRegistry.h"
14-
#include "mc/util/ProfilerLite.h"
1512
#include "mc/util/Timer.h"
1613
#include "mc/world/Minecraft.h"
1714

@@ -24,12 +21,6 @@ void registerTickCommand(CommandPermissionLevel permission) {
2421
auto& tickCommand = ll::command::CommandRegistrar::getInstance()
2522
.getOrCreateCommand("tick", "command.tick.description"_tr(), permission);
2623

27-
// tick query
28-
tickCommand.overload().text("query").execute([](CommandOrigin const&, CommandOutput& output) {
29-
output.success("command.tick.query.output"_tr((ProfilerLite::gProfilerLiteInstance().mDebugRemoteServerTickTime)
30-
));
31-
});
32-
3324
// tick freeze|reset
3425
ll::command::CommandRegistrar::getInstance().tryRegisterRuntimeEnum(
3526
"tickFreezeType",

Diff for: src/coral_fans/commands/minerule.cpp

+55-18
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,55 @@ namespace coral_fans::commands {
1313
void registerMineruleCommand(CommandPermissionLevel permission) {
1414
using ll::i18n_literals::operator""_tr;
1515

16-
coral_fans::functions::DropHookManager::getInstance().bedrockDrop =
17-
coral_fans::mod().getConfigDb()->get("minerule.bedrockDrop") == "true";
18-
coral_fans::functions::DropHookManager::getInstance().mbDrop =
19-
coral_fans::mod().getConfigDb()->get("minerule.movingBlockDrop") == "true";
20-
2116
auto& mineruleCommand = ll::command::CommandRegistrar::getInstance()
2217
.getOrCreateCommand("minerule", "command.minerule.description"_tr(), permission);
2318

19+
// mineruleCommand.runtimeOverload()
20+
// .text("fuck_bedrock_no_drop")
21+
// .required("isopen", ll::command::ParamKind::Bool)
22+
// .execute([](CommandOrigin const&, CommandOutput& output, ll::command::RuntimeCommand const& self) {
23+
// bool isopen = self["isopen"].get<ll::command::ParamKind::Bool>();
24+
// if (isopen) {
25+
// if (coral_fans::mod().getConfigDb()->set("minerule.bedrockDrop", "true")) {
26+
// output.success("command.minerule.bedrockDrop.success.true"_tr());
27+
// coral_fans::functions::DropHookManager::getInstance().bedrockDrop = true;
28+
// functions::dropHook();
29+
// } else output.error("command.minerule.bedrockDrop.error"_tr());
30+
// } else {
31+
// if (coral_fans::mod().getConfigDb()->set("minerule.bedrockDrop", "false")) {
32+
// output.success("command.minerule.bedrockDrop.success.false"_tr());
33+
// coral_fans::functions::DropHookManager::getInstance().bedrockDrop = false;
34+
// functions::dropHook();
35+
// } else output.error("command.minerule.bedrockDrop.error"_tr());
36+
// }
37+
// });
38+
39+
// mineruleCommand.runtimeOverload()
40+
// .text("fuck_movingBlock_no_drop")
41+
// .required("isopen", ll::command::ParamKind::Bool)
42+
// .execute([](CommandOrigin const&, CommandOutput& output, ll::command::RuntimeCommand const& self) {
43+
// bool isopen = self["isopen"].get<ll::command::ParamKind::Bool>();
44+
// if (isopen) {
45+
// if (coral_fans::mod().getConfigDb()->set("minerule.movingBlockDrop", "true")) {
46+
// output.success("command.minerule.movingBlockDrop.success.true"_tr());
47+
// coral_fans::functions::DropHookManager::getInstance().mbDrop = true;
48+
// functions::dropHook();
49+
// } else output.error("command.minerule.movingBlockDrop.error"_tr());
50+
// } else {
51+
// if (coral_fans::mod().getConfigDb()->set("minerule.movingBlockDrop", "false")) {
52+
// output.success("command.minerule.movingBlockDrop.success.false"_tr());
53+
// coral_fans::functions::DropHookManager::getInstance().mbDrop = false;
54+
// functions::dropHook();
55+
// } else output.error("command.minerule.movingBlockDrop.error"_tr());
56+
// }
57+
// });
58+
59+
// coral_fans::functions::DropHookManager::getInstance().bedrockDrop =
60+
// coral_fans::mod().getConfigDb()->get("minerule.bedrockDrop") == "true";
61+
// coral_fans::functions::DropHookManager::getInstance().mbDrop =
62+
// coral_fans::mod().getConfigDb()->get("minerule.movingBlockDrop") == "true";
63+
// functions::dropHook();
64+
2465
mineruleCommand.runtimeOverload()
2566
.text("fuck_bedrock_no_drop")
2667
.required("isopen", ll::command::ParamKind::Bool)
@@ -29,17 +70,16 @@ void registerMineruleCommand(CommandPermissionLevel permission) {
2970
if (isopen) {
3071
if (coral_fans::mod().getConfigDb()->set("minerule.bedrockDrop", "true")) {
3172
output.success("command.minerule.bedrockDrop.success.true"_tr());
32-
coral_fans::functions::DropHookManager::getInstance().bedrockDrop = true;
33-
functions::DropHookManager::getInstance().dropHook();
73+
coral_fans::functions::bedrockDropHook(true);
3474
} else output.error("command.minerule.bedrockDrop.error"_tr());
3575
} else {
3676
if (coral_fans::mod().getConfigDb()->set("minerule.bedrockDrop", "false")) {
3777
output.success("command.minerule.bedrockDrop.success.false"_tr());
38-
coral_fans::functions::DropHookManager::getInstance().bedrockDrop = false;
39-
functions::DropHookManager::getInstance().dropHook();
78+
coral_fans::functions::bedrockDropHook(false);
4079
} else output.error("command.minerule.bedrockDrop.error"_tr());
4180
}
4281
});
82+
functions::bedrockDropHook(coral_fans::mod().getConfigDb()->get("minerule.bedrockDrop") == "true");
4383

4484
mineruleCommand.runtimeOverload()
4585
.text("fuck_movingBlock_no_drop")
@@ -49,19 +89,16 @@ void registerMineruleCommand(CommandPermissionLevel permission) {
4989
if (isopen) {
5090
if (coral_fans::mod().getConfigDb()->set("minerule.movingBlockDrop", "true")) {
5191
output.success("command.minerule.movingBlockDrop.success.true"_tr());
52-
coral_fans::functions::DropHookManager::getInstance().mbDrop = true;
53-
functions::DropHookManager::getInstance().dropHook();
92+
coral_fans::functions::mbDropHook(true);
5493
} else output.error("command.minerule.movingBlockDrop.error"_tr());
5594
} else {
5695
if (coral_fans::mod().getConfigDb()->set("minerule.movingBlockDrop", "false")) {
5796
output.success("command.minerule.movingBlockDrop.success.false"_tr());
58-
coral_fans::functions::DropHookManager::getInstance().mbDrop = false;
59-
functions::DropHookManager::getInstance().dropHook();
97+
coral_fans::functions::mbDropHook(false);
6098
} else output.error("command.minerule.movingBlockDrop.error"_tr());
6199
}
62100
});
63-
64-
functions::DropHookManager::getInstance().dropHook();
101+
functions::bedrockDropHook(coral_fans::mod().getConfigDb()->get("minerule.movingBlockDrop") == "true");
65102

66103
mineruleCommand.runtimeOverload()
67104
.text("replicated_portal_sand_farm")
@@ -77,9 +114,7 @@ void registerMineruleCommand(CommandPermissionLevel permission) {
77114
} else output.error("command.minerule.replicated_portal_sand_farm.error"_tr());
78115
});
79116

80-
functions::hook_portal_sand_farm(
81-
coral_fans::mod().getConfigDb()->get("minerule.replicated_portal_sand_farm") == "true"
82-
);
117+
functions::hook_portal_sand_farm(mod().getConfigDb()->get("minerule.replicated_portal_sand_farm") == "true");
83118

84119
mineruleCommand.runtimeOverload()
85120
.text("remove_portal_pigzombie_cd")
@@ -94,5 +129,7 @@ void registerMineruleCommand(CommandPermissionLevel permission) {
94129
functions::portal_spawn_hook(isopen);
95130
} else output.error("command.minerule.remove_portal_pigzombie_cd.error"_tr());
96131
});
132+
133+
functions::portal_spawn_hook(mod().getConfigDb()->get("minerule.remove_portal_pigzombie_cd") == "true");
97134
}
98135
} // namespace coral_fans::commands

Diff for: src/coral_fans/functions/func/AutoTool.cpp

+28-25
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "coral_fans/base/Mod.h"
33
#include "coral_fans/base/Utils.h"
44
#include "ll/api/memory/Hook.h"
5+
#include "mc/network/ServerPlayerBlockUseHandler.h"
6+
#include "mc/server/ServerPlayer.h"
57
#include "mc/world/Container.h"
68
#include "mc/world/actor/player/Inventory.h"
79
#include "mc/world/actor/player/Player.h"
@@ -25,22 +27,27 @@ struct ToolInfo {
2527
int searchBestToolInInv(Container& inv, int currentSlot, const Block* block, const int minDamage, bool weapon) {
2628
if (!weapon && !block) return currentSlot;
2729
auto& currentItem = inv.getItem(currentSlot);
28-
ToolInfo curInfo{
29-
weapon ? currentItem.mItem.get()->getAttackDamage()
30-
: currentItem.mItem.get()->getDestroySpeed(currentItem, *block),
31-
currentSlot,
32-
currentItem.getMaxDamage() - currentItem.getDamageValue()
33-
};
30+
ToolInfo curInfo;
31+
if (currentItem == ItemStack::EMPTY_ITEM()) {
32+
curInfo = {0, currentSlot, 0};
33+
} else {
34+
curInfo = {
35+
weapon ? currentItem.mItem.get()->getAttackDamage()
36+
: currentItem.mItem.get()->getDestroySpeed(currentItem, *block),
37+
currentSlot,
38+
currentItem.getMaxDamage() - currentItem.getDamageValue()
39+
};
40+
}
3441
int size = inv.getContainerSize();
3542
for (int i = 0; i < size; ++i) {
3643
auto& item = inv.getItem(i);
37-
if (item.mCount != 0) {
38-
float value = weapon ? currentItem.mItem.get()->getAttackDamage()
39-
: currentItem.mItem.get()->getDestroySpeed(currentItem, *block);
44+
if (item != ItemStack::EMPTY_ITEM()) {
45+
float value =
46+
weapon ? item.mItem.get()->getAttackDamage() : item.mItem.get()->getDestroySpeed(currentItem, *block);
4047
short remainDamage = item.getMaxDamage() - item.getDamageValue();
4148
// skip low remainDamage tools
4249
if (remainDamage <= minDamage) continue;
43-
if (value >= curInfo.value) {
50+
if (value > curInfo.value) {
4451
curInfo = {value, i, remainDamage};
4552
}
4653
}
@@ -52,27 +59,24 @@ int searchBestToolInInv(Container& inv, int currentSlot, const Block* block, con
5259

5360
namespace coral_fans::functions {
5461

55-
LL_TYPE_INSTANCE_HOOK(
62+
LL_STATIC_HOOK(
5663
CoralFansTweakersAutoToolHook1,
5764
ll::memory::HookPriority::Normal,
58-
BlockEventCoordinator,
59-
&BlockEventCoordinator::sendBlockDestructionStarted,
65+
&ServerPlayerBlockUseHandler::onStartDestroyBlock,
6066
void,
61-
Player& player,
62-
BlockPos const& blockPos,
63-
Block const& block,
64-
uchar unk_char
67+
ServerPlayer& player,
68+
const BlockPos& pos,
69+
int face
6570
) {
66-
if (coral_fans::mod().getConfigDb()->get("functions.global.autotool") == "true"
67-
&& coral_fans::mod().getConfigDb()->get(
68-
std::format("functions.players.{}.autotool", player.getUuid().asString())
69-
) == "true") {
71+
if (coral_fans::mod().getConfigDb()->get(std::format("functions.players.{}.autotool", player.getUuid().asString()))
72+
== "true") {
7073
int currentSlot = player.getSelectedItemSlot();
7174
int minDamage =
7275
std::stoi(coral_fans::mod()
7376
.getConfigDb()
7477
->get(std::format("functions.players.{}.autotool.mindamage", player.getUuid().asString()))
7578
.value_or("1"));
79+
const Block& block = player.getDimensionBlockSourceConst().getBlock(pos);
7680
int bestSlot = ::searchBestToolInInv(*player.mInventory->mInventory, currentSlot, &block, minDamage, false);
7781
if (bestSlot <= 8) {
7882
player.setSelectedSlot(bestSlot);
@@ -81,7 +85,7 @@ LL_TYPE_INSTANCE_HOOK(
8185
player.refreshInventory();
8286
}
8387
}
84-
return origin(player, blockPos, block, unk_char);
88+
return origin(player, pos, face);
8589
}
8690

8791
LL_TYPE_INSTANCE_HOOK(
@@ -94,9 +98,8 @@ LL_TYPE_INSTANCE_HOOK(
9498
::SharedTypes::Legacy::ActorDamageCause const& cause,
9599
bool doPredictiveSound
96100
) {
97-
if (coral_fans::mod().getConfigDb()->get("functions.global.autotool") == "true"
98-
&& coral_fans::mod().getConfigDb()->get(std::format("functions.players.{}.autotool", this->getUuid().asString())
99-
) == "true") {
101+
if (coral_fans::mod().getConfigDb()->get(std::format("functions.players.{}.autotool", this->getUuid().asString()))
102+
== "true") {
100103
int currentSlot = this->getSelectedItemSlot();
101104
int minDamage =
102105
std::stoi(coral_fans::mod()

Diff for: src/coral_fans/functions/func/Droppernocost.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
#include "mc/world/level/block/actor/DispenserBlockActor.h"
77

88

9-
namespace coral_fans::functions::droppernocost {
10-
int _slot, _count;
11-
bool mutex = false, mutex2 = true;
9+
namespace coral_fans::functions {
1210

1311
// droppernocost
1412
LL_TYPE_INSTANCE_HOOK(
@@ -20,11 +18,11 @@ LL_TYPE_INSTANCE_HOOK(
2018
int slot,
2119
int count
2220
) {
23-
if (mutex) {
21+
if (FuncDropNoCostManager::getInstance().mutex) {
2422
origin(slot, count);
25-
mutex = false;
23+
FuncDropNoCostManager::getInstance().mutex = false;
2624
} else {
27-
_slot = slot, _count = count;
25+
FuncDropNoCostManager::getInstance()._slot = slot, FuncDropNoCostManager::getInstance()._count = count;
2826
}
2927
}
3028

@@ -36,8 +34,8 @@ LL_TYPE_INSTANCE_HOOK(
3634
bool,
3735
::ItemStack const& item
3836
) {
39-
mutex = true;
40-
this->removeItem(_slot, _count);
37+
FuncDropNoCostManager::getInstance().mutex = true;
38+
this->removeItem(FuncDropNoCostManager::getInstance()._slot, FuncDropNoCostManager::getInstance()._count);
4139
return origin(item);
4240
}
4341

@@ -53,7 +51,7 @@ LL_TYPE_INSTANCE_HOOK(
5351
::Vec3 const& pos,
5452
uchar face
5553
) {
56-
mutex2 = false;
54+
FuncDropNoCostManager::getInstance().mutex2 = false;
5755
return origin(region, container, slot, pos, face);
5856
}
5957

@@ -66,8 +64,8 @@ LL_TYPE_INSTANCE_HOOK(
6664
int slot,
6765
::ItemStack const& item
6866
) {
69-
if (mutex2) origin(slot, item);
70-
else mutex2 = true;
67+
if (FuncDropNoCostManager::getInstance().mutex2) origin(slot, item);
68+
else FuncDropNoCostManager::getInstance().mutex2 = true;
7169
}
7270

7371
void droppernocostHook(bool bl) {
@@ -83,4 +81,4 @@ void droppernocostHook(bool bl) {
8381
CoralFansTweakersDropperNoCostHook4::unhook();
8482
}
8583
}
86-
} // namespace coral_fans::functions::droppernocost
84+
} // namespace coral_fans::functions

Diff for: src/coral_fans/functions/func/Droppernocost.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
namespace coral_fans::functions::droppernocost {
1+
namespace coral_fans::functions {
2+
3+
class FuncDropNoCostManager {
4+
public:
5+
int _slot, _count;
6+
bool mutex = false, mutex2 = true;
7+
8+
static FuncDropNoCostManager& getInstance() {
9+
static FuncDropNoCostManager instance;
10+
return instance;
11+
}
12+
};
213
void droppernocostHook(bool);
3-
}
14+
} // namespace coral_fans::functions

0 commit comments

Comments
 (0)