Global features registration API
This commit is contained in:
parent
4dd1c55924
commit
d99d1262d0
4 changed files with 39 additions and 20 deletions
|
@ -1,24 +1,22 @@
|
|||
package ru.betterend.mixin.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.ChunkRegion;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.GenerationSettings;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.registry.FeatureRegistry;
|
||||
|
||||
@Mixin(Biome.class)
|
||||
|
@ -33,20 +31,9 @@ public abstract class BiomeMixin {
|
|||
@Inject(method = "generateFeatureStep", at = @At("HEAD"))
|
||||
public void generateFeatureStep(StructureAccessor structureAccessor, ChunkGenerator chunkGenerator, ChunkRegion region, long populationSeed, ChunkRandom random, BlockPos pos, CallbackInfo cinfo) {
|
||||
if (!injected) {
|
||||
if (category.equals(Biome.Category.THEEND)) {
|
||||
int index = FeatureRegistry.ENDER_ORE.getFeatureStep().ordinal();
|
||||
List<List<Supplier<ConfiguredFeature<?, ?>>>> features = this.generationSettings.getFeatures();
|
||||
if (features.size() > index) {
|
||||
features.get(index).add(() -> {
|
||||
return FeatureRegistry.ENDER_ORE.getFeatureConfigured();
|
||||
});
|
||||
} else {
|
||||
List<Supplier<ConfiguredFeature<?, ?>>> feature = Lists.newArrayList();
|
||||
feature.add(() -> {
|
||||
return FeatureRegistry.ENDER_ORE.getFeatureConfigured();
|
||||
});
|
||||
features.add(feature);
|
||||
}
|
||||
Identifier biomeId = region.toServerWorld().getRegistryManager().get(Registry.BIOME_KEY).getId(Biome.class.cast(this));
|
||||
if (biomeId != null && !biomeId.getNamespace().equals(BetterEnd.MOD_ID) && category.equals(Biome.Category.THEEND)) {
|
||||
FeatureRegistry.registerGlobals(this.generationSettings.getFeatures());
|
||||
}
|
||||
this.injected = true;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
package ru.betterend.registry;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import ru.betterend.world.features.BlueVineFeature;
|
||||
import ru.betterend.world.features.DoublePlantFeature;
|
||||
import ru.betterend.world.features.EndFeature;
|
||||
|
@ -11,6 +17,9 @@ import ru.betterend.world.features.SinglePlantFeature;
|
|||
import ru.betterend.world.features.VineFeature;
|
||||
|
||||
public class FeatureRegistry {
|
||||
|
||||
public final static List<EndFeature> globalFeatures = Lists.newArrayList();
|
||||
|
||||
// Trees //
|
||||
public static final EndFeature MOSSY_GLOWSHROOM = new EndFeature("mossy_glowshroom", new MossyGlowshroomFeature(), 3);
|
||||
public static final EndFeature PYTHADENDRON_TREE = new EndFeature("pythadendron_tree", new PythadendronTreeFeature(), 2);
|
||||
|
@ -33,6 +42,27 @@ public class FeatureRegistry {
|
|||
// Ores //
|
||||
public static final EndFeature ENDER_ORE = EndFeature.makeOreFeature("ender_ore", BlockRegistry.ENDER_ORE, 6, 3, 0, 4, 96);
|
||||
public static final EndFeature VIOLECITE_LAYER = EndFeature.makeLayerFeature("violecite_layer", BlockRegistry.VIOLECITE, 15, 4, 96, 8);
|
||||
public static final EndFeature FLAVOLITE_LAYER = EndFeature.makeLayerFeature("flavolite_layer", BlockRegistry.FLAVOLITE, 12, 4, 96, 6);
|
||||
|
||||
public static void registerGlobals(List<List<Supplier<ConfiguredFeature<?, ?>>>> features) {
|
||||
globalFeatures.add(FLAVOLITE_LAYER);
|
||||
globalFeatures.add(ENDER_ORE);
|
||||
|
||||
globalFeatures.forEach(feature -> {
|
||||
int index = feature.getFeatureStep().ordinal();
|
||||
if (features.size() > index) {
|
||||
features.get(index).add(() -> {
|
||||
return feature.getFeatureConfigured();
|
||||
});
|
||||
} else {
|
||||
List<Supplier<ConfiguredFeature<?, ?>>> newFeature = Lists.newArrayList();
|
||||
newFeature.add(() -> {
|
||||
return feature.getFeatureConfigured();
|
||||
});
|
||||
features.add(newFeature);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void register() {}
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ public class BiomeChorusForest extends EndBiome {
|
|||
.setMusic(SoundRegistry.MUSIC_CHORUS_FOREST)
|
||||
.addFeature(FeatureRegistry.ENDER_ORE)
|
||||
.addFeature(FeatureRegistry.VIOLECITE_LAYER)
|
||||
.addFeature(FeatureRegistry.FLAVOLITE_LAYER)
|
||||
.addFeature(FeatureRegistry.RARE_END_LAKE)
|
||||
.addFeature(FeatureRegistry.PYTHADENDRON_TREE)
|
||||
.addFeature(FeatureRegistry.PYTHADENDRON_BUSH)
|
||||
|
|
|
@ -21,6 +21,7 @@ public class BiomeFoggyMushroomland extends EndBiome {
|
|||
.setMusic(SoundRegistry.MUSIC_FOGGY_MUSHROOMLAND)
|
||||
.addStructureFeature(StructureRegistry.GIANT_MOSSY_GLOWSHROOM)
|
||||
.addFeature(FeatureRegistry.ENDER_ORE)
|
||||
.addFeature(FeatureRegistry.FLAVOLITE_LAYER)
|
||||
.addFeature(FeatureRegistry.END_LAKE)
|
||||
.addFeature(FeatureRegistry.MOSSY_GLOWSHROOM)
|
||||
.addFeature(FeatureRegistry.BLUE_VINE)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue