Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'eclipse'
apply plugin: 'maven-publish'

version = '1.0'
group = 'com.yourname.modid' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'modid'
version = '1.1.0'
group = 'com.markus1002'
archivesBaseName = 'incubation'

sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' // Need this here so eclipse task generates correctly.

Expand Down Expand Up @@ -71,7 +71,7 @@ minecraft {
}

dependencies {
minecraft 'net.minecraftforge:forge:1.16.1-32.0.57'
minecraft 'net.minecraftforge:forge:1.16.3-34.1.0'
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public ChickenNestFeature(Codec<NoFeatureConfig> config)
super(config);
}

public boolean func_230362_a_(ISeedReader worldIn, StructureManager manager, ChunkGenerator generator, Random rand, BlockPos pos, NoFeatureConfig config)
{
@Override
public boolean func_241855_a(ISeedReader worldIn, ChunkGenerator generator, Random rand, BlockPos pos, NoFeatureConfig config) {
BlockState blockstate = ModBlocks.CHICKEN_NEST.getDefaultState().with(ChickenNestBlock.EGGS, 1 + rand.nextInt(3));

int i = worldIn.getHeight(Heightmap.Type.WORLD_SURFACE, pos.getX(), pos.getZ());
Expand All @@ -37,4 +37,4 @@ public boolean func_230362_a_(ISeedReader worldIn, StructureManager manager, Chu

return true;
}
}
}
13 changes: 11 additions & 2 deletions src/main/java/com/markus1002/incubation/core/Incubation.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import com.markus1002.incubation.core.util.EventHandler;
import com.markus1002.incubation.core.util.VanillaCompatibility;

import net.minecraft.world.gen.feature.Feature;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand All @@ -18,11 +21,17 @@ public Incubation()

MinecraftForge.EVENT_BUS.register(new EventHandler());
MinecraftForge.EVENT_BUS.register(this);

MinecraftForge.EVENT_BUS.addListener(ModFeatures::addFeaturesToBiome);
}

@SubscribeEvent
public void handleRegistration(RegistryEvent.Register<Feature<?>> event) {
ModFeatures.registerFeatures(event);
}

private void setup(final FMLCommonSetupEvent event)
{
VanillaCompatibility.setupVanillaCompatibility();
ModFeatures.setupFeatures();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,67 @@

import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.MobSpawnInfo;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.IFeatureConfig;
import net.minecraft.world.gen.feature.NoFeatureConfig;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.placement.ChanceConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.common.world.MobSpawnInfoBuilder;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.IForgeRegistry;

import java.util.function.Supplier;

@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModFeatures
{
public static final Feature<NoFeatureConfig> CHICKEN_NEST = new ChickenNestFeature(NoFeatureConfig.field_236558_a_);

@SubscribeEvent
public static void registerFeatures(RegistryEvent.Register<Feature<?>> event)
{
registerFeature(CHICKEN_NEST, "chicken_nest");
// make sure it's the expected registry
final ResourceLocation regName = ForgeRegistries.FEATURES.getRegistryName();
if (!event.getName().equals(regName)) {
return;
}
IForgeRegistry<Feature<?>> reg = event.getRegistry();

// register all features below this point
registerFeature(reg, CHICKEN_NEST, "chicken_nest");
}

private static void registerFeature(Feature<?> feature, String name)
private static void registerFeature(IForgeRegistry<Feature<?>> reg, Feature<?> feature, String name)
{
feature.setRegistryName(name);
ForgeRegistries.FEATURES.register(feature);
reg.register(feature);
}

public static void setupFeatures()

public static void addFeaturesToBiome(BiomeLoadingEvent biome)
{
for(Biome biome : ForgeRegistries.BIOMES.getValues())
{
if (BiomeDictionary.getTypes(biome).contains(Type.FOREST) && doesCreatureSpawnInBiome(EntityType.CHICKEN, EntityClassification.CREATURE, biome))
{
biome.addFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CHICKEN_NEST.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.CHANCE_HEIGHTMAP_DOUBLE.configure(new ChanceConfig(32))));
}
}
if (biome.getCategory() == Biome.Category.FOREST && doesCreatureSpawnInBiome(EntityType.CHICKEN, biome.getSpawns()))

biome.getGeneration().getFeatures(GenerationStage.Decoration.VEGETAL_DECORATION).add(
configuredFeatureSupplier(CHICKEN_NEST)
);
}

private static boolean doesCreatureSpawnInBiome(EntityType<?> entityType, EntityClassification classification, Biome biome)
private static Supplier<ConfiguredFeature<?,?>> configuredFeatureSupplier(Feature<NoFeatureConfig> feature) {
return () -> feature.withConfiguration(IFeatureConfig.NO_FEATURE_CONFIG).withPlacement(Placement.field_242898_b.configure(new ChanceConfig(32)));
}

private static boolean doesCreatureSpawnInBiome(EntityType<?> entityType, MobSpawnInfoBuilder spawns)
{
for (Biome.SpawnListEntry entry : biome.getSpawns(classification))
{
if (entry.entityType == entityType)
{
for (MobSpawnInfo.Spawners spawner : spawns.getSpawner(EntityClassification.CREATURE)) {
if (spawner.field_242588_c == entityType) {
return true;
}
}

return false;
}
}
}
11 changes: 6 additions & 5 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
modLoader="javafml"
loaderVersion="[31,)"
issueTrackerURL="https://github.com/Markus1002/Incubation/issues"
loaderVersion="[34,)"
issueTrackerURL="https://github.com/allaryin/Incubation/issues"
license="LGPL-2.1"
[[mods]]
modId="incubation"
version="1.1.0"
displayName="Incubation"
displayURL="https://www.curseforge.com/minecraft/mc-mods/incubation"
logoFile="logo.png"
credits="Markus1002, Translators: vhslance, F4zzer, peehpeh, xM4RCOSx, XanaSago, Rye"
authors="Markus1002"
authors="Markus1002, allaryin"
description='''Adds chicken nests and makes eggs more useful.'''
[[dependencies.incubation]]
modId="forge"
mandatory=true
versionRange="[32.0.57,)"
versionRange="[34.1.0,)"
ordering="NONE"
side="BOTH"
[[dependencies.incubation]]
modId="minecraft"
mandatory=true
versionRange="[1.16.1]"
versionRange="[1.16.3]"
ordering="NONE"
side="BOTH"