Skip to content

Commit

Permalink
Added support for end surface rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Adubbz committed Jan 13, 2024
1 parent f8c1e89 commit 07eab88
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public static SurfaceRules.RuleSource getDefaultSurfaceRules(RuleCategory catego

if (category == RuleCategory.NETHER)
return TBSurfaceRuleData.nether();
else if (category == RuleCategory.END) {
return TBSurfaceRuleData.end();
}

return TBSurfaceRuleData.overworld();
}
Expand All @@ -125,7 +128,7 @@ public static SurfaceRules.RuleSource getDefaultSurfaceRules(RuleCategory catego
*/
public enum RuleCategory
{
OVERWORLD, NETHER
OVERWORLD, NETHER, END
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,31 +36,25 @@ public class MixinNoiseGeneratorSettings implements IExtendedNoiseGeneratorSetti
private SurfaceRules.RuleSource surfaceRule;

@Unique
private RegionType regionType = null;
private SurfaceRuleManager.RuleCategory ruleCategory = null;
@Unique
private SurfaceRules.RuleSource namespacedSurfaceRuleSource = null;

@Inject(method = "surfaceRule", at = @At("HEAD"), cancellable = true)
private void surfaceRule(CallbackInfoReturnable<SurfaceRules.RuleSource> cir)
{
if (this.regionType != null)
if (this.ruleCategory != null)
{
if (this.namespacedSurfaceRuleSource == null)
this.namespacedSurfaceRuleSource = regionType == RegionType.NETHER ? SurfaceRuleManager.getNamespacedRules(SurfaceRuleManager.RuleCategory.NETHER, this.surfaceRule) : SurfaceRuleManager.getNamespacedRules(SurfaceRuleManager.RuleCategory.OVERWORLD, this.surfaceRule);
this.namespacedSurfaceRuleSource = SurfaceRuleManager.getNamespacedRules(this.ruleCategory, this.surfaceRule);

cir.setReturnValue(this.namespacedSurfaceRuleSource);
}
}

@Override
public void setRegionType(RegionType regionType)
public void setRuleCategory(SurfaceRuleManager.RuleCategory ruleCategory)
{
this.regionType = regionType;
}

@Override
public RegionType getRegionType()
{
return this.regionType;
this.ruleCategory = ruleCategory;
}
}
21 changes: 14 additions & 7 deletions Common/src/main/java/terrablender/util/LevelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import terrablender.DimensionTypeTags;
import terrablender.api.RegionType;
import terrablender.api.Regions;
import terrablender.api.SurfaceRuleManager;
import terrablender.core.TerraBlender;
import terrablender.worldgen.IExtendedBiomeSource;
import terrablender.worldgen.IExtendedNoiseGeneratorSettings;
Expand Down Expand Up @@ -75,19 +76,20 @@ public static RegionType getRegionTypeForDimension(Holder<DimensionType> dimensi

public static void initializeBiomes(RegistryAccess registryAccess, Holder<DimensionType> dimensionType, ResourceKey<LevelStem> levelResourceKey, ChunkGenerator chunkGenerator, long seed)
{
if (!(chunkGenerator instanceof NoiseBasedChunkGenerator noiseBasedChunkGenerator))
return;

NoiseGeneratorSettings generatorSettings = noiseBasedChunkGenerator.generatorSettings().value();

if (chunkGenerator.getBiomeSource() instanceof TheEndBiomeSource)
{
((IExtendedTheEndBiomeSource)chunkGenerator.getBiomeSource()).initializeForTerraBlender(registryAccess, seed);
((IExtendedNoiseGeneratorSettings)(Object)generatorSettings).setRuleCategory(SurfaceRuleManager.RuleCategory.END);
return;
}
else if (!shouldApplyToChunkGenerator(chunkGenerator))
{
return;
}
else if (!shouldApplyToBiomeSource(chunkGenerator.getBiomeSource())) return;

RegionType regionType = getRegionTypeForDimension(dimensionType);
NoiseBasedChunkGenerator noiseBasedChunkGenerator = (NoiseBasedChunkGenerator)chunkGenerator;
NoiseGeneratorSettings generatorSettings = noiseBasedChunkGenerator.generatorSettings().value();
MultiNoiseBiomeSource biomeSource = (MultiNoiseBiomeSource)chunkGenerator.getBiomeSource();
IExtendedBiomeSource biomeSourceEx = (IExtendedBiomeSource)biomeSource;

Expand All @@ -96,7 +98,12 @@ else if (!shouldApplyToChunkGenerator(chunkGenerator))
return;

// Set the chunk generator settings' region type
((IExtendedNoiseGeneratorSettings)(Object)generatorSettings).setRegionType(regionType);
SurfaceRuleManager.RuleCategory ruleCategory = switch(regionType) {
case OVERWORLD -> SurfaceRuleManager.RuleCategory.OVERWORLD;
case NETHER -> SurfaceRuleManager.RuleCategory.NETHER;
default -> throw new IllegalArgumentException("Attempted to get surface rule category for unsupported region type " + regionType);
};
((IExtendedNoiseGeneratorSettings)(Object)generatorSettings).setRuleCategory(ruleCategory);

Climate.ParameterList parameters = biomeSource.parameters();
IExtendedParameterList parametersEx = (IExtendedParameterList)parameters;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
package terrablender.worldgen;

import terrablender.api.RegionType;

/**
* Copyright (C) Glitchfiend
* <p>
Expand All @@ -19,8 +15,11 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package terrablender.worldgen;

import terrablender.api.SurfaceRuleManager;

public interface IExtendedNoiseGeneratorSettings
{
void setRegionType(RegionType regionType);
RegionType getRegionType();
void setRuleCategory(SurfaceRuleManager.RuleCategory ruleCategory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ public static SurfaceRules.RuleSource nether()
return SurfaceRules.sequence(builder.build().toArray(SurfaceRules.RuleSource[]::new));
}

public static SurfaceRules.RuleSource end()
{
return ENDSTONE;
}

public static SurfaceRules.RuleSource air()
{
return AIR;
Expand Down

0 comments on commit 07eab88

Please sign in to comment.