Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate biome features and biome events on load, closes #190 #226

Merged
merged 1 commit into from
Mar 14, 2021
Merged
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
13 changes: 5 additions & 8 deletions src/main/java/vectorwing/farmersdelight/FarmersDelight.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -20,7 +19,6 @@
import vectorwing.farmersdelight.setup.ClientEventHandler;
import vectorwing.farmersdelight.setup.CommonEventHandler;
import vectorwing.farmersdelight.setup.Configuration;
import vectorwing.farmersdelight.world.CropPatchGeneration;

@Mod(FarmersDelight.MODID)
@Mod.EventBusSubscriber(modid = FarmersDelight.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
Expand All @@ -32,16 +30,15 @@ public class FarmersDelight
public static final FDItemGroup ITEM_GROUP = new FDItemGroup(FarmersDelight.MODID);

public FarmersDelight() {
FMLJavaModLoadingContext.get().getModEventBus().addListener(CommonEventHandler::init);
FMLJavaModLoadingContext.get().getModEventBus().addListener(ClientEventHandler::init);
FMLJavaModLoadingContext.get().getModEventBus().addGenericListener(IRecipeSerializer.class, this::registerRecipeSerializers);
MinecraftForge.EVENT_BUS.addListener(EventPriority.HIGH, CropPatchGeneration::onBiomeLoad);
final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

modEventBus.addListener(CommonEventHandler::init);
modEventBus.addListener(ClientEventHandler::init);
modEventBus.addGenericListener(IRecipeSerializer.class, this::registerRecipeSerializers);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, Configuration.COMMON_CONFIG);
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, Configuration.CLIENT_CONFIG);

final IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

ModParticleTypes.PARTICLE_TYPES.register(modEventBus);
ModEnchantments.ENCHANTMENTS.register(modEventBus);
ModItems.ITEMS.register(modEventBus);
Expand Down
200 changes: 123 additions & 77 deletions src/main/java/vectorwing/farmersdelight/setup/CommonEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStage;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.world.BiomeGenerationSettingsBuilder;
import net.minecraftforge.event.LootTableLoadEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.player.UseHoeEvent;
import net.minecraftforge.event.village.VillagerTradesEvent;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
Expand All @@ -37,6 +41,7 @@
import vectorwing.farmersdelight.registry.ModItems;
import vectorwing.farmersdelight.tile.dispenser.CuttingBoardDispenseBehavior;
import vectorwing.farmersdelight.utils.tags.ModTags;
import vectorwing.farmersdelight.world.CropPatchGeneration;
import vectorwing.farmersdelight.world.VillageStructures;

import javax.annotation.ParametersAreNonnullByDefault;
Expand All @@ -58,8 +63,11 @@ public class CommonEventHandler
private static final String[] SCAVENGING_ENTITIES = new String[]{"cow", "pig", "chicken", "rabbit", "horse", "donkey", "mule", "llama", "spider", "hoglin", "shulker"};

public static void init(final FMLCommonSetupEvent event) {
registerCompostables(event);
registerDispenserBehaviors(event);
event.enqueueWork(() -> {
registerCompostables();
registerDispenserBehaviors();
CropPatchGeneration.registerConfiguredFeatures();
});

ModAdvancements.register();

Expand All @@ -73,83 +81,121 @@ public static void init(final FMLCommonSetupEvent event) {
}
}

public static void registerDispenserBehaviors(final FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
if (Configuration.DISPENSER_TOOLS_CUTTING_BOARD.get()) {
CuttingBoardDispenseBehavior.registerBehaviour(Items.WOODEN_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.WOODEN_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.WOODEN_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.STONE_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.STONE_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.STONE_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.IRON_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.IRON_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.IRON_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.DIAMOND_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.DIAMOND_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.DIAMOND_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.GOLDEN_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.GOLDEN_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.GOLDEN_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.NETHERITE_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.NETHERITE_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.NETHERITE_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.SHEARS, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.FLINT_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.IRON_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.DIAMOND_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.GOLDEN_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.NETHERITE_KNIFE.get(), new CuttingBoardDispenseBehavior());
}
});
public static void registerDispenserBehaviors() {
if (Configuration.DISPENSER_TOOLS_CUTTING_BOARD.get()) {
CuttingBoardDispenseBehavior.registerBehaviour(Items.WOODEN_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.WOODEN_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.WOODEN_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.STONE_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.STONE_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.STONE_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.IRON_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.IRON_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.IRON_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.DIAMOND_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.DIAMOND_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.DIAMOND_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.GOLDEN_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.GOLDEN_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.GOLDEN_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.NETHERITE_PICKAXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.NETHERITE_AXE, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.NETHERITE_SHOVEL, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(Items.SHEARS, new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.FLINT_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.IRON_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.DIAMOND_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.GOLDEN_KNIFE.get(), new CuttingBoardDispenseBehavior());
CuttingBoardDispenseBehavior.registerBehaviour(ModItems.NETHERITE_KNIFE.get(), new CuttingBoardDispenseBehavior());
}
}

public static void registerCompostables(final FMLCommonSetupEvent event) {
event.enqueueWork(() -> {
// 30% chance
ComposterBlock.CHANCES.put(ModItems.TREE_BARK.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.STRAW.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.CABBAGE_SEEDS.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.TOMATO_SEEDS.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.RICE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.RICE_PANICLE.get(), 0.65F);

// 50% chance
ComposterBlock.CHANCES.put(ModItems.PUMPKIN_SLICE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.CABBAGE_LEAF.get(), 0.65F);

// 65% chance
ComposterBlock.CHANCES.put(ModItems.CABBAGE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.ONION.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.TOMATO.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_CABBAGES.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_ONIONS.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_TOMATOES.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_CARROTS.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_POTATOES.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_BEETROOTS.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_RICE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.PIE_CRUST.get(), 0.65F);

// 85% chance
ComposterBlock.CHANCES.put(ModItems.RICE_BALE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.SWEET_BERRY_COOKIE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.HONEY_COOKIE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.CAKE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.APPLE_PIE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.SWEET_BERRY_CHEESECAKE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.CHOCOLATE_PIE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.RAW_PASTA.get(), 0.85F);

// 100% chance
ComposterBlock.CHANCES.put(ModItems.APPLE_PIE.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.SWEET_BERRY_CHEESECAKE.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.CHOCOLATE_PIE.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.DUMPLINGS.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.STUFFED_PUMPKIN.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.BROWN_MUSHROOM_COLONY.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.RED_MUSHROOM_COLONY.get(), 1.0F);
});
public static void registerCompostables() {
// 30% chance
ComposterBlock.CHANCES.put(ModItems.TREE_BARK.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.STRAW.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.CABBAGE_SEEDS.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.TOMATO_SEEDS.get(), 0.3F);
ComposterBlock.CHANCES.put(ModItems.RICE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.RICE_PANICLE.get(), 0.65F);

// 50% chance
ComposterBlock.CHANCES.put(ModItems.PUMPKIN_SLICE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.CABBAGE_LEAF.get(), 0.65F);

// 65% chance
ComposterBlock.CHANCES.put(ModItems.CABBAGE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.ONION.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.TOMATO.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_CABBAGES.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_ONIONS.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_TOMATOES.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_CARROTS.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_POTATOES.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_BEETROOTS.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.WILD_RICE.get(), 0.65F);
ComposterBlock.CHANCES.put(ModItems.PIE_CRUST.get(), 0.65F);

// 85% chance
ComposterBlock.CHANCES.put(ModItems.RICE_BALE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.SWEET_BERRY_COOKIE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.HONEY_COOKIE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.CAKE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.APPLE_PIE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.SWEET_BERRY_CHEESECAKE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.CHOCOLATE_PIE_SLICE.get(), 0.85F);
ComposterBlock.CHANCES.put(ModItems.RAW_PASTA.get(), 0.85F);

// 100% chance
ComposterBlock.CHANCES.put(ModItems.APPLE_PIE.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.SWEET_BERRY_CHEESECAKE.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.CHOCOLATE_PIE.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.DUMPLINGS.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.STUFFED_PUMPKIN.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.BROWN_MUSHROOM_COLONY.get(), 1.0F);
ComposterBlock.CHANCES.put(ModItems.RED_MUSHROOM_COLONY.get(), 1.0F);
}

@SubscribeEvent
public static void onBiomeLoad(BiomeLoadingEvent event) {
BiomeGenerationSettingsBuilder builder = event.getGeneration();
Biome.Climate climate = event.getClimate();

if (event.getName().getPath().equals("beach")) {
if (Configuration.GENERATE_WILD_BEETROOTS.get()) {
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CropPatchGeneration.PATCH_WILD_BEETROOTS);
}
if (Configuration.GENERATE_WILD_CABBAGES.get()) {
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CropPatchGeneration.PATCH_WILD_CABBAGES);
}
}

if (event.getCategory().equals(Biome.Category.SWAMP) || event.getCategory().equals(Biome.Category.JUNGLE)) {
if (Configuration.GENERATE_WILD_RICE.get()) {
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CropPatchGeneration.PATCH_WILD_RICE);
}
}

if (climate.temperature >= 1.0F) {
if (Configuration.GENERATE_WILD_TOMATOES.get()) {
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CropPatchGeneration.PATCH_WILD_TOMATOES);
}
}

if (climate.temperature > 0.3F && climate.temperature < 1.0F) {
if (Configuration.GENERATE_WILD_CARROTS.get()) {
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CropPatchGeneration.PATCH_WILD_CARROTS);
}
if (Configuration.GENERATE_WILD_ONIONS.get()) {
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CropPatchGeneration.PATCH_WILD_ONIONS);
}
}

if (climate.temperature > 0.0F && climate.temperature <= 0.3F) {
if (Configuration.GENERATE_WILD_POTATOES.get()) {
builder.withFeature(GenerationStage.Decoration.VEGETAL_DECORATION, CropPatchGeneration.PATCH_WILD_POTATOES);
}
}
}

@SubscribeEvent
Expand Down
Loading