Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions include/endstone/event/block/block_from_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "endstone/event/block/block_grow_event.h"

namespace endstone {

class BlockFromEvent final : public BlockGrowEvent {
public:
ENDSTONE_EVENT(BlockFormEvent)
using BlockGrowEvent::BlockGrowEvent;
};

} // namespace endstone
45 changes: 45 additions & 0 deletions include/endstone/event/block/block_from_to_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "endstone/event/block/block_event.h"
#include "endstone/event/cancellable.h"

namespace endstone {

class BlockFromToEvent : public Cancellable<BlockEvent> {
public:
explicit BlockFromToEvent(std::unique_ptr<Block> block, std::unique_ptr<Block> to_block)
: Cancellable(std::move(block)), to_block_(std::move(to_block))
{
}
~BlockFromToEvent() override = default;

inline static const std::string NAME = "BlockFromToEvent";
[[nodiscard]] std::string getEventName() const override
{
return NAME;
}

[[nodiscard]] Block &getToBlock() const
{
return *to_block_;
}

private:
std::unique_ptr<Block> to_block_;
};

} // namespace endstone
45 changes: 45 additions & 0 deletions include/endstone/event/block/block_grow_event.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "endstone/event/block/block_event.h"
#include "endstone/event/cancellable.h"

namespace endstone {

class BlockGrowEvent : public Cancellable<BlockEvent> {
public:
explicit BlockGrowEvent(std::unique_ptr<Block> block, std::unique_ptr<BlockState> new_state)
: Cancellable(std::move(block)), new_state_(std::move(new_state))
{
}
~BlockGrowEvent() override = default;

inline static const std::string NAME = "BlockGrowEvent";
[[nodiscard]] std::string getEventName() const override
{
return NAME;
}

[[nodiscard]] BlockState &getToBlock() const
{
return *new_state_;
}

private:
std::unique_ptr<BlockState> new_state_;
};

} // namespace endstone
1 change: 1 addition & 0 deletions src/bedrock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ add_library(bedrock STATIC
world/level/block/block_type.cpp
world/level/block/campfire_block.cpp
world/level/block/fire_block.cpp
world/level/block/liquid_block.cpp
world/level/block/vanilla_block_type_ids.cpp
world/level/block/actor/beehive_block_actor.cpp
world/level/block/actor/furnace_block_actor.cpp
Expand Down
3 changes: 3 additions & 0 deletions src/bedrock/symbol_generator/symbols.toml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ version = "1.21.124"
"?_runPlugins@ServerScriptManager@@AEAAXW4PluginExecutionGroup@@AEAVServerInstance@@@Z" = 34021952
# UnverifiedCertificate
"?fromString@UnverifiedCertificate@@SA?AV1@AEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z" = 9484752
# LiquidBlock
"?_trySpreadTo@LiquidBlock@@AEBAXAEAVBlockSource@@AEBVBlockPos@@H1E@Z" = 68306928
"?_isLiquidBlocking@LiquidBlock@@AEBA_NAEAVBlockSource@@AEBVBlockPos@@1E@Z" = 68311184

[linux]
"BlockState::StateListNode::mHead" = 221392056
Expand Down
17 changes: 17 additions & 0 deletions src/bedrock/world/level/block/liquid_block.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "bedrock/world/level/block/liquid_block.h"

#include "bedrock/world/level/block_source.h"

bool LiquidBlock::_canSpreadTo(BlockSource &region, BlockPos const &pos, BlockPos const &flow_from_pos,
unsigned char flow_from_direction) const
{
if (pos.y < region.getMinHeight()) {
return false;
}
if (const auto &block = region.getLiquidBlock(pos);
block.getMaterial() == getMaterial() || block.getMaterial().isType(MaterialType::Lava) ||
_isLiquidBlocking(region, pos, flow_from_pos, flow_from_direction)) {
return false;
}
return true;
}
26 changes: 26 additions & 0 deletions src/bedrock/world/level/block/liquid_block.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once
#include "bedrock/world/level/block/block_type.h"
class LiquidBlockBase : public ::BlockType {};
class LiquidBlock : public LiquidBlockBase {
private:
ENDSTONE_HOOK void _trySpreadTo(BlockSource &region, BlockPos const &pos, int neighbor,
BlockPos const &flow_from_pos, unsigned char flow_from_direction) const;
bool _canSpreadTo(BlockSource &region, BlockPos const &pos, BlockPos const &flow_from_pos,
unsigned char flow_from_direction) const;
ENDSTONE_HOOK bool _isLiquidBlocking(BlockSource &region, BlockPos const &pos, BlockPos const &flow_from_pos,
unsigned char flow_from_direction) const;
};
1 change: 1 addition & 0 deletions src/bedrock/world/level/material/material.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Material {
{
return type_;
}
bool operator==(const Material &) const = default;

private:
MaterialType type_;
Expand Down
1 change: 1 addition & 0 deletions src/endstone/runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ add_library(endstone_runtime SHARED
bedrock_hooks/server_player_movement_correction_system.cpp
bedrock_hooks/server_script_manager.cpp
bedrock_hooks/leaves_block.cpp
bedrock_hooks/liquid_block.cpp
main.cpp
hook.cpp
vtable_hook.cpp
Expand Down
30 changes: 30 additions & 0 deletions src/endstone/runtime/bedrock_hooks/liquid_block.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "bedrock/world/level/block/liquid_block.h"

#include "bedrock/world/level/block_source.h"
#include "endstone/core/block/block.h"
#include "endstone/core/server.h"
#include "endstone/event/block/block_from_to_event.h"
#include "endstone/runtime/hook.h"

void LiquidBlock::_trySpreadTo(BlockSource &region, BlockPos const &pos, int neighbor, BlockPos const &flow_from_pos,
unsigned char flow_from_direction) const
{
const auto &server = endstone::core::EndstoneServer::getInstance();
if (server.isPrimaryThread() && _canSpreadTo(region, pos, flow_from_pos, flow_from_direction)) {
endstone::BlockFromToEvent event(endstone::core::EndstoneBlock::at(region, flow_from_pos),
endstone::core::EndstoneBlock::at(region, pos));
server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
}
ENDSTONE_HOOK_CALL_ORIGINAL(&LiquidBlock::_trySpreadTo, this, region, pos, neighbor, flow_from_pos,
flow_from_direction);
}

bool LiquidBlock::_isLiquidBlocking(BlockSource &region, BlockPos const &pos, BlockPos const &flow_from_pos,
unsigned char flow_from_direction) const
{
return ENDSTONE_HOOK_CALL_ORIGINAL(&LiquidBlock::_isLiquidBlocking, this, region, pos, flow_from_pos,
flow_from_direction);
}
Loading