1
+ #include " CustomStructure.h"
2
+
3
+ #include " ll/api/memory/Hook.h"
4
+
5
+ #include " mc/deps/core/threading/WorkerPool.h"
6
+ #include " mc/resources/BaseGameVersion.h"
7
+ #include " mc/world/level/block/VanillaBlockTypeIds.h"
8
+ #include " mc/world/level/block/registry/BlockTypeRegistry.h"
9
+ #include " mc/world/level/levelgen/feature/registry/FeatureRegistry.h"
10
+ #include " mc/world/level/levelgen/structure/Projection.h"
11
+ #include " mc/world/level/levelgen/structure/StructureManager.h"
12
+ #include " mc/world/level/levelgen/structure/registry/JigsawStructureBlockRulesRegistry.h"
13
+ #include " mc/world/level/levelgen/structure/registry/JigsawStructureElementRegistry.h"
14
+ #include " mc/world/level/levelgen/structure/registry/JigsawStructureRegistry.h"
15
+ #include " mc/world/level/levelgen/structure/registry/StructurePools.h"
16
+ #include " mc/world/level/levelgen/structure/structurepools/StructurePoolActorRule.h"
17
+ #include " mc/world/level/levelgen/structure/structurepools/StructurePoolBlockPredicateAlwaysTrue.h"
18
+ #include " mc/world/level/levelgen/structure/structurepools/StructurePoolBlockPredicateBlockMatchRandom.h"
19
+ #include " mc/world/level/levelgen/structure/structurepools/StructurePoolBlockRule.h"
20
+ #include " mc/world/level/levelgen/structure/structurepools/StructurePoolBlockTagRule.h"
21
+ #include " mc/world/level/levelgen/structure/structurepools/StructurePoolElement.h"
22
+ #include " mc/world/level/levelgen/structure/structurepools/StructureTemplatePool.h"
23
+ #include " mc/world/level/storage/Experiments.h"
24
+
25
+ #include < memory>
26
+
27
+ namespace custom_structure {
28
+
29
+ void CustomJigsawStructureBlockRules::initialize (JigsawStructureRegistry& registry) {
30
+ auto & jigsawBlockRulesRegistry = registry.getJigsawStructureBlockRulesRegistry ();
31
+ // auto& DefaultBlockState =
32
+ // BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::PolishedBlackstoneBricks(), 1);
33
+ auto & resultBlock = BlockTypeRegistry::getDefaultBlockState (VanillaBlockTypeIds::RedstoneBlock (), 1 );
34
+ auto & block = BlockTypeRegistry::getDefaultBlockState (VanillaBlockTypeIds::Blackstone (), 1 );
35
+
36
+ std::unique_ptr<IStructurePoolBlockPredicate> sourceBlock =
37
+ std::make_unique<StructurePoolBlockPredicateBlockMatchRandom>(block, 0.3 );
38
+ std::unique_ptr<IStructurePoolBlockPredicate> targetBlock =
39
+ std::make_unique<StructurePoolBlockPredicateAlwaysTrue>();
40
+
41
+ auto blockRule =
42
+ std::make_unique<StructurePoolBlockRule>(std::move (sourceBlock), std::move (targetBlock), &resultBlock);
43
+
44
+ auto ruleList = std::make_unique<std::vector<std::unique_ptr<StructurePoolBlockRule>>>();
45
+
46
+ ruleList->push_back (std::move (blockRule));
47
+
48
+ jigsawBlockRulesRegistry.registerBlockRules (" custom:custom_structure_block_rule" , std::move (ruleList));
49
+ }
50
+
51
+ void CustomJigsawStructureElements::initialize (
52
+ gsl::not_null<Bedrock::NonOwnerPointer<StructureManager>> manager,
53
+ FeatureRegistry& featureRegistry,
54
+ JigsawStructureRegistry& jigsawRegistry
55
+ ) {
56
+ auto & jigsawBlockRulesRegistry = jigsawRegistry.getJigsawStructureBlockRulesRegistry ();
57
+ auto & jigsawStructureElementRegistry = jigsawRegistry.getJigsawStructureElementRegistry ();
58
+ auto ruleList = jigsawBlockRulesRegistry.lookupByName (" custom:custom_structure_block_rule" );
59
+ std::vector<std::unique_ptr<StructurePoolBlockTagRule>> blockTag{};
60
+ std::vector<std::unique_ptr<StructurePoolActorRule>> actorRule{};
61
+ // blockTag.push_back(nullptr);
62
+ // actorRule.push_back(nullptr);
63
+
64
+ // 每一个结构nbt文件都得这样注册进来,多个nbt结构文件的可以使用同一个Block Rule
65
+ jigsawStructureElementRegistry.registerStructureElement (
66
+ " mike:21room" ,
67
+ std::make_unique<StructurePoolElement>(
68
+ manager,
69
+ " custom/21room" ,
70
+ ruleList,
71
+ nullptr ,
72
+ nullptr ,
73
+ Projection::Rigid,
74
+ PostProcessSettings::None
75
+ )
76
+ );
77
+
78
+ jigsawStructureElementRegistry.registerStructureElement (
79
+ " mike:ew7x4" ,
80
+ std::make_unique<StructurePoolElement>(
81
+ manager,
82
+ " custom/ewhall" ,
83
+ ruleList,
84
+ nullptr ,
85
+ nullptr ,
86
+ Projection::Rigid,
87
+ PostProcessSettings::None
88
+ )
89
+ );
90
+
91
+ jigsawStructureElementRegistry.registerStructureElement (
92
+ " mike:ns7x4" ,
93
+ std::make_unique<StructurePoolElement>(
94
+ manager,
95
+ " custom/nshall" ,
96
+ ruleList,
97
+ nullptr ,
98
+ nullptr ,
99
+ Projection::Rigid,
100
+ PostProcessSettings::None
101
+ )
102
+ );
103
+ }
104
+
105
+ void CustomJigsawStructure::initialize (
106
+ Bedrock::NotNullNonOwnerPtr<::StructureManager> manager,
107
+ FeatureRegistry& featureRegistry,
108
+ JigsawStructureRegistry& registry
109
+ ) {
110
+ CustomJigsawStructureBlockRules::initialize (registry);
111
+ CustomJigsawStructureElements::initialize (manager, featureRegistry, registry);
112
+ auto & jigsawStructureElementRegistry = registry.getJigsawStructureElementRegistry ();
113
+
114
+ std::vector<std::pair<StructurePoolElement const *, int >> templates_room{
115
+ {jigsawStructureElementRegistry.lookupByName (" mike:21room" ), 1 }
116
+ };
117
+ std::vector<std::pair<StructurePoolElement const *, int >> templates_ew{
118
+ {jigsawStructureElementRegistry.lookupByName (" mike:ew7x4" ), 1 }
119
+ };
120
+ std::vector<std::pair<StructurePoolElement const *, int >> templates_ns{
121
+ {jigsawStructureElementRegistry.lookupByName (" mike:ns7x4" ), 1 }
122
+ };
123
+
124
+ registry.registerPool (std::make_unique<StructureTemplatePool>(" mike:21room" , " empty" , templates_room));
125
+ registry.registerPool (std::make_unique<StructureTemplatePool>(" mike:ew7x4" , " empty" , templates_ew));
126
+ registry.registerPool (std::make_unique<StructureTemplatePool>(" mike:ns7x4" , " empty" , templates_ns));
127
+ }
128
+
129
+ } // namespace custom_structure
130
+
131
+ LL_AUTO_TYPE_STATIC_HOOK (
132
+ InitStructure,
133
+ HookPriority::Normal,
134
+ br::worldgen::StructurePools,
135
+ br::worldgen::StructurePools::bootstrap,
136
+ void ,
137
+ Bedrock::NotNullNonOwnerPtr<StructureManager> structureManager,
138
+ FeatureRegistry& featureRegistry,
139
+ JigsawStructureRegistry& jigsawStructureRegistry,
140
+ BaseGameVersion const & baseGameVersion,
141
+ Experiments const & experiments
142
+ ) {
143
+ origin (structureManager, featureRegistry, jigsawStructureRegistry, baseGameVersion, experiments);
144
+ custom_structure::CustomJigsawStructure::initialize (structureManager, featureRegistry, jigsawStructureRegistry);
145
+ return ;
146
+ };
0 commit comments