Skip to content

Commit

Permalink
feat: add member fields for PistonActionEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jan 12, 2025
1 parent f63813e commit 3e7d5bd
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/bedrock/world/events/block_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "bedrock/world/actor/actor_definition_identifier.h"
#include "bedrock/world/events/event_variant.h"
#include "bedrock/world/item/item_stack.h"
#include "bedrock/world/level/block/actor/piston_block_actor.h"
#include "bedrock/world/level/block_pos.h"
#include "bedrock/world/level/dimension/dimension.h"

Expand All @@ -46,7 +47,12 @@ struct CraftUISetResultNameEvent {
const BlockType type;
const std::string name;
};
struct PistonActionEvent {};
struct PistonActionEvent {
std::shared_ptr<BlockSourceHandle> block_source_handle;
const BlockPos piston_block_pos;
PistonState action_type;
bool should_check_attached_blocks;
};
struct LeverActionEvent {};
struct ButtonPushEvent {};
struct PressurePlatePushEvent {};
Expand Down
22 changes: 22 additions & 0 deletions src/bedrock/world/level/block/actor/piston_block_actor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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

enum class PistonState : char {
Retracted = 0,
Expanding = 1,
Expanded = 2,
Retracting = 3,
};
11 changes: 10 additions & 1 deletion src/endstone/core/event/handlers/block_gameplay_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "endstone/core/event/handlers/block_gameplay_handler.h"

#include <magic_enum/magic_enum.hpp>

#include "bedrock/world/actor/actor.h"
#include "endstone/block/block_face.h"
#include "endstone/core/block/block_face.h"
Expand All @@ -40,7 +42,8 @@ GameplayHandlerResult<CoordinatorResult> EndstoneBlockGameplayHandler::handleEve
{
auto visitor = [&](auto &&arg) -> GameplayHandlerResult<CoordinatorResult> {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, Details::ValueOrRef<const BlockTryPlaceByPlayerEvent>>) {
if constexpr (std::is_same_v<T, Details::ValueOrRef<const BlockTryPlaceByPlayerEvent>> ||
std::is_same_v<T, Details::ValueOrRef<const PistonActionEvent>>) {
if (!handleEvent(arg.value())) {
return {HandlerResult::BypassListeners, CoordinatorResult::Cancel};
}
Expand Down Expand Up @@ -72,6 +75,12 @@ GameplayHandlerResult<CoordinatorResult> EndstoneBlockGameplayHandler::handleEve
return std::visit(visitor, event.variant);
}

bool EndstoneBlockGameplayHandler::handleEvent(const PistonActionEvent &event)
{
// TODO(event): piston events
return true;
}

bool EndstoneBlockGameplayHandler::handleEvent(const BlockTryPlaceByPlayerEvent &event)
{
const StackResultStorageEntity stack_result(event.player);
Expand Down
1 change: 1 addition & 0 deletions src/endstone/core/event/handlers/block_gameplay_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class EndstoneBlockGameplayHandler final : public BlockGameplayHandler {
GameplayHandlerResult<CoordinatorResult> handleEvent(MutableBlockGameplayEvent<CoordinatorResult> &event) override;

private:
bool handleEvent(const PistonActionEvent &event);
bool handleEvent(const BlockTryPlaceByPlayerEvent &event);
bool handleEvent(ExplosionStartedEvent &event);
bool handleEvent(BlockTryDestroyByPlayerEvent &event);
Expand Down

0 comments on commit 3e7d5bd

Please sign in to comment.