Skip to content

Commit e575c9c

Browse files
committed
Random Patch condition
1 parent c8ed969 commit e575c9c

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<#include "mcitems.ftl">
22
new RandomPatchConfiguration.GrassConfigurationBuilder(${mappedBlockToBlockStateProvider(input$block)}, SimpleBlockPlacer.INSTANCE)
3-
.tries(${field$tries}).xspread(${field$xzSpread}).zspread(${field$xzSpread}).yspread(${field$ySpread}).build()
3+
.tries(${field$tries}).xspread(${field$xzSpread}).zspread(${field$xzSpread}).yspread(${field$ySpread}).build()
4+
$
5+
if(!(${input$condition})) return false;
6+
$

src/main/resources/forge-1.17.1/generator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import:
88

99
java_models:
1010
key: mojmap-1.17.x
11-
compatible: [mojmap-1.18.x, mojmap-1.19.x, mojmap-1.20.x]
11+
compatible: [mojmap-1.18.x, mojmap-1.19.x, mojmap-1.20.x, mojmap-1.21.x]
1212
requested_key_words: [ModelPart, ~ModelRenderer, ~(ResourceLocation.]
1313

1414
# gradle task definitions

src/main/resources/forge-1.17.1/templates/feature/feature.java.ftl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,18 @@ import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvi
4949
</#if>
5050
<#assign placementPattern = r'\$([^$]+)\$'>
5151
<#assign placementMatches = placementcode?matches(placementPattern)>
52-
<#assign hardcodedElements = []>
52+
<#assign placementHardcodedElements = []>
5353
<#list placementMatches as match>
54-
<#assign hardcodedElements = hardcodedElements + [match?groups[1]]>
54+
<#assign placementHardcodedElements = placementHardcodedElements + [match?groups[1]]>
5555
</#list>
56-
<#assign nonHardcodedElements = placementcode?replace(placementPattern, "", "r")>
56+
<#assign nonHardcodedPlacement = placementcode?replace(placementPattern, "", "r")>
57+
<#assign configurationMatches = configurationcode?matches(placementPattern)>
58+
<#assign configurationHardcodedElements = []>
59+
<#list configurationMatches as match>
60+
<#assign configurationHardcodedElements = configurationHardcodedElements + [match?groups[1]]>
61+
</#list>
62+
<#assign nonHardcodedConfiguration = configurationcode?replace(placementPattern, "", "r")>
63+
<#assign allHardcodedElements = placementHardcodedElements + configurationHardcodedElements>
5764
<#compress>
5865
public class ${name}Feature extends ${generator.map(featuretype, "features")} {
5966
private static ${name}Feature FEATURE = null;
@@ -64,8 +71,9 @@ public class ${name}Feature extends ${generator.map(featuretype, "features")} {
6471
}
6572

6673
public static Feature<?> feature() {
74+
Random random = new Random();
6775
FEATURE = new ${name}Feature();
68-
CONFIGURED_FEATURE = <#if featuretype == "configured_feature_reference">${configurationcode}<#else>FEATURE.configured(<#if configurationcode == "">NoneFeatureConfiguration.INSTANCE<#else>${configurationcode}</#if>)</#if><#if data.hasPlacedFeature()>${nonHardcodedElements}</#if>;
76+
CONFIGURED_FEATURE = <#if featuretype == "configured_feature_reference">${nonHardcodedConfiguration}<#else>FEATURE.configured(<#if nonHardcodedConfiguration == "">NoneFeatureConfiguration.INSTANCE<#else>${nonHardcodedConfiguration}</#if>)</#if><#if data.hasPlacedFeature()>${nonHardcodedPlacement}</#if>;
6977

7078
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation("${modid}:${registryname}"), CONFIGURED_FEATURE);
7179

@@ -105,7 +113,7 @@ public class ${name}Feature extends ${generator.map(featuretype, "features")} {
105113
);
106114
</#if>
107115

108-
<#if data.hasPlacedFeature() && ((data.restrictionBiomes?has_content && cond) || data.hasGenerationConditions() || (hardcodedElements?size > 0))>
116+
<#if data.hasPlacedFeature() && ((data.restrictionBiomes?has_content && cond) || data.hasGenerationConditions() || (allHardcodedElements?size > 0))>
109117
@Override public boolean place(FeaturePlaceContext<${configuration}> context) {
110118
<#-- #4781 - we need to use WorldGenLevel instead of Level, or one can run incompatible procedures in condition -->
111119
WorldGenLevel world = context.level();
@@ -123,13 +131,13 @@ public class ${name}Feature extends ${generator.map(featuretype, "features")} {
123131
return false;
124132
</#if>
125133

126-
<#if data.hasPlacedFeature() && (hardcodedElements?size > 0)>
127-
<#list hardcodedElements as element>
134+
<#if data.hasPlacedFeature() && (allHardcodedElements?size > 0)>
135+
<#list allHardcodedElements as element>
128136
${element}
129137
</#list>
130138
</#if>
131139

132-
return super.place(<#if (hardcodedElements?size > 0)>new FeaturePlaceContext<>(world, context.chunkGenerator(), context.random(), origin, context.config())<#else>context</#if>);
140+
return super.place(<#if (allHardcodedElements?size > 0)>new FeaturePlaceContext<>(world, context.chunkGenerator(), context.random(), origin, context.config())<#else>context</#if>);
133141
}
134142
</#if>
135143
}</#compress>
@@ -178,4 +186,4 @@ public class ${name}Feature extends ${generator.map(featuretype, "features")} {
178186
<#assign result = "minecraft:" + noHash />
179187
<#return input?starts_with("#")?then("#" + result, result)/>
180188
</#if>
181-
</#function>
189+
</#function>

0 commit comments

Comments
 (0)