Skip to content

Commit

Permalink
better feature registration
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsterner committed Aug 3, 2023
1 parent 913e0ae commit 3927f33
Show file tree
Hide file tree
Showing 12 changed files with 310 additions and 122 deletions.
25 changes: 16 additions & 9 deletions src/main/java/dev/sterner/culturaldelights/CulturalDelights.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,34 @@

import com.mojang.serialization.Codec;
import dev.sterner.culturaldelights.common.registry.CDObjects;
import dev.sterner.culturaldelights.common.registry.CDConfiguredFeatures;
import dev.sterner.culturaldelights.common.registry.CDWorldGenerators;
import dev.sterner.culturaldelights.common.utils.Constants;
import dev.sterner.culturaldelights.common.world.AvocadoBundleTreeDecorator;
import dev.sterner.culturaldelights.mixin.TreeDecoratorTypeInvoker;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.loot.v2.LootTableEvents;
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.LootPool;
import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.random.Random;
import net.minecraft.village.TradeOffer;
import net.minecraft.village.TradeOffers;
import net.minecraft.village.VillagerProfession;
import net.minecraft.world.biome.BiomeKeys;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.treedecorator.TreeDecorator;
import net.minecraft.world.gen.treedecorator.TreeDecoratorType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CulturalDelights implements ModInitializer {
public static final String MOD_ID = "culturaldelights";
private static final Identifier SQUID_LOOT_TABLE_ID = EntityType.SQUID.getLootTableId();
private static final Identifier GLOW_SQUID_LOOT_TABLE_ID = EntityType.GLOW_SQUID.getLootTableId();

Expand All @@ -46,8 +42,19 @@ private static <P extends TreeDecorator> TreeDecoratorType<P> register(Identifie
@Override
public void onInitialize() {
CDObjects.init();

CDConfiguredFeatures.registerAll();
CDWorldGenerators.init();

BiomeModifications.addFeature(context -> context.getBiomeKey().equals(BiomeKeys.PLAINS), GenerationStep.Feature.VEGETAL_DECORATION,
CDConfiguredFeatures.PATCH_WILD_CUCUMBERS.key());
BiomeModifications.addFeature(context -> context.getBiomeKey().equals(BiomeKeys.SWAMP), GenerationStep.Feature.VEGETAL_DECORATION,
CDConfiguredFeatures.PATCH_WILD_EGGPLANTS.key());
BiomeModifications.addFeature(context -> context.getBiomeKey().equals(BiomeKeys.SWAMP), GenerationStep.Feature.VEGETAL_DECORATION,
CDConfiguredFeatures.PATCH_WILD_CUCUMBERS.key());
BiomeModifications.addFeature(context -> context.getBiomeKey().equals(BiomeKeys.JUNGLE), GenerationStep.Feature.VEGETAL_DECORATION,
CDConfiguredFeatures.PATCH_WILD_EGGPLANTS.key());

TradeOfferHelper.registerVillagerOffers(VillagerProfession.FARMER, 1, factories -> {
factories.add(new EmeraldToItemOffer(new ItemStack(CDObjects.CUCUMBER), 1, 10, 2, 0.2F));
factories.add(new EmeraldToItemOffer(new ItemStack(CDObjects.EGGPLANT), 1, 10, 2, 0.2F));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.sterner.culturaldelights.common.registry;

import dev.sterner.culturaldelights.CulturalDelights;
import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.util.Identifier;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.FeatureConfig;
import net.minecraft.world.gen.feature.PlacedFeature;

public enum CDConfiguredFeatures {
PATCH_WILD_CORN("patch_wild_corn"),
PATCH_WILD_CUCUMBERS("patch_wild_cucumbers"),
PATCH_WILD_EGGPLANTS("patch_wild_eggplants");

private final Identifier featureIdentifier;
private RegistryKey<ConfiguredFeature<?, ?>> configuredFeatureRegistryKey;
private RegistryKey<PlacedFeature> featureRegistryKey;

CDConfiguredFeatures(String featurePathName) {
this.featureIdentifier = new Identifier(CulturalDelights.MOD_ID, featurePathName);
}

public static void registerAll() {
for (CDConfiguredFeatures value : values()) {
value.configuredFeatureRegistryKey = RegistryKey.of(RegistryKeys.CONFIGURED_FEATURE, value.featureIdentifier);
value.featureRegistryKey = RegistryKey.of(RegistryKeys.PLACED_FEATURE, value.featureIdentifier);
}
}

public RegistryKey<ConfiguredFeature<? extends FeatureConfig, ?>> configKey() {
return configuredFeatureRegistryKey;
}

public RegistryKey<PlacedFeature> key() {
return featureRegistryKey;
}

public Identifier identifier() {
return featureIdentifier;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package dev.sterner.culturaldelights.common.registry;

import dev.sterner.culturaldelights.common.utils.Constants;
import dev.sterner.culturaldelights.common.world.AvocadoBundleTreeDecorator;
import dev.sterner.culturaldelights.mixin.TreeDecoratorTypeInvoker;
import net.fabricmc.fabric.api.biome.v1.BiomeModification;
import net.fabricmc.fabric.api.biome.v1.BiomeModifications;
import net.fabricmc.fabric.api.biome.v1.BiomeSelectors;
import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBiomeTags;
import net.minecraft.registry.RegistryKey;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.feature.*;
import net.minecraft.world.gen.treedecorator.TreeDecoratorType;

public class CDWorldGenerators {

Expand All @@ -21,21 +15,7 @@ public class CDWorldGenerators {
public static final RegistryKey<ConfiguredFeature<?, ?>> AVOCADO_PIT = ConfiguredFeatures.of("culturaldelights:avocado_pit");
public static final RegistryKey<PlacedFeature> TREE_AVOCADO_PIT = PlacedFeatures.of("culturaldelights:tree_avocado_pit");

public static final RegistryKey<ConfiguredFeature<?, ?>> WILD_CORN = ConfiguredFeatures.of("culturaldelights:wild_corn");
public static final RegistryKey<PlacedFeature> WILD_CORN_PLACED = PlacedFeatures.of("culturaldelights:wild_corn");

public static final RegistryKey<ConfiguredFeature<?, ?>> WILD_CUCUMBERS = ConfiguredFeatures.of("culturaldelights:wild_cucumbers");
public static final RegistryKey<PlacedFeature> WILD_CUCUMBERS_PLACED = PlacedFeatures.of("culturaldelights:wild_cucumbers");

public static final RegistryKey<ConfiguredFeature<?, ?>> WILD_EGGPLANTS = ConfiguredFeatures.of("culturaldelights:wild_eggplants");
public static final RegistryKey<PlacedFeature> WILD_EGGPLANTS_PLACED = PlacedFeatures.of("culturaldelights:wild_eggplants");


public static void init() {
BiomeModifications.addFeature(BiomeSelectors.tag(ConventionalBiomeTags.JUNGLE), GenerationStep.Feature.VEGETAL_DECORATION, TREE_AVOCADO);
BiomeModifications.addFeature(BiomeSelectors.tag(ConventionalBiomeTags.PLAINS), GenerationStep.Feature.VEGETAL_DECORATION, WILD_CORN_PLACED);
BiomeModifications.addFeature(BiomeSelectors.tag(ConventionalBiomeTags.SWAMP), GenerationStep.Feature.VEGETAL_DECORATION, WILD_EGGPLANTS_PLACED);
BiomeModifications.addFeature(BiomeSelectors.tag(ConventionalBiomeTags.SWAMP), GenerationStep.Feature.VEGETAL_DECORATION, WILD_CUCUMBERS_PLACED);
BiomeModifications.addFeature(BiomeSelectors.tag(ConventionalBiomeTags.JUNGLE), GenerationStep.Feature.VEGETAL_DECORATION, WILD_EGGPLANTS_PLACED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"type": "farmersdelight:wild_crop",
"config": {
"primary_feature": {
"feature": {
"type": "minecraft:simple_block",
"config": {
"to_place": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "culturaldelights:wild_corn"
}
}
}
},
"placement": [
{
"type": "minecraft:block_predicate_filter",
"predicate": {
"type": "minecraft:all_of",
"predicates": [
{
"type": "minecraft:matching_blocks",
"blocks": "minecraft:air"
},
{
"type": "minecraft:matching_block_tag",
"tag": "minecraft:dirt",
"offset": [
0,
-1,
0
]
}
]
}
}
]
},
"secondary_feature": {
"feature": {
"type": "minecraft:simple_block",
"config": {
"to_place": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "minecraft:air"
}
}
}
},
"placement": [
{
"type": "minecraft:block_predicate_filter",
"predicate": {
"type": "minecraft:all_of",
"predicates": [
{
"type": "minecraft:matching_blocks",
"blocks": "minecraft:air"
},
{
"type": "minecraft:matching_block_tag",
"tag": "minecraft:dirt",
"offset": [
0,
-1,
0
]
}
]
}
}
]
},
"tries": 32,
"xz_spread": 6,
"y_spread": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"type": "farmersdelight:wild_crop",
"config": {
"primary_feature": {
"feature": {
"type": "minecraft:simple_block",
"config": {
"to_place": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "culturaldelights:wild_cucumbers"
}
}
}
},
"placement": [
{
"type": "minecraft:block_predicate_filter",
"predicate": {
"type": "minecraft:all_of",
"predicates": [
{
"type": "minecraft:matching_blocks",
"blocks": "minecraft:air"
},
{
"type": "minecraft:matching_block_tag",
"tag": "minecraft:dirt",
"offset": [
0,
-1,
0
]
}
]
}
}
]
},
"secondary_feature": {
"feature": {
"type": "minecraft:simple_block",
"config": {
"to_place": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "minecraft:air"
}
}
}
},
"placement": [
{
"type": "minecraft:block_predicate_filter",
"predicate": {
"type": "minecraft:all_of",
"predicates": [
{
"type": "minecraft:matching_blocks",
"blocks": "minecraft:air"
},
{
"type": "minecraft:matching_block_tag",
"tag": "minecraft:dirt",
"offset": [
0,
-1,
0
]
}
]
}
}
]
},
"tries": 32,
"xz_spread": 6,
"y_spread": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"type": "farmersdelight:wild_crop",
"config": {
"primary_feature": {
"feature": {
"type": "minecraft:simple_block",
"config": {
"to_place": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "culturaldelights:wild_eggplant"
}
}
}
},
"placement": [
{
"type": "minecraft:block_predicate_filter",
"predicate": {
"type": "minecraft:all_of",
"predicates": [
{
"type": "minecraft:matching_blocks",
"blocks": "minecraft:air"
},
{
"type": "minecraft:matching_block_tag",
"tag": "minecraft:dirt",
"offset": [
0,
-1,
0
]
}
]
}
}
]
},
"secondary_feature": {
"feature": {
"type": "minecraft:simple_block",
"config": {
"to_place": {
"type": "minecraft:simple_state_provider",
"state": {
"Name": "minecraft:air"
}
}
}
},
"placement": [
{
"type": "minecraft:block_predicate_filter",
"predicate": {
"type": "minecraft:all_of",
"predicates": [
{
"type": "minecraft:matching_blocks",
"blocks": "minecraft:air"
},
{
"type": "minecraft:matching_block_tag",
"tag": "minecraft:dirt",
"offset": [
0,
-1,
0
]
}
]
}
}
]
},
"tries": 32,
"xz_spread": 6,
"y_spread": 3
}
}
Loading

0 comments on commit 3927f33

Please sign in to comment.