Skip to content

Commit

Permalink
feat: add server config for BioForge recipe unlocking and villager tr…
Browse files Browse the repository at this point in the history
…ades
  • Loading branch information
Elenterius committed Nov 2, 2023
1 parent dd31596 commit 47a8b12
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
26 changes: 26 additions & 0 deletions src/main/java/com/github/elenterius/biomancy/BiomancyConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.github.elenterius.biomancy;

import com.github.elenterius.biomancy.config.ServerConfig;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig;
import org.apache.commons.lang3.tuple.Pair;

public final class BiomancyConfig {

public static final ForgeConfigSpec SERVER_SPECIFICATION;
public static final ServerConfig SERVER;

private BiomancyConfig() {}

static {
Pair<ServerConfig, ForgeConfigSpec> specPair = new ForgeConfigSpec.Builder().configure(ServerConfig::new);
SERVER = specPair.getLeft();
SERVER_SPECIFICATION = specPair.getRight();
}

public static void register(ModLoadingContext modLoadingContext) {
modLoadingContext.registerConfig(ModConfig.Type.SERVER, BiomancyConfig.SERVER_SPECIFICATION);
}

}
3 changes: 3 additions & 0 deletions src/main/java/com/github/elenterius/biomancy/BiomancyMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentInstance;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.RegistryObject;
Expand All @@ -31,6 +32,7 @@ public BiomancyMod() {
GeckoLib.initialize();

IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
ModLoadingContext modLoadingContext = ModLoadingContext.get();

ModBannerPatterns.BANNERS.register(modEventBus);

Expand All @@ -55,6 +57,7 @@ public BiomancyMod() {
ModSoundEvents.SOUND_EVENTS.register(modEventBus);
ModParticleTypes.PARTICLE_TYPES.register(modEventBus);

BiomancyConfig.register(modLoadingContext);
ModsCompatHandler.onBiomancyInit(modEventBus);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.elenterius.biomancy.client.gui;

import com.github.elenterius.biomancy.BiomancyConfig;
import com.github.elenterius.biomancy.crafting.recipe.BioForgeRecipe;
import com.github.elenterius.biomancy.init.ModBioForgeTabs;
import com.github.elenterius.biomancy.init.ModRecipeBookTypes;
Expand Down Expand Up @@ -268,7 +269,7 @@ private static void canCraftRecipe(RecipeCollection recipeCollection, StackedCon

private void updateAndSearchRecipes() {
LocalPlayer player = getPlayer();
boolean isCreativePlayer = player.isCreative() || BioForgeCompat.isRecipeCollectionOverwriteEnabled();
boolean isCreativePlayer = player.isCreative() || !BiomancyConfig.SERVER.doBioForgeRecipeProgression.get() || BioForgeCompat.isRecipeCollectionOverwriteEnabled();

ClientRecipeBook recipeBook = player.getRecipeBook();
List<RecipeCollection> recipesForCategory = recipeBook.getCollection(ModRecipeBookCategories.getRecipeBookCategories(tabs.get(activeTab)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.github.elenterius.biomancy.config;

import net.minecraftforge.common.ForgeConfigSpec;

public class ServerConfig {

public final ForgeConfigSpec.BooleanValue doBioForgeRecipeProgression;
public final ForgeConfigSpec.BooleanValue addTradesToVillagers;
public final ForgeConfigSpec.BooleanValue addTradesToWanderingTrader;

public ServerConfig(ForgeConfigSpec.Builder builder) {
builder.push("recipes");

doBioForgeRecipeProgression = builder
.comment("Determines if the BioForge recipes need to be unlocked to be able to craft them")
.define("doBioForgeRecipeProgression", true);

builder.pop();

builder.push("trades");

addTradesToVillagers = builder
.comment("Determines if villagers will sell biomancy items")
.define("addTradesToVillagers", true);

addTradesToWanderingTrader = builder
.comment("Determines if wandering traders will sell biomancy items")
.define("addTradesToWanderingTrader", true);

builder.pop();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.elenterius.biomancy.init;

import com.github.elenterius.biomancy.BiomancyConfig;
import com.github.elenterius.biomancy.BiomancyMod;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import net.minecraft.world.entity.npc.VillagerProfession;
Expand All @@ -21,6 +22,8 @@ public class ModVillagerTrades {

@SubscribeEvent
public static void onVillagerTrades(final VillagerTradesEvent event) {
if (Boolean.FALSE.equals(BiomancyConfig.SERVER.addTradesToVillagers.get())) return;

if (event.getType() == VillagerProfession.BUTCHER) {
addButcherTrades(event.getTrades());
}
Expand All @@ -31,6 +34,8 @@ else if (event.getType() == VillagerProfession.CLERIC) {

@SubscribeEvent
public static void onWandererTrades(final WandererTradesEvent event) {
if (Boolean.FALSE.equals(BiomancyConfig.SERVER.addTradesToWanderingTrader.get())) return;

List<VillagerTrades.ItemListing> genericTrades = event.getGenericTrades();
genericTrades.add(sellToPlayer(ModItems.EXOTIC_DUST.get(), 4, 2, 16, 5));
genericTrades.add(sellToPlayer(ModItems.FLESH_SPIKE.get(), 2, 16, 5));
Expand Down

0 comments on commit 47a8b12

Please sign in to comment.