Skip to content

Commit

Permalink
added configs
Browse files Browse the repository at this point in the history
  • Loading branch information
NewJumper committed Dec 8, 2023
1 parent e3b56fa commit 1586d85
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/main/java/com/kyanite/deeperdarker/DeeperDarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.kyanite.deeperdarker.datagen.data.loot.DDLootModifierProvider;
import com.kyanite.deeperdarker.datagen.data.loot.DDLootTableProvider;
import com.kyanite.deeperdarker.util.DDCreativeTab;
import com.kyanite.deeperdarker.util.DeeperDarkerConfig;
import com.kyanite.deeperdarker.world.DDFeatures;
import com.kyanite.deeperdarker.world.otherside.OthersideDimension;
import net.minecraft.client.model.BoatModel;
Expand Down Expand Up @@ -52,7 +53,9 @@
import net.minecraftforge.event.level.BlockEvent;
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.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
Expand Down Expand Up @@ -86,6 +89,8 @@ public DeeperDarker() {
eventBus.addListener(this::generateData);
eventBus.addListener(this::registerAttributes);
eventBus.addListener(this::registerSpawnPlacements);

ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, DeeperDarkerConfig.SPEC);
}

private void commonSetup(FMLCommonSetupEvent event) {
Expand Down Expand Up @@ -147,8 +152,8 @@ public static void breakEvent(final BlockEvent.BreakEvent event) {

if(event.getLevel() instanceof ServerLevel level) {
RandomSource random = level.getRandom();
if(random.nextFloat() < 0.16f) {
if(random.nextFloat() < 0.6875f) {
if(random.nextDouble() < DeeperDarkerConfig.fakeVaseChance) {
if(random.nextDouble() < 1 - DeeperDarkerConfig.stalkerSpawnChance) {
for(int i = 0; i < random.nextInt(1, 4); i++) {
DDEntities.SCULK_LEECH.get().spawn(level, event.getPos(), MobSpawnType.TRIGGERED);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.kyanite.deeperdarker.content.items;

import com.kyanite.deeperdarker.content.DDBlocks;
import com.kyanite.deeperdarker.util.DeeperDarkerConfig;
import com.kyanite.deeperdarker.world.otherside.OthersideDimension;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
Expand Down Expand Up @@ -38,7 +39,7 @@ public InteractionResult useOn(UseOnContext pContext) {

@Override
public void inventoryTick(ItemStack pStack, Level pLevel, Entity pEntity, int pSlotId, boolean pIsSelected) {
if(RandomSource.create().nextFloat() < 0.012f) {
if(DeeperDarkerConfig.wardenHeartPulses && RandomSource.create().nextFloat() < 0.012f) {
pEntity.playSound(SoundEvents.WARDEN_HEARTBEAT, 1.7f, 1f);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.kyanite.deeperdarker.util;

import com.kyanite.deeperdarker.DeeperDarker;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.config.ModConfigEvent;

@Mod.EventBusSubscriber(modid = DeeperDarker.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class DeeperDarkerConfig {
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();

private static final ForgeConfigSpec.BooleanValue WARDEN_HEART_PULSES = BUILDER.comment("Heart of the Deep beats like a heart", "Default: true").define("wardenHeartPulses", true);
private static final ForgeConfigSpec.DoubleValue FAKE_VASE_CHANCE = BUILDER.comment("Chance of a vase being fake", "Default: 0.16").defineInRange("fakeVaseChance", 0.16, 0, 1);
private static final ForgeConfigSpec.DoubleValue STALKER_SPAWN_CHANCE = BUILDER.comment("Chance of a Stalker spawning when a fake vase is broken", "Default: 0.3125").defineInRange("stalkerSpawnChance", 0.3125, 0, 1);

public static final ForgeConfigSpec SPEC = BUILDER.build();
public static boolean wardenHeartPulses;
public static double fakeVaseChance;
public static double stalkerSpawnChance;

@SubscribeEvent
public static void onLoad(final ModConfigEvent event) {
wardenHeartPulses = WARDEN_HEART_PULSES.get();
fakeVaseChance = FAKE_VASE_CHANCE.get();
stalkerSpawnChance = STALKER_SPAWN_CHANCE.get();
}
}

0 comments on commit 1586d85

Please sign in to comment.