-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CustomLayeredFeature & LayeredFeature
- Loading branch information
1 parent
aa6da87
commit 527dd78
Showing
12 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...main/java/com/mmodding/mmodding_lib/library/worldgen/features/builtin/LayeredFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.mmodding.mmodding_lib.library.worldgen.features.builtin; | ||
|
||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.codecs.RecordCodecBuilder; | ||
import net.minecraft.util.registry.Registry; | ||
import net.minecraft.util.registry.RegistryKey; | ||
import net.minecraft.world.gen.feature.Feature; | ||
import net.minecraft.world.gen.feature.FeatureConfig; | ||
import net.minecraft.world.gen.feature.PlacedFeature; | ||
import net.minecraft.world.gen.feature.util.FeatureContext; | ||
|
||
import java.util.List; | ||
|
||
public class LayeredFeature extends Feature<LayeredFeature.Config> { | ||
|
||
public LayeredFeature(Codec<LayeredFeature.Config> codec) { | ||
super(codec); | ||
} | ||
|
||
@Override | ||
public boolean place(FeatureContext<Config> context) { | ||
context.getConfig().features.forEach(feature -> { | ||
PlacedFeature entry = context.getWorld().getRegistryManager().get(Registry.PLACED_FEATURE_KEY).get(feature); | ||
if (entry != null) { | ||
entry.generate(context.getWorld(), context.getGenerator(), context.getRandom(), context.getOrigin()); | ||
} | ||
else { | ||
throw new IllegalArgumentException("PlacedFeature at " + feature + "does not exist"); | ||
} | ||
}); | ||
return true; | ||
} | ||
|
||
public static class Config implements FeatureConfig { | ||
|
||
private final List<RegistryKey<PlacedFeature>> features; | ||
|
||
public static final Codec<Config> CODEC = RecordCodecBuilder.create( | ||
instance -> instance | ||
.group(Codec.list(RegistryKey.codec(Registry.PLACED_FEATURE_KEY)).fieldOf("features").forGetter(config -> config.features)) | ||
.apply(instance, Config::new) | ||
); | ||
|
||
public Config(List<RegistryKey<PlacedFeature>> features) { | ||
this.features = features; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...reds/DifferedDripstoneClusterFeature.java → ...ered/DifferedDripstoneClusterFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...fereds/DifferedLargeDripstoneFeature.java → ...ffered/DifferedLargeDripstoneFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...fereds/DifferedLiquidVegetationPatch.java → ...ffered/DifferedLiquidVegetationPatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...reds/DifferedPointedDripstoneFeature.java → ...ered/DifferedPointedDripstoneFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...va/com/mmodding/mmodding_lib/library/worldgen/features/defaults/CustomLayeredFeature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.mmodding.mmodding_lib.library.worldgen.features.defaults; | ||
|
||
import com.mmodding.mmodding_lib.library.utils.BiArrayList; | ||
import com.mmodding.mmodding_lib.library.utils.BiList; | ||
import com.mmodding.mmodding_lib.library.utils.IdentifierUtils; | ||
import com.mmodding.mmodding_lib.library.worldgen.MModdingFeatures; | ||
import com.mmodding.mmodding_lib.library.worldgen.features.builtin.LayeredFeature; | ||
import net.minecraft.util.Holder; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
import net.minecraft.util.registry.RegistryKey; | ||
import net.minecraft.world.gen.GenerationStep; | ||
import net.minecraft.world.gen.feature.*; | ||
import org.quiltmc.qsl.worldgen.biome.api.BiomeModifications; | ||
import org.quiltmc.qsl.worldgen.biome.api.BiomeSelectionContext; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.Predicate; | ||
import java.util.function.Supplier; | ||
|
||
public class CustomLayeredFeature implements CustomFeature, FeatureRegistrable { | ||
|
||
private final AtomicBoolean registered = new AtomicBoolean(); | ||
private final AtomicReference<Identifier> identifier = new AtomicReference<>(); | ||
private final BiList<PlacedFeature, String> additionalPlacedFeatures = new BiArrayList<>(); | ||
|
||
private final Supplier<List<RegistryKey<PlacedFeature>>> features; | ||
private final GenerationStep.Feature step; | ||
private final List<PlacementModifier> defaultPlacementModifiers; | ||
|
||
public CustomLayeredFeature(Supplier<List<RegistryKey<PlacedFeature>>> features, GenerationStep.Feature step, PlacementModifier... defaultPlacementModifiers) { | ||
this.features = features; | ||
this.step = step; | ||
this.defaultPlacementModifiers = List.of(defaultPlacementModifiers); | ||
} | ||
|
||
@Override | ||
public Feature<LayeredFeature.Config> getFeature() { | ||
return MModdingFeatures.LAYERED; | ||
} | ||
|
||
@Override | ||
public ConfiguredFeature<?, ?> getConfiguredFeature() { | ||
return new ConfiguredFeature<>(this.getFeature(), new LayeredFeature.Config(this.features.get())); | ||
} | ||
|
||
public PlacedFeature createPlacedFeature(List<PlacementModifier> placementModifiers) { | ||
return new PlacedFeature(Holder.createDirect(this.getConfiguredFeature()), placementModifiers); | ||
} | ||
|
||
@Override | ||
public PlacedFeature getDefaultPlacedFeature() { | ||
return this.createPlacedFeature(this.defaultPlacementModifiers); | ||
} | ||
|
||
public CustomLayeredFeature addPlacedFeature(List<PlacementModifier> placementModifiers, String idExt) { | ||
this.additionalPlacedFeatures.add(this.createPlacedFeature(placementModifiers), idExt); | ||
return this; | ||
} | ||
|
||
@Override | ||
public BiList<PlacedFeature, String> getAdditionalPlacedFeatures() { | ||
return this.additionalPlacedFeatures; | ||
} | ||
|
||
@Override | ||
public void addDefaultToBiomes(Predicate<BiomeSelectionContext> ctx) { | ||
this.addAdditionalToBiomes(ctx, ""); | ||
} | ||
|
||
@Override | ||
public void addAdditionalToBiomes(Predicate<BiomeSelectionContext> ctx, String idExt) { | ||
if (this.registered.get()) { | ||
BiomeModifications.addFeature( | ||
ctx, this.step, | ||
RegistryKey.of(Registry.PLACED_FEATURE_KEY, IdentifierUtils.extend(this.identifier.get(), idExt)) | ||
); | ||
} | ||
} | ||
|
||
@Override | ||
public void setIdentifier(Identifier identifier) { | ||
this.identifier.set(identifier); | ||
} | ||
|
||
@Override | ||
public boolean isNotRegistered() { | ||
return !this.registered.get(); | ||
} | ||
|
||
@Override | ||
public void setRegistered() { | ||
this.registered.set(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters