Advertisement
Guest User

Untitled

a guest
Oct 6th, 2021
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.53 KB | None | 0 0
  1. package net.usernaem.potsnstuff.core.config;
  2.  
  3.  
  4. import java.io.File;
  5.  
  6. import com.electronwill.nightconfig.core.CommentedConfig;
  7. import com.electronwill.nightconfig.core.file.CommentedFileConfig;
  8. import com.electronwill.nightconfig.core.io.WritingMode;
  9.  
  10. import net.minecraftforge.common.ForgeConfigSpec;
  11. import net.minecraftforge.eventbus.api.SubscribeEvent;
  12. import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
  13. import net.minecraftforge.fml.config.ModConfig;
  14. import net.usernaem.potsnstuff.PotsNStuff;
  15.  
  16. @EventBusSubscriber(modid = PotsNStuff.MOD_ID_STRING, bus = EventBusSubscriber.Bus.MOD)
  17. public class PnsConfig {
  18.     public static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
  19.     public static final ForgeConfigSpec SPEC;
  20.    
  21.    
  22.     public static final ForgeConfigSpec.BooleanValue fuze_is_craftable;
  23.     public static final ForgeConfigSpec.ConfigValue<Integer> fuze_normal_time;
  24.     public static final ForgeConfigSpec.ConfigValue<Integer> fuze_normal_effect;
  25.     public static final ForgeConfigSpec.ConfigValue<Integer> fuze_strong_effect;
  26.     public static final ForgeConfigSpec.ConfigValue<Boolean> grounding_is_craftable;
  27.     public static final ForgeConfigSpec.ConfigValue<Integer> grounding_normal_time;
  28.     public static final ForgeConfigSpec.ConfigValue<Integer> grounding_long_time;
  29.     public static final ForgeConfigSpec.ConfigValue<Boolean> recall_is_craftable;
  30.     public static final ForgeConfigSpec.ConfigValue<Integer> recall_normal_time;
  31.     public static final ForgeConfigSpec.ConfigValue<Integer> recall_long_time;
  32.     public static final ForgeConfigSpec.ConfigValue<Boolean> photosynthesis_is_craftable;
  33.     public static final ForgeConfigSpec.ConfigValue<Integer> photosynthesis_normal_time;
  34.     public static final ForgeConfigSpec.ConfigValue<Integer> photosynthesis_long_time;
  35.     public static final ForgeConfigSpec.ConfigValue<Boolean> inferno_is_craftable;
  36.     public static final ForgeConfigSpec.ConfigValue<Integer> inferno_normal_time;
  37.     public static final ForgeConfigSpec.ConfigValue<Integer> inferno_long_time;
  38.     public static final ForgeConfigSpec.ConfigValue<Boolean> absorption_is_craftable;
  39.     public static final ForgeConfigSpec.ConfigValue<Integer> absorption_normal_time;
  40.     public static final ForgeConfigSpec.ConfigValue<Integer> absorption_long_time;
  41.     public static final ForgeConfigSpec.ConfigValue<Integer> absorption_normal_effect;
  42.     public static final ForgeConfigSpec.ConfigValue<Integer> absorption_strong_effect;
  43.     public static final ForgeConfigSpec.ConfigValue<Boolean> health_boost_is_craftable;
  44.     public static final ForgeConfigSpec.ConfigValue<Integer> health_boost_normal_time;
  45.     public static final ForgeConfigSpec.ConfigValue<Integer> health_boost_long_time;
  46.     public static final ForgeConfigSpec.ConfigValue<Integer> health_boost_normal_effect;
  47.     public static final ForgeConfigSpec.ConfigValue<Integer> health_boost_strong_effect;
  48.     public static final ForgeConfigSpec.ConfigValue<Boolean> haste_is_craftable;
  49.     public static final ForgeConfigSpec.ConfigValue<Integer> haste_normal_time;
  50.     public static final ForgeConfigSpec.ConfigValue<Integer> haste_long_time;
  51.     public static final ForgeConfigSpec.ConfigValue<Integer> haste_normal_effect;
  52.     public static final ForgeConfigSpec.ConfigValue<Integer> haste_strong_effect;
  53.     public static final ForgeConfigSpec.ConfigValue<Boolean> iron_skin_is_craftable;
  54.     public static final ForgeConfigSpec.ConfigValue<Integer> iron_skin_normal_time;
  55.     public static final ForgeConfigSpec.ConfigValue<Integer> iron_skin_long_time;
  56.     public static final ForgeConfigSpec.ConfigValue<Boolean> diamond_skin_is_craftable;
  57.     public static final ForgeConfigSpec.ConfigValue<Integer> diamond_skin_normal_time;
  58.     public static final ForgeConfigSpec.ConfigValue<Integer> diamond_skin_long_time;
  59.     public static final ForgeConfigSpec.ConfigValue<Boolean> reflect_is_craftable;
  60.     public static final ForgeConfigSpec.ConfigValue<Integer> reflect_normal_time;
  61.     public static final ForgeConfigSpec.ConfigValue<Integer> reflect_long_time;
  62.     public static final ForgeConfigSpec.ConfigValue<Boolean> blast_is_craftable;
  63.     public static final ForgeConfigSpec.ConfigValue<Integer> blast_normal_time;
  64.     public static final ForgeConfigSpec.ConfigValue<Integer> blast_long_time;
  65.     public static final ForgeConfigSpec.ConfigValue<Boolean> undeath_is_craftable;
  66.     public static final ForgeConfigSpec.ConfigValue<Integer> undeath_normal_time;
  67.     public static final ForgeConfigSpec.ConfigValue<Integer> undeath_long_time;
  68.     public static final ForgeConfigSpec.ConfigValue<Boolean> frail_is_craftable;
  69.     public static final ForgeConfigSpec.ConfigValue<Integer> frail_normal_time;
  70.     public static final ForgeConfigSpec.ConfigValue<Integer> frail_long_time;
  71.     public static final ForgeConfigSpec.ConfigValue<Double> frail_multiplier;
  72.     public static final ForgeConfigSpec.ConfigValue<Boolean> flight_is_craftable;
  73.     public static final ForgeConfigSpec.ConfigValue<Integer> flight_normal_time;
  74.     public static final ForgeConfigSpec.ConfigValue<Integer> flight_long_time;
  75.     public static final ForgeConfigSpec.ConfigValue<Boolean> aqua_is_craftable;
  76.     public static final ForgeConfigSpec.ConfigValue<Boolean> hell_touch_is_craftable;
  77.     public static final ForgeConfigSpec.ConfigValue<Boolean> clense_is_craftable;
  78.     public static final ForgeConfigSpec.ConfigValue<Boolean> cure_is_craftable;
  79.     public static final ForgeConfigSpec.ConfigValue<Boolean> nullify_is_craftable;
  80.     public static final ForgeConfigSpec.ConfigValue<Boolean> launching_is_craftable;
  81.     public static final ForgeConfigSpec.ConfigValue<Boolean> lightning_is_craftable;
  82.        
  83.     static {
  84.         BUILDER.push("Set up which potions can be crafted");
  85.         fuze_is_craftable = BUILDER.define("fuze potion", true);
  86.         grounding_is_craftable = BUILDER.define("grounding potion", true);
  87.         recall_is_craftable = BUILDER.define("recall potion", true);
  88.         photosynthesis_is_craftable = BUILDER.define("photosynthesis potion", true);
  89.         inferno_is_craftable = BUILDER.define("inferno potion", true);
  90.         absorption_is_craftable = BUILDER.define("absorption potion", true);
  91.         health_boost_is_craftable = BUILDER.define("health boost potion", true);
  92.         haste_is_craftable = BUILDER.define("haste potion", true);
  93.         iron_skin_is_craftable = BUILDER.define("iron skin potion", true);
  94.         diamond_skin_is_craftable = BUILDER.define("diamond skin potion", true);
  95.         reflect_is_craftable = BUILDER.define("projectile immunity potion", true);
  96.         blast_is_craftable = BUILDER.define("blast immunity potion", true);
  97.         undeath_is_craftable = BUILDER.define("undying potion", true);
  98.         frail_is_craftable = BUILDER.define("frailness potion", true);
  99.         flight_is_craftable = BUILDER.define("flight potion", true);
  100.         aqua_is_craftable = BUILDER.define("aqua potion", true);
  101.         hell_touch_is_craftable = BUILDER.define("hells touch potion", true);
  102.         clense_is_craftable = BUILDER.define("clense potion", true);
  103.         cure_is_craftable = BUILDER.comment("clense must be enabled for cure effect").define("cure potion", true);
  104.         nullify_is_craftable = BUILDER.comment("clense must be enabled for nullify effect").define("nullify potion", true);
  105.         launching_is_craftable = BUILDER.define("launching potion", true);
  106.         lightning_is_craftable = BUILDER.define("lightning in a bottle", true);
  107.         BUILDER.pop();
  108.        
  109.         BUILDER.comment("effect level range is [0-5]. Time is set as 100 = 5 seconds").push("values");
  110.         BUILDER.push("fuze effect");
  111.         fuze_normal_time = BUILDER.define("fuze normal time", 400);
  112.         fuze_normal_effect = BUILDER.define("fuze normal level", 2);
  113.         fuze_strong_effect = BUILDER.define("fuze strong level", 5);
  114.         BUILDER.pop();
  115.         BUILDER.push("grounding effect");
  116.         grounding_normal_time = BUILDER.define("grounding normal time", 600);
  117.         grounding_long_time = BUILDER.define("grounding long time", 1200);
  118.         BUILDER.pop();
  119.         BUILDER.push("recall effect");
  120.         recall_normal_time = BUILDER.define("recall normal time", 600);
  121.         recall_long_time = BUILDER.define("recall long time", 6000);
  122.         BUILDER.pop();
  123.         BUILDER.push("photosynthesis effect");
  124.         photosynthesis_normal_time = BUILDER.define("photosynthesis normal time", 1200);
  125.         photosynthesis_long_time = BUILDER.define("photosynthesis long time", 6000);
  126.         BUILDER.pop();
  127.         BUILDER.push("inferno effect");
  128.         inferno_normal_time = BUILDER.define("inferno normal time", 400);
  129.         inferno_long_time = BUILDER.define("inferno long time", 800);
  130.         BUILDER.pop();
  131.         BUILDER.push("absorption effect");
  132.         absorption_normal_time = BUILDER.define("absorption normal time", 1200);
  133.         absorption_long_time = BUILDER.define("absorption long time", 12000);
  134.         absorption_normal_effect = BUILDER.define("absorption normal level", 2);
  135.         absorption_strong_effect = BUILDER.define("absorption strong level", 4);
  136.         BUILDER.pop();
  137.         BUILDER.push("health boost effect");
  138.         health_boost_normal_time = BUILDER.define("health boost normal time", 1200);
  139.         health_boost_long_time = BUILDER.define("health boost long time", 12000);
  140.         health_boost_normal_effect = BUILDER.define("health boost normal level", 2);
  141.         health_boost_strong_effect = BUILDER.define("health boost strong level", 4);
  142.         BUILDER.pop();
  143.         BUILDER.push("haste effect");
  144.         haste_normal_time = BUILDER.define("haste normal time", 1200);
  145.         haste_long_time = BUILDER.define("haste long time", 12000);
  146.         haste_normal_effect = BUILDER.define("haste normal level", 2);
  147.         haste_strong_effect = BUILDER.define("haste strong level", 4);
  148.         BUILDER.pop();
  149.         BUILDER.push("iron skin effect");
  150.         iron_skin_normal_time = BUILDER.define("iron skin normal time", 1200);
  151.         iron_skin_long_time = BUILDER.define("iron skin long time", 12000);
  152.         BUILDER.pop();
  153.         BUILDER.push("diamond skin effect");
  154.         diamond_skin_normal_time = BUILDER.define("diamond skin normal time", 1200);
  155.         diamond_skin_long_time = BUILDER.define("diamond skin long time", 12000);
  156.         BUILDER.pop();
  157.         BUILDER.push("projectile immunity effect");
  158.         reflect_normal_time = BUILDER.define("reflect normal time", 1200);
  159.         reflect_long_time = BUILDER.define("reflect long time", 6000);
  160.         BUILDER.pop();
  161.         BUILDER.push("blast immunity effect");
  162.         blast_normal_time = BUILDER.define("blast normal time", 1200);
  163.         blast_long_time = BUILDER.define("blast long time", 6000);
  164.         BUILDER.pop();
  165.         BUILDER.push("undying effect");
  166.         undeath_normal_time = BUILDER.define("undying normal time", 1200);
  167.         undeath_long_time = BUILDER.define("undying long time", 12000);
  168.         BUILDER.pop();
  169.         BUILDER.push("frailness effect");
  170.         frail_normal_time = BUILDER.define("frailness normal time", 600);
  171.         frail_long_time = BUILDER.define("frailness long time", 1200);
  172.         frail_multiplier = BUILDER.comment("multiplier for damage taken while under frailness effect").define("frailness multiplier", 2.0);
  173.         BUILDER.pop();
  174.         BUILDER.push("flight effect");
  175.         flight_normal_time = BUILDER.define("flight normal time", 600);
  176.         flight_long_time = BUILDER.define("flight long time", 1200);
  177.         BUILDER.pop();
  178.         BUILDER.pop();
  179.        
  180.         SPEC = BUILDER.build();
  181.     }
  182.  
  183.  
  184.     public static double frailMultiplier;
  185.     @SubscribeEvent
  186.     public static void onModConfigEvent(final ModConfig.ModConfigEvent configEvent) {
  187.         if (configEvent.getConfig().getSpec() == PnsConfig.SPEC) {
  188.             bakeConfig();
  189.         }
  190.     }
  191.  
  192.     public static void bakeConfig() {
  193.         PnsConfig.frailMultiplier = PnsConfig.frail_multiplier.get();
  194.     }
  195.    
  196.  
  197.     public static void loadConfig(final ForgeConfigSpec config, final String path) {
  198.         final CommentedFileConfig file = (CommentedFileConfig)CommentedFileConfig.builder(new File(path)).preserveInsertionOrder().sync().autosave().writingMode(WritingMode.REPLACE).build();
  199.         file.load();
  200.         config.setConfig((CommentedConfig)file);
  201.        
  202.        
  203.        
  204.        
  205.     }
  206. }
  207.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement