Skip to content

Commit

Permalink
feat: add CreativeGroupInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Feb 18, 2025
1 parent e6d4d09 commit a584e7f
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 7 deletions.
1 change: 0 additions & 1 deletion src/bedrock/forward.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ enum class BurnOdds;
enum class ChunkCachedDataState : std::int8_t;
enum class ChunkDebugDisplaySavedState : std::int8_t;
enum class ChunkTerrainDataState : std::int8_t;
enum class CreativeItemCategory;
enum class FertilizerType;
enum class FlameOdds;
enum class InHandUpdateType : std::int8_t;
Expand Down
2 changes: 1 addition & 1 deletion src/bedrock/world/game_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

Bedrock::NonOwnerPointer<ServerNetworkHandler> GameSession::getServerNetworkHandler() const
{
return Bedrock::NonOwnerPointer<ServerNetworkHandler>(*server_network_handler_);
return *server_network_handler_;
}

Level *GameSession::getLevel() const
Expand Down
26 changes: 26 additions & 0 deletions src/bedrock/world/item/item_category.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

enum class CreativeItemCategory : int {
All = 0,
Construction = 1,
Nature = 2,
Equipment = 3,
Items = 4,
ItemCommandOnly = 5,
Undefined = 6,
NUM_CATEGORIES = 7,
};
35 changes: 35 additions & 0 deletions src/bedrock/world/item/registry/creative_group_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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/core/string/string_hash.h"
#include "bedrock/world/item/item_category.h"
#include "bedrock/world/item/item_instance.h"
#include "bedrock/world/item/registry/creative_item_entry_fwd.h"

class CreativeGroupInfo : public Bedrock::EnableNonOwnerReferences {
public:
CreativeGroupInfo(CreativeItemRegistryPtr, CreativeItemCategory, const HashedString &, uint32_t,
const ItemInstance &);
CreativeGroupInfo(CreativeItemRegistryPtr, CreativeItemCategory, HashedString &&, uint32_t, ItemInstance &&);
CreativeGroupInfo(CreativeItemRegistryPtr, CreativeItemCategory, uint32_t);

private:
CreativeItemCategory category_; // +24
CreativeItemRegistryPtr registry_; // +32
HashedString name_; // +40
ItemInstance icon_; // +80
uint32_t index_; // +208
std::vector<unsigned int> item_indexes_; // +216
};
20 changes: 20 additions & 0 deletions src/bedrock/world/item/registry/creative_item_entry_fwd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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

using CreativeItemEntryPtr = class CreativeItemEntry *;
using CreativeGroupInfoPtr = class CreativeGroupInfo *;
using CreativeItemRegistryPtr = class CreativeItemRegistry *;
using CreativeItemGroupCategoryPtr = class CreativeItemGroupCategory *;
4 changes: 3 additions & 1 deletion src/bedrock/world/item/registry/creative_item_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
#include <functional>

#include "bedrock/core/utility/enable_non_owner_references.h"
#include "bedrock/world/item/registry/creative_group_info.h"
#include "bedrock/world/item/registry/creative_item_entry.h"

class CreativeItemRegistry : public Bedrock::EnableNonOwnerReferences {
public:
void forEachCreativeItemInstance(std::function<bool(const ItemInstance &)>) const;

private:
std::vector<CreativeItemEntry> creative_items_; // +24
std::vector<CreativeItemEntry> creative_items_; // +24
std::vector<CreativeGroupInfo> creative_groups_; // +48
};
2 changes: 1 addition & 1 deletion src/bedrock/world/item/registry/item_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ WeakPtr<Item> ItemRegistry::getItem(const HashedString &id) const

Bedrock::NonOwnerPointer<CreativeItemRegistry> ItemRegistry::getCreativeItemRegistry() const
{
return Bedrock::NonOwnerPointer<CreativeItemRegistry>(*creative_item_registry_);
return *creative_item_registry_;
}
2 changes: 1 addition & 1 deletion src/bedrock/world/item/registry/item_registry.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ class ItemRegistry : public std::enable_shared_from_this<ItemRegistry> {
BaseGameVersion world_base_game_version_; //
bool check_for_item_world_compatibility_; //
std::shared_ptr<std::mutex> compatibility_check_mutex_; //
std::unique_ptr<CreativeItemRegistry> creative_item_registry_; //
std::unique_ptr<CreativeItemRegistry> creative_item_registry_; // +960
};
3 changes: 1 addition & 2 deletions src/bedrock/world/level/block/block_legacy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
#include "bedrock/core/math/color.h"
#include "bedrock/core/string/string_hash.h"
#include "bedrock/core/utility/optional_ref.h"
#include "bedrock/entity/gamerefs_entity/entity_context.h"
#include "bedrock/forward.h"
#include "bedrock/resources/base_game_version.h"
#include "bedrock/util/int_range.h"
#include "bedrock/world/direction.h"
#include "bedrock/world/flip.h"
#include "bedrock/world/item/item_category.h"
#include "bedrock/world/level/block/actor/block_actor.h"
#include "bedrock/world/level/block/block_color_logic.h"
#include "bedrock/world/level/block/block_state_instance.h"
#include "bedrock/world/level/block/components/block_component_storage.h"
#include "bedrock/world/level/block_pos.h"
Expand Down

0 comments on commit a584e7f

Please sign in to comment.