Skip to content

Commit 64fa7c2

Browse files
committed
Added PlacementFixed + Support for 1.21.x models
1 parent 974e6e2 commit 64fa7c2

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$if(!(
2+
<#if field_list$x?size != 0>
3+
<#list 0..field_list$x?size-1 as i>
4+
(context.origin().getX() == ${field_list$x[i]} && context.origin().getY() == ${field_list$y[i]} && context.origin().getZ() == ${field_list$z[i]})
5+
<#sep> ||</#list>
6+
<#else>false</#if>
7+
))
8+
return false;$

src/main/resources/forge-1.18.2/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.18.x
11-
compatible: [mojmap-1.17.x, mojmap-1.19.x, mojmap-1.20.x]
11+
compatible: [mojmap-1.17.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.18.2/templates/feature/feature.java.ftl

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvi
4747
</#if>
4848
</#list>
4949
</#if>
50+
<#assign placementPattern = r'\$([^$]+)\$'>
51+
<#assign placementMatches = placementcode?matches(placementPattern)>
52+
<#assign placementHardcodedElements = []>
53+
<#list placementMatches as match>
54+
<#assign placementHardcodedElements = placementHardcodedElements + [match?groups[1]]>
55+
</#list>
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>
5064
<#compress>
5165
public class ${name}Feature extends ${generator.map(featuretype, "features")} {
5266
private static ${name}Feature FEATURE = null;
@@ -59,9 +73,9 @@ public class ${name}Feature extends ${generator.map(featuretype, "features")} {
5973

6074
public static Feature<?> feature() {
6175
FEATURE = new ${name}Feature();
62-
CONFIGURED_FEATURE = <#if featuretype == "configured_feature_reference">${configurationcode}<#else>FeatureUtils.register("${modid}:${registryname}", FEATURE, ${configurationcode})</#if>;
76+
CONFIGURED_FEATURE = <#if featuretype == "configured_feature_reference">${nonHardcodedConfiguration}<#else>FeatureUtils.register("${modid}:${registryname}", FEATURE, ${nonHardcodedConfiguration})</#if>;
6377
PLACED_FEATURE = PlacementUtils.register("${modid}:${registryname}", CONFIGURED_FEATURE,
64-
List.of(<#if data.hasPlacedFeature()>${placementcode?remove_ending(",")}</#if>));
78+
List.of(<#if data.hasPlacedFeature()>${nonHardcodedPlacement?remove_ending(",")}</#if>));
6579
return FEATURE;
6680
}
6781

@@ -98,7 +112,7 @@ public class ${name}Feature extends ${generator.map(featuretype, "features")} {
98112
);
99113
</#if>
100114

101-
<#if data.hasPlacedFeature() && ((data.restrictionBiomes?has_content && cond) || data.hasGenerationConditions())>
115+
<#if data.hasPlacedFeature() && (((data.restrictionBiomes?has_content && cond) || data.hasGenerationConditions()) || (allHardcodedElements?size > 0))>
102116
@Override public boolean place(FeaturePlaceContext<${configuration}> context) {
103117
<#-- #4781 - we need to use WorldGenLevel instead of Level, or one can run incompatible procedures in condition -->
104118
WorldGenLevel world = context.level();
@@ -115,6 +129,12 @@ public class ${name}Feature extends ${generator.map(featuretype, "features")} {
115129
return false;
116130
</#if>
117131

132+
<#if (allHardcodedElements?size > 0)>
133+
<#list allHardcodedElements as element>
134+
${element}
135+
</#list>
136+
</#if>
137+
118138
return super.place(context);
119139
}
120140
</#if>

src/main/resources/forge-1.18.2/utils/mcelements.ftl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,26 @@
3737
</#function>
3838

3939
<#function toPlacedFeature featureType featureConfig placement="">
40+
<#local placementPattern = r'\$([^$]+)\$'>
41+
<#local placementMatches = placement?matches(placementPattern)>
42+
<#local hasHardcodedElements = (placementMatches?size > 0)>
43+
<#local nonHardcodedElements = placement>
44+
45+
<#if hasHardcodedElements>
46+
<#local nonHardcodedElements = placement?replace(placementPattern, "", "r")>
47+
</#if>
48+
4049
<#if featureType == "placed_feature_inline">
4150
<#return featureConfig>
4251
<#else>
4352
<#if featureType == "configured_feature_reference" && placement == "">
4453
<#return 'PlacementUtils.inlinePlaced(' + featureConfig + ')'>
4554
<#elseif featureType == "configured_feature_reference">
46-
<#return 'PlacementUtils.inlinePlaced(' + featureConfig + ',' + placement?remove_ending(",") + ')'>
47-
<#elseif placement == "">
55+
<#return 'PlacementUtils.inlinePlaced(' + featureConfig + ',' + nonHardcodedElements?remove_ending(",") + ')'>
56+
<#elseif nonHardcodedElements == "">
4857
<#return 'PlacementUtils.inlinePlaced(' + generator.map(featureType, "features", 2) + ', ' + featureConfig + ')'>
4958
<#else>
50-
<#return 'PlacementUtils.inlinePlaced(' + generator.map(featureType, "features", 2) + ', ' + featureConfig + ',' + placement?remove_ending(",") + ')'>
59+
<#return 'PlacementUtils.inlinePlaced(' + generator.map(featureType, "features", 2) + ', ' + featureConfig + ',' + nonHardcodedElements?remove_ending(",") + ')'>
5160
</#if>
5261
</#if>
5362
</#function>

0 commit comments

Comments
 (0)