Skip to content

Commit 88926bb

Browse files
committed
test: update custom structure generator
1 parent d0cbe6d commit 88926bb

File tree

9 files changed

+192
-46
lines changed

9 files changed

+192
-46
lines changed

src/more_dimensions/MoreDimenison.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include "ll/api/Versions.h"
44
#include "ll/api/mod/RegisterHelper.h"
5-
#include "more_dimensions/core/dimension/VanillaDimensionId2Patch.h"
5+
#include "more_dimensions/core/dimension/MoreDimensionsPatch.h"
66

77
namespace more_dimensions {
88

src/more_dimensions/core/dimension/FakeDimensionId.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,12 @@ static void fakeChangeDimension(
116116
changeDimensionPacket.mPos = pos;
117117
changeDimensionPacket.mRespawn = true;
118118
changeDimensionPacket.mLoadingScreenId = {screedId};
119-
std::cout<<"test id:"<< changeDimensionPacket.mDimensionId->id <<std::endl;
120119
ll::service::getLevel()->getPacketSender()->sendToClient(netId, changeDimensionPacket, SubClientId::PrimaryClient);
121120
PlayerActionPacket playerActionPacket;
122121
playerActionPacket.mAction = PlayerActionType::ChangeDimensionAck;
123122
playerActionPacket.mRuntimeId = runtimeId;
124-
std::cout<<"test1"<<std::endl;
125123
ll::service::getLevel()->getPacketSender()->sendToClient(netId, playerActionPacket, SubClientId::PrimaryClient);
126124
sendEmptyChunks(netId, pos, 3, true);
127-
std::cout<<"test2"<<std::endl;
128125
}
129126

130127
namespace CustomDimensionHookList {

src/more_dimensions/core/dimension/VanillaDimensionId2Patch.h renamed to src/more_dimensions/core/dimension/MoreDimensionsPatch.h

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
#include <iostream>
44
#include <vector>
55

6-
6+
extern "C" {
7+
__declspec(dllimport) bool pl_notice(void* target);
8+
}
79
namespace {
810
struct AddressAndReg {
911
DWORD func_rva_start;
@@ -126,5 +128,27 @@ void injectNaticeCode() {
126128
}
127129
for (auto& item : data) {
128130
PatchFunction(hModule, item.func_rva_start, item.func_rva_end, item.native_code);
131+
if(item.func_rva_start == 0x12A9A9F){
132+
void* funcp = (void*)((BYTE*)hModule + 0x12A9A80);
133+
pl_notice(funcp);
134+
}
129135
};
130-
};
136+
};
137+
138+
// BOOL APIENTRY DllMain(HMODULE hModule,
139+
// DWORD ul_reason_for_call,
140+
// LPVOID lpReserved
141+
// )
142+
// {
143+
// switch (ul_reason_for_call)
144+
// {
145+
// case DLL_PROCESS_ATTACH:
146+
// injectNaticeCode();
147+
// break;
148+
// case DLL_THREAD_ATTACH:
149+
// case DLL_THREAD_DETACH:
150+
// case DLL_PROCESS_DETACH:
151+
// break;
152+
// }
153+
// return TRUE;
154+
// }

src/test/generator/generator-custom-structure/CustomStructure.cpp

Lines changed: 147 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,51 @@ namespace custom_structure {
2626

2727
void CustomJigsawStructureBlockRules::initialize(JigsawStructureRegistry& registry) {
2828
auto& jigsawBlockRulesRegistry = registry.mJigsawBlockRulesRegistry;
29-
// auto& DefaultBlockState =
30-
// BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::PolishedBlackstoneBricks(), 1);
31-
auto& resultBlock = BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::RedstoneBlock(), 1);
32-
auto& block = BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::Blackstone(), 1);
3329

34-
std::unique_ptr<IStructurePoolBlockPredicate> sourceBlock =
35-
std::make_unique<StructurePoolBlockPredicateBlockMatchRandom>(block, 0.3);
30+
// input_predicate block
31+
auto& stoneBricks = BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::StoneBricks());
32+
33+
// output_state blocks
34+
auto& mossyStoneBricks = BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::MossyStoneBricks());
35+
auto& crackedStoneBricks = BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::CrackedStoneBricks());
36+
auto& cobblestone = BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::Cobblestone());
37+
38+
// input_predicate
39+
std::unique_ptr<IStructurePoolBlockPredicate> sourceBlock_pro1 =
40+
std::make_unique<StructurePoolBlockPredicateBlockMatchRandom>(stoneBricks, 0.2);
41+
std::unique_ptr<IStructurePoolBlockPredicate> sourceBlock_pro2 =
42+
std::make_unique<StructurePoolBlockPredicateBlockMatchRandom>(stoneBricks, 0.1);
43+
3644
std::unique_ptr<IStructurePoolBlockPredicate> targetBlock =
3745
std::make_unique<StructurePoolBlockPredicateAlwaysTrue>();
3846

39-
auto blockRule =
40-
std::make_unique<StructurePoolBlockRule>(std::move(sourceBlock), std::move(targetBlock), &resultBlock);
47+
auto blockRule_1 =
48+
std::make_unique<StructurePoolBlockRule>(std::move(sourceBlock_pro1), std::move(targetBlock), &mossyStoneBricks);
49+
auto blockRule_2 =
50+
std::make_unique<StructurePoolBlockRule>(std::move(sourceBlock_pro1), std::move(targetBlock), &crackedStoneBricks);
51+
auto blockRule_3 =
52+
std::make_unique<StructurePoolBlockRule>(std::move(sourceBlock_pro2), std::move(targetBlock), &cobblestone);
53+
54+
4155
auto ruleList = std::make_unique<std::vector<std::unique_ptr<StructurePoolBlockRule>>>();
4256

43-
ruleList->push_back(std::move(blockRule));
57+
ruleList->emplace_back(std::move(blockRule_1));
58+
ruleList->emplace_back(std::move(blockRule_2));
59+
ruleList->emplace_back(std::move(blockRule_3));
60+
61+
jigsawBlockRulesRegistry->registerBlockRules("mike:stone_brick_replacement_jig", std::move(ruleList));
62+
63+
// br::worldgen::processors::BlockRules::Test block_test;
64+
// block_test.mData = br::worldgen::processors::BlockRules::RandomBlockMatch(stoneBricks.mLegacyBlock.get(), 0.2);
65+
66+
// auto blockRule_1 = br::worldgen::processors::RuleSet::from(block_test, mossyStoneBricks);
67+
// auto blockRule_2 = br::worldgen::processors::RuleSet::from(block_test, crackedStoneBricks);
68+
// auto blockRule_3 = br::worldgen::processors::RuleSet::from(block_test, cobblestone);
69+
70+
// auto ruleList = br::worldgen::StructureProcessor::Rule({blockRule_1, blockRule_2, blockRule_3});
71+
// auto prot = br::worldgen::StructureProcessor::Protected(VanillaBlockTypeIds::RedstoneBlock());
72+
// jigsawBlockRulesRegistry->record("mike:stone_brick_replacement", {ruleList, prot});
4473

45-
jigsawBlockRulesRegistry->registerBlockRules("custom:custom_structure_block_rule", std::move(ruleList));
4674
}
4775

4876
void CustomJigsawStructureElements::initialize(
@@ -52,45 +80,124 @@ void CustomJigsawStructureElements::initialize(
5280
) {
5381
auto& jigsawBlockRulesRegistry = jigsawRegistry.mJigsawBlockRulesRegistry;
5482
auto& jigsawStructureElementRegistry = jigsawRegistry.mJigsawElementRegistry;
55-
auto ruleList = jigsawBlockRulesRegistry->lookupByName("custom:custom_structure_block_rule");
83+
auto ruleList = jigsawBlockRulesRegistry->lookupByName("mike:stone_brick_replacement");
5684

5785
// 每一个结构nbt文件都得这样注册进来,多个nbt结构文件的可以使用同一个Block Rule
86+
// mike:5x5int
5887
jigsawStructureElementRegistry->registerStructureElement(
59-
"mike:21room",
88+
"mike:5x5intb",
6089
std::make_unique<StructurePoolElement>(
6190
manager,
62-
"custom/21room",
91+
"custom/beds5x5int",
92+
ruleList,
93+
nullptr,
94+
nullptr,
95+
Projection::TerrainMatching,
96+
PostProcessSettings::All
97+
)
98+
);
99+
jigsawStructureElementRegistry->registerStructureElement(
100+
"mike:5x5intc",
101+
std::make_unique<StructurePoolElement>(
102+
manager,
103+
"custom/chestcarpet5x5int",
104+
ruleList,
105+
nullptr,
106+
nullptr,
107+
Projection::TerrainMatching,
108+
PostProcessSettings::All
109+
)
110+
);
111+
jigsawStructureElementRegistry->registerStructureElement(
112+
"mike:5x5intk",
113+
std::make_unique<StructurePoolElement>(
114+
manager,
115+
"custom/kitchen5x5int",
63116
ruleList,
64117
nullptr,
65118
nullptr,
66-
Projection::Rigid,
67-
PostProcessSettings::None
119+
Projection::TerrainMatching,
120+
PostProcessSettings::All
68121
)
69122
);
70123

124+
//mike:ew7x4
71125
jigsawStructureElementRegistry->registerStructureElement(
72-
"mike:ew7x4",
126+
"mike:ew7x4h",
73127
std::make_unique<StructurePoolElement>(
74128
manager,
75129
"custom/ewhall",
76130
ruleList,
77131
nullptr,
78132
nullptr,
79-
Projection::Rigid,
80-
PostProcessSettings::None
133+
Projection::TerrainMatching,
134+
PostProcessSettings::All
135+
)
136+
);
137+
jigsawStructureElementRegistry->registerStructureElement(
138+
"mike:ew7x4r",
139+
std::make_unique<StructurePoolElement>(
140+
manager,
141+
"custom/21room",
142+
ruleList,
143+
nullptr,
144+
nullptr,
145+
Projection::TerrainMatching,
146+
PostProcessSettings::All
81147
)
82148
);
83149

150+
//mike:ns7x4
84151
jigsawStructureElementRegistry->registerStructureElement(
85-
"mike:ns7x4",
152+
"mike:ns7x4h",
86153
std::make_unique<StructurePoolElement>(
87154
manager,
88155
"custom/nshall",
89156
ruleList,
90157
nullptr,
91158
nullptr,
92-
Projection::Rigid,
93-
PostProcessSettings::None
159+
Projection::TerrainMatching,
160+
PostProcessSettings::All
161+
)
162+
);
163+
jigsawStructureElementRegistry->registerStructureElement(
164+
"mike:ns7x4r",
165+
std::make_unique<StructurePoolElement>(
166+
manager,
167+
"custom/21room",
168+
ruleList,
169+
nullptr,
170+
nullptr,
171+
Projection::TerrainMatching,
172+
PostProcessSettings::All
173+
)
174+
);
175+
176+
//mike:ewcap
177+
jigsawStructureElementRegistry->registerStructureElement(
178+
"mike:ewcap",
179+
std::make_unique<StructurePoolElement>(
180+
manager,
181+
"custom/ewcap",
182+
ruleList,
183+
nullptr,
184+
nullptr,
185+
Projection::TerrainMatching,
186+
PostProcessSettings::All
187+
)
188+
);
189+
190+
//mike:nacap
191+
jigsawStructureElementRegistry->registerStructureElement(
192+
"mike:nscap",
193+
std::make_unique<StructurePoolElement>(
194+
manager,
195+
"custom/nscap",
196+
ruleList,
197+
nullptr,
198+
nullptr,
199+
Projection::TerrainMatching,
200+
PostProcessSettings::All
94201
)
95202
);
96203
}
@@ -104,19 +211,31 @@ void CustomJigsawStructure::initialize(
104211
CustomJigsawStructureElements::initialize(manager, featureRegistry, registry);
105212
auto& jigsawStructureElementRegistry = registry.mJigsawElementRegistry;
106213

107-
std::vector<std::pair<StructurePoolElement const*, int>> templates_room{
108-
{jigsawStructureElementRegistry->lookupByName("mike:21room"), 1}
214+
std::vector<std::pair<StructurePoolElement const*, int>> templates_5x5{
215+
{jigsawStructureElementRegistry->lookupByName("mike:5x5intb"), 4},
216+
{jigsawStructureElementRegistry->lookupByName("mike:5x5intc"), 1},
217+
{jigsawStructureElementRegistry->lookupByName("mike:5x5intk"), 1}
109218
};
110219
std::vector<std::pair<StructurePoolElement const*, int>> templates_ew{
111-
{jigsawStructureElementRegistry->lookupByName("mike:ew7x4"), 1}
220+
{jigsawStructureElementRegistry->lookupByName("mike:ew7x4h"), 4},
221+
{jigsawStructureElementRegistry->lookupByName("mike:ew7x4r"), 1}
112222
};
113223
std::vector<std::pair<StructurePoolElement const*, int>> templates_ns{
114-
{jigsawStructureElementRegistry->lookupByName("mike:ns7x4"), 1}
224+
{jigsawStructureElementRegistry->lookupByName("mike:ns7x4h"), 4},
225+
{jigsawStructureElementRegistry->lookupByName("mike:ns7x4r"), 1}
226+
};
227+
std::vector<std::pair<StructurePoolElement const*, int>> templates_ewcap{
228+
{jigsawStructureElementRegistry->lookupByName("mike:ewcap"), 4}
229+
};
230+
std::vector<std::pair<StructurePoolElement const*, int>> templates_nscap{
231+
{jigsawStructureElementRegistry->lookupByName("mike:nscap"), 4}
115232
};
116233

117-
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:21room", "empty", templates_room));
118-
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:ew7x4", "empty", templates_ew));
119-
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:ns7x4", "empty", templates_ns));
234+
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:5x5int", "empty", templates_5x5));
235+
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:ew7x4", "mike:ewcap", templates_ew));
236+
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:ns7x4", "mike:nscap", templates_ns));
237+
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:ewcap", "empty", templates_ewcap));
238+
registry.registerPool(std::make_unique<StructureTemplatePool>("mike:nscap", "empty", templates_nscap));
120239
}
121240

122241
} // namespace custom_structure

src/test/generator/generator-custom-structure/structure/CustomStructureFeature.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ bool CustomStructureFeature::getNearestGeneratedFeature(
3333

3434
bool CustomStructureFeature::
3535
isFeatureChunk(::BiomeSource const&, ::Random& random, ::ChunkPos const& cpos, uint, ::IPreliminarySurfaceProvider const&, ::Dimension const&) {
36-
int salt = 0x13272F0;
36+
int salt = 39281139;
3737
uint newSeed = mSeed + salt + 0xF1565BD5 * (cpos.z / mMaxSpacing) - 0x66C60AF8 * (cpos.x / mMaxSpacing);
3838
random.mRandom->mObject.mHaveNextNextGaussian = false;
3939
random.mRandom->mObject.mSeed = newSeed;
@@ -75,7 +75,7 @@ std::unique_ptr<::StructureStart> CustomStructureFeature::
7575
};
7676

7777
CustomStructureFeature::CustomStructureFeature(uint seed, uint minSpacing, uint maxSpacing)
78-
: StructureFeature(seed, HashedString("custom:custom_structure_test")),
78+
: StructureFeature(seed, HashedString("mike:basic_dungeon")),
7979
mSeed(seed),
8080
mMinSpacing(minSpacing),
8181
mMaxSpacing(maxSpacing) {}

src/test/generator/generator-custom-structure/structure/CustomStructurePiece.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ namespace custom_structure {
2323
int CustomStructurePiece::
2424
generateHeightAtPosition(BlockPos const&, Dimension& dim, BlockVolume&, std::unordered_map<ChunkPos, std::unique_ptr<std::vector<short>>>&)
2525
const {
26-
return dim.mSeaLevel + 1;
26+
return dim.mSeaLevel + 2;
2727
};
2828

2929
Block const* CustomStructurePiece::getSupportBlock(::BlockSource&, ::BlockPos const&, ::Block const&) const {
30-
return &BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::Netherrack(), 1);
30+
return &BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::GrassBlock());
3131
};
3232

3333
Block const& CustomStructurePiece::getBeardStabilizeBlock(::Block const&) const {
34-
return BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::Netherrack(), 1);
34+
return BlockTypeRegistry::getDefaultBlockState(VanillaBlockTypeIds::GrassBlock());
3535
};
3636

37-
AdjustmentEffect CustomStructurePiece::getTerrainAdjustmentEffect() const { return AdjustmentEffect::BeardAndShave; };
37+
AdjustmentEffect CustomStructurePiece::getTerrainAdjustmentEffect() const { return AdjustmentEffect::Beard; };
3838

3939
CustomStructurePiece::CustomStructurePiece(
4040
::StructurePoolElement const& element,
@@ -55,7 +55,7 @@ void CustomStructurePiece::addPieces(
5555
VanillaBiomeTypes biomeType,
5656
Dimension& dimension
5757
) {
58-
auto templates = pools.lookupByName("mike:21room");
58+
auto templates = pools.lookupByName("mike:ns7x4");
5959
// templates.getRandomTemplate(random);
6060

6161
auto lambda = [](StructurePoolElement const& element,
@@ -73,7 +73,7 @@ void CustomStructurePiece::addPieces(
7373
place.addPieces(
7474
*templates->mTemplates->at(index),
7575
position,
76-
Rotation::Rotate90,
76+
Rotation(random.nextInt(4)),
7777
"",
7878
{}
7979
);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
11
#include "CustomStructureStart.h"
2+
3+
// CustomStructureStart::CustomStructureStart(int chunk_x, int chunk_z) {
4+
// chunkX = chunk_x;
5+
// chunkZ = chunk_z;
6+
// }

src/test/generator/generator-custom-structure/structure/CustomStructureStart.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
class CustomStructureStart : public StructureStart {
77
public:
88
CustomStructureStart() = default;
9-
virtual std::string_view getStructureName() const { return "custom:custom_structure_start"; };
9+
virtual std::string_view getStructureName() const { return "mike:basic_dungeon"; };
1010
};

0 commit comments

Comments
 (0)