Skip to content

Commit

Permalink
add config
Browse files Browse the repository at this point in the history
  • Loading branch information
DerToaster98 committed Apr 3, 2022
1 parent 6b02efa commit 66829c7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import de.dertoaster.crossbowverhaul.config.CrossbowverhaulConfigHolder;
import de.dertoaster.crossbowverhaul.init.ModEnchantments;
import de.dertoaster.crossbowverhaul.init.ModEntityTypes;
import de.dertoaster.crossbowverhaul.init.ModItemProperties;
import de.dertoaster.crossbowverhaul.init.ModItems;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

Expand All @@ -27,6 +30,9 @@ public class CrossbowverhaulMod
public CrossbowverhaulMod() {
IEventBus modbus = FMLJavaModLoadingContext.get().getModEventBus();

//Register config
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CrossbowverhaulConfigHolder.ITEM_CONFIG_SPEC);

//Register items
ModItems.registerToEventBus(modbus);
//Register entities
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package de.dertoaster.crossbowverhaul.config;

import org.apache.commons.lang3.tuple.Pair;

import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.ForgeConfigSpec.ConfigValue;

public class CrossbowverhaulConfigHolder {

public static class ItemConfig {
private static final boolean allowEnchantmentsOnCrossbow = true;
private static final boolean allowEnchantmentsOnNetheriteCrossbow = true;
private static final boolean modifyMultiShotEnchantment = true;

public final ConfigValue<Boolean> coEnchCrossbow;
public final ConfigValue<Boolean> coEnchNetheriteCrossbow;
public final ConfigValue<Boolean> coModMultishot;

public ItemConfig(ForgeConfigSpec.Builder builder) {
builder.push("co-item");

this.coEnchCrossbow = builder
.comment("Enable enchantments on the crossbow")
.defineInRange("Enable enchants on crossbow", allowEnchantmentsOnCrossbow, true, false, Boolean.class);

this.coEnchNetheriteCrossbow = builder
.comment("Enable enchantments on the netherite crossbow")
.defineInRange("Enable enchants on netherite crossbow", allowEnchantmentsOnNetheriteCrossbow, true, false, Boolean.class);

builder.pop();

builder.push("co-ench");

this.coModMultishot = builder
.comment("Allows multishot to go up to five")
.defineInRange("Modify multishot enchantment", modifyMultiShotEnchantment, true, false, Boolean.class);

builder.pop();
}

}

public static final ItemConfig ITEM_CONFIG;
public static final ForgeConfigSpec ITEM_CONFIG_SPEC;

static {
Pair<ItemConfig, ForgeConfigSpec> itemConfigSpecPair = new ForgeConfigSpec.Builder().configure(ItemConfig::new);

ITEM_CONFIG = itemConfigSpecPair.getLeft();
ITEM_CONFIG_SPEC = itemConfigSpecPair.getRight();
}

}

0 comments on commit 66829c7

Please sign in to comment.