Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Mar 30, 2024
1 parent a522789 commit 26cca13
Show file tree
Hide file tree
Showing 16 changed files with 468 additions and 109 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Custom
BreakBeforeBinaryOperators: NonAssignment
ColumnLimit: 120
ColumnLimit: 90
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerIndentWidth: 0
IndentWidth: 4
Expand Down
13 changes: 0 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,3 @@ jobs:
name: ${{ github.event.repository.name }}-windows-x64-${{ github.sha }}
path: |
bin/
clang-format:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- run: |
choco install llvm -y --version=17.0.6
- name: clang-format
run: |
Get-ChildItem src/ -Filter *.cpp -Recurse | ForEach-Object { clang-format --dry-run -Werror $_.FullName; if ($LASTEXITCODE -ne 0) { exit 1; } }
Get-ChildItem src/ -Filter *.h -Recurse | ForEach-Object { clang-format --dry-run -Werror $_.FullName; if ($LASTEXITCODE -ne 0) { exit 1; } }
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
# LeviLamina Plugin Template
# BedrockBugFixes

A LeviLamina plugin template
## BugFixes

This plugin is a template for developing LeviLamina plugins.
All bugfixes will not affect the vanilla features.
所有bugfix均不会影响原版特性。

## Install
### HopperBugsFix

Generate a new repository from this template.
fix MCPE-99462 Hoppers don't pickup items parallel to chunk border

## Usage
修复漏斗区块边界问题。

Before using this plugin template, make sure that you have installed XMake and a Minecraft Bedrock Server with LeviLamina.
### BeeBugsFix

1. Clone the new repository into a local folder.
fix a bug where bees could not collect nectar normally when there were more than 1 flower around.
修复蜜蜂在周围有超过1个花时无法正常采蜜的bug。

1. Change the plugin name and the expected LeviLamina version in `xmake.lua`.
### AllayTeleportBugFix

1. Add your code.

1. Run `xmake repo -u` in the root of the repository.

1. Run `xmake` to build the plugin.

Now the build is complete at `bin/`.
fix allay was incorrectly teleported across dimensions without passing through the portal.
修复了小安粒在未经过传送门时被错误的跨维度传送的bug。

## Contributing

Expand All @@ -32,4 +29,4 @@ PRs accepted.

## License

CC0-1.0 © LiteLDev
AGPL v3.0
45 changes: 45 additions & 0 deletions src/bugfix/AllayTeleportBugFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "Summary.h"

#include <ll/api/memory/Hook.h>

#include <mc/world/AutomaticID.h>
#include <mc/world/actor/ai/goal/FollowOwnerGoal.h>
#include <mc/world/actor/player/Player.h>

namespace bbf {

LL_TYPE_INSTANCE_HOOK(
FollowOwnerGoalHook,
ll::memory::HookPriority::Normal,
FollowOwnerGoal,
//&FollowOwnerGoal::onPlayerDimensionChanged,
"?onPlayerDimensionChanged@FollowOwnerGoal@@UEAAXPEAVPlayer@@V?$AutomaticID@"
"VDimension@@H@@1@Z",
void,
Player* player,
DimensionType fromDimension,
DimensionType toDimension
) {
auto& mob = ll::memory::dAccess<Mob>(this, 7 * 8);
if (mob.isType(ActorType::Allay)) {
return;
}
origin(player, fromDimension, toDimension);
}

struct AllayTeleportBugFix::Impl {
ll::memory::HookRegistrar<FollowOwnerGoalHook> r;
};

void AllayTeleportBugFix::call(bool enable) {
if (enable) {
if (!impl) impl = std::make_unique<Impl>();
} else {
impl.reset();
}
}

AllayTeleportBugFix::AllayTeleportBugFix() = default;
AllayTeleportBugFix::~AllayTeleportBugFix() = default;

} // namespace bbf
76 changes: 76 additions & 0 deletions src/bugfix/BeeBugsFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "Summary.h"

#include <ll/api/memory/Hook.h>

#include <mc/math/Vec3.h>
#include <mc/world/AutomaticID.h>
#include <mc/world/actor/ActorDefinitionTrigger.h>
#include <mc/world/actor/ActorFilterGroup.h>
#include <mc/world/actor/ai/goal/MoveToBlockGoal.h>
#include <mc/world/actor/player/Player.h>
#include <mc/world/item/ItemDescriptor.h>

namespace bbf {

LL_TYPE_INSTANCE_HOOK(
MoveToBlockGoalHook,
ll::memory::HookPriority::Normal,
MoveToBlockGoal,
//&MoveToBlockGoal::onPlayerDimensionChanged,
"??0MoveToBlockGoal@@QEAA@AEAVMob@@MHHHHMVVec3@@MW4TargetSelectionMethod@@V?$vector@"
"VActorDefinitionTrigger@@V?$allocator@VActorDefinitionTrigger@@@std@@@std@@3V?$"
"vector@VItemDescriptor@@V?$allocator@VItemDescriptor@@@std@@@5@AEBVActorFilterGroup@"
"@@Z",
MoveToBlockGoal*,
Mob& mob,
float speedModifier,
int searchRange,
int searchHeight,
int tickInterval,
int stayDurationTicks,
float goalRadius,
Vec3 targetPositionOffset,
float chanceToStart,
::TargetSelectionMethod targetSelectionMethod,
std::vector<ActorDefinitionTrigger> onReachTriggers,
std::vector<ActorDefinitionTrigger> onStayCompletedTriggers,
std::vector<ItemDescriptor> targetBlocks,
ActorFilterGroup const& filterGroup
) {
if (mob.isType(ActorType::Bee)) {
targetSelectionMethod = TargetSelectionMethod::Nearest;
}
return origin(
mob,
speedModifier,
searchRange,
searchHeight,
tickInterval,
stayDurationTicks,
goalRadius,
targetPositionOffset,
chanceToStart,
targetSelectionMethod,
std::move(onReachTriggers),
std::move(onStayCompletedTriggers),
std::move(targetBlocks),
filterGroup
);
}

struct BeeBugsFix::Impl {
ll::memory::HookRegistrar<MoveToBlockGoalHook> r;
};

void BeeBugsFix::call(bool enable) {
if (enable) {
if (!impl) impl = std::make_unique<Impl>();
} else {
impl.reset();
}
}

BeeBugsFix::BeeBugsFix() = default;
BeeBugsFix::~BeeBugsFix() = default;

} // namespace bbf
111 changes: 111 additions & 0 deletions src/bugfix/HopperBugsFix.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "Summary.h"

#include <ll/api/memory/Hook.h>

#include <mc/entity/WeakEntityRef.h>
#include <mc/math/Vec3.h>
#include <mc/world/Container.h>
#include <mc/world/actor/Actor.h>
#include <mc/world/actor/Hopper.h>
#include <mc/world/actor/item/ItemActor.h>
#include <mc/world/level/BlockSource.h>
#include <mc/world/level/ChunkPos.h>
#include <mc/world/level/block/Block.h>
#include <mc/world/level/block/utils/VanillaBlockTypeIds.h>
#include <mc/world/level/chunk/LevelChunk.h>
#include <mc/world/phys/AABB.h>

namespace bbf {

LL_TYPE_INSTANCE_HOOK(
HopperTryAddItemHook,
ll::memory::HookPriority::Normal,
Hopper,
&Hopper::_tryAddItemsFromPos,
bool,
BlockSource& blockSource,
Container& container,
Vec3 const& pos
) {
AABB aabb;

if (mIsEntity) {
aabb.min = pos - Vec3{0.5f, 0.0f, 0.5f};
aabb.max = pos + Vec3{0.5f, 1.0f, 0.5f};
} else {
aabb.min = pos;
aabb.min.y -= 0.375f;
aabb.max = pos + 1;
}

ChunkPos minChunk(
((int)std::floor(aabb.min.x - 0.125f)) >> 4,
((int)std::floor(aabb.min.z - 0.125f)) >> 4
);
ChunkPos maxChunk(
((int)std::floor(aabb.max.x + 0.125f)) >> 4,
((int)std::floor(aabb.max.z + 0.125f)) >> 4
);

for (int x = minChunk.x; x <= maxChunk.x; x++)
for (int z = minChunk.z; z <= maxChunk.z; z++) {
auto* chunk = blockSource.getChunk({x, z});
if (!chunk) {
continue;
}
for (auto& weakEntityRef : chunk->getChunkEntities()) {
auto* actor = weakEntityRef.tryUnwrap<Actor>().as_ptr();
if (!actor || !actor->isType(ActorType::ItemEntity)
|| !aabb.intersects(actor->getAABB()) || actor->isRemoved()) {
continue;
}
auto& item = static_cast<ItemActor*>(actor)->item();
if (item.isNull()) {
continue;
}
if (_addItem(blockSource, container, item, -1, item.mCount)) {
if (item.mCount != 0) {
_addItem(
blockSource,
container,
item,
-1,
item.mCount
); // need to add twice
}
if (item.mCount == 0) {
actor->remove();
}
return true;
}
}
}
return false;
}

LL_TYPE_INSTANCE_HOOK(
IsContainerBlockHook,
ll::memory::HookPriority::Normal,
Block,
&Block::isContainerBlock,
bool
) {
return getName() == VanillaBlockTypeIds::Composter || origin();
}

struct HopperBugsFix::Impl {
ll::memory::HookRegistrar<HopperTryAddItemHook, IsContainerBlockHook> r;
};

void HopperBugsFix::call(bool enable) {
if (enable) {
if (!impl) impl = std::make_unique<Impl>();
} else {
impl.reset();
}
}

HopperBugsFix::HopperBugsFix() = default;
HopperBugsFix::~HopperBugsFix() = default;

} // namespace bbf
30 changes: 30 additions & 0 deletions src/bugfix/Summary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include <memory>

namespace bbf {
struct HopperBugsFix {
struct Impl;
std::unique_ptr<Impl> impl;

void call(bool);
HopperBugsFix();
~HopperBugsFix();
};
struct BeeBugsFix {
struct Impl;
std::unique_ptr<Impl> impl;

void call(bool);
BeeBugsFix();
~BeeBugsFix();
};
struct AllayTeleportBugFix {
struct Impl;
std::unique_ptr<Impl> impl;

void call(bool);
AllayTeleportBugFix();
~AllayTeleportBugFix();
};
} // namespace bbf
Loading

0 comments on commit 26cca13

Please sign in to comment.