Implement Config
This commit is contained in:
@@ -11,7 +11,9 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
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.FMLCommonSetupEvent;
|
||||
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
||||
import org.slf4j.Logger;
|
||||
@@ -29,6 +31,8 @@ public class AscendMindMotion {
|
||||
MinecraftForge.EVENT_BUS.register(PlayerTickHandler.class);
|
||||
MinecraftForge.EVENT_BUS.register(CombatEvents.class);
|
||||
LOGGER.info("Ascend: Mind and Motion initialized!");
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.CLIENT, ConfigMM.CLIENT_SPEC);
|
||||
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigMM.COMMON_SPEC);
|
||||
}
|
||||
|
||||
private void commonSetup(final FMLCommonSetupEvent event) {
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package net.fretux.mindmotion;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraftforge.common.ForgeConfigSpec;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.event.config.ModConfigEvent;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mod.EventBusSubscriber(modid = AscendMindMotion.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public class Config
|
||||
{
|
||||
private static final ForgeConfigSpec.Builder BUILDER = new ForgeConfigSpec.Builder();
|
||||
|
||||
private static final ForgeConfigSpec.BooleanValue LOG_DIRT_BLOCK = BUILDER
|
||||
.comment("Whether to log the dirt block on common setup")
|
||||
.define("logDirtBlock", true);
|
||||
|
||||
private static final ForgeConfigSpec.IntValue MAGIC_NUMBER = BUILDER
|
||||
.comment("A magic number")
|
||||
.defineInRange("magicNumber", 42, 0, Integer.MAX_VALUE);
|
||||
|
||||
public static final ForgeConfigSpec.ConfigValue<String> MAGIC_NUMBER_INTRODUCTION = BUILDER
|
||||
.comment("What you want the introduction message to be for the magic number")
|
||||
.define("magicNumberIntroduction", "The magic number is... ");
|
||||
|
||||
private static final ForgeConfigSpec.ConfigValue<List<? extends String>> ITEM_STRINGS = BUILDER
|
||||
.comment("A list of items to log on common setup.")
|
||||
.defineListAllowEmpty("items", List.of("minecraft:iron_ingot"), Config::validateItemName);
|
||||
|
||||
static final ForgeConfigSpec SPEC = BUILDER.build();
|
||||
|
||||
public static boolean logDirtBlock;
|
||||
public static int magicNumber;
|
||||
public static String magicNumberIntroduction;
|
||||
public static Set<Item> items;
|
||||
|
||||
private static boolean validateItemName(final Object obj)
|
||||
{
|
||||
return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName));
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
static void onLoad(final ModConfigEvent event)
|
||||
{
|
||||
logDirtBlock = LOG_DIRT_BLOCK.get();
|
||||
magicNumber = MAGIC_NUMBER.get();
|
||||
magicNumberIntroduction = MAGIC_NUMBER_INTRODUCTION.get();
|
||||
items = ITEM_STRINGS.get().stream()
|
||||
.map(itemName -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package net.fretux.mindmotion;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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 = AscendMindMotion.MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
|
||||
public final class ConfigMM {
|
||||
public static final ForgeConfigSpec CLIENT_SPEC;
|
||||
public static final Client CLIENT;
|
||||
public static final ForgeConfigSpec COMMON_SPEC;
|
||||
public static final Common COMMON;
|
||||
|
||||
static {
|
||||
ForgeConfigSpec.Builder clientBuilder = new ForgeConfigSpec.Builder();
|
||||
ForgeConfigSpec.Builder commonBuilder = new ForgeConfigSpec.Builder();
|
||||
|
||||
CLIENT = new Client(clientBuilder);
|
||||
CLIENT_SPEC = clientBuilder.build();
|
||||
|
||||
COMMON = new Common(commonBuilder);
|
||||
COMMON_SPEC = commonBuilder.build();
|
||||
}
|
||||
|
||||
public static class Client {
|
||||
public final ForgeConfigSpec.BooleanValue DISABLE_SHADERS;
|
||||
public final ForgeConfigSpec.DoubleValue FLASH_STRENGTH_MULTIPLIER;
|
||||
public final ForgeConfigSpec.DoubleValue SANITY_DESAT_MULTIPLIER;
|
||||
|
||||
Client(ForgeConfigSpec.Builder b) {
|
||||
b.push("visual");
|
||||
|
||||
DISABLE_SHADERS = b
|
||||
.comment("Disable all screen-space effects for accessibility / epilepsy.")
|
||||
.define("disableShaders", false);
|
||||
|
||||
FLASH_STRENGTH_MULTIPLIER = b
|
||||
.comment("Global multiplier for white/black insanity flashes (0 = off).")
|
||||
.defineInRange("flashStrengthMultiplier", 0.8, 0.0, 2.0);
|
||||
|
||||
SANITY_DESAT_MULTIPLIER = b
|
||||
.comment("Intensity of desaturation from low sanity.")
|
||||
.defineInRange("sanityDesaturationMultiplier", 1.0, 0.0, 3.0);
|
||||
|
||||
b.pop();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Common {
|
||||
public final ForgeConfigSpec.DoubleValue BASE_SANITY_REGEN_LIGHT;
|
||||
public final ForgeConfigSpec.DoubleValue BASE_SANITY_DECAY_DARK;
|
||||
public final ForgeConfigSpec.BooleanValue ENABLE_LOW_SANITY_SOUNDS;
|
||||
public final ForgeConfigSpec.DoubleValue SCRATCHING_CHANCE;
|
||||
public final ForgeConfigSpec.DoubleValue PANIC_CHANCE;
|
||||
public final ForgeConfigSpec.IntValue TEMPO_DECAY_DELAY;
|
||||
public final ForgeConfigSpec.IntValue VENT_COST;
|
||||
public final ForgeConfigSpec.IntValue TEMPO_PER_MANA_REGEN_PERCENT;
|
||||
|
||||
Common(ForgeConfigSpec.Builder b) {
|
||||
b.push("sanity");
|
||||
|
||||
BASE_SANITY_REGEN_LIGHT = b
|
||||
.comment("Sanity gained per tick in bright light.")
|
||||
.defineInRange("sanityRegenLight", 0.03, 0.0, 1.0);
|
||||
|
||||
BASE_SANITY_DECAY_DARK = b
|
||||
.comment("Sanity lost per tick in darkness.")
|
||||
.defineInRange("sanityDecayDark", 0.02, 0.0, 1.0);
|
||||
|
||||
ENABLE_LOW_SANITY_SOUNDS = b
|
||||
.comment("Enable creepy noises when sanity is low.")
|
||||
.define("enableLowSanitySounds", true);
|
||||
|
||||
b.pop().push("insanity");
|
||||
|
||||
SCRATCHING_CHANCE = b
|
||||
.comment("Base chance per sanity tick to trigger 'scratching' at low sanity.")
|
||||
.defineInRange("scratchingChance", 0.02, 0.0, 1.0);
|
||||
|
||||
PANIC_CHANCE = b
|
||||
.comment("Base chance per sanity tick to trigger panic at low sanity.")
|
||||
.defineInRange("panicChance", 0.015, 0.0, 1.0);
|
||||
|
||||
b.pop().push("tempo");
|
||||
|
||||
TEMPO_DECAY_DELAY = b
|
||||
.comment("Ticks without combat before tempo begins to decay.")
|
||||
.defineInRange("tempoDecayDelay", 100, 0, 20000);
|
||||
|
||||
VENT_COST = b
|
||||
.comment("Tempo required to use the Vent ability.")
|
||||
.defineInRange("ventCost", 40, 1, 1000);
|
||||
|
||||
TEMPO_PER_MANA_REGEN_PERCENT = b
|
||||
.comment("How many tempo = 1% bonus mana regen with Iron's Spellbooks.")
|
||||
.defineInRange("tempoPerManaRegenPercent", 5, 1, 100);
|
||||
|
||||
b.pop();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onLoad(ModConfigEvent.Loading e) {
|
||||
System.out.println("MindMotion config loaded: " + e.getConfig().getModId());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onReload(ModConfigEvent.Reloading e) {
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.fretux.mindmotion.client.effects;
|
||||
|
||||
import io.redspace.ironsspellbooks.api.registry.AttributeRegistry;
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.minecraft.world.entity.ai.attributes.Attribute;
|
||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||
@@ -11,7 +12,10 @@ import net.minecraftforge.fml.ModList;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class IronsSpellbooksCompatMM {
|
||||
public static final double TEMPO_PER_PERCENT = 3;
|
||||
public static int getTempoPerPercent() {
|
||||
return ConfigMM.COMMON.TEMPO_PER_MANA_REGEN_PERCENT.get();
|
||||
}
|
||||
|
||||
private static final UUID TEMPO_MANA_REGEN_UUID =
|
||||
UUID.fromString("de4f16ad-73b3-4b99-bf77-44c9878222aa");
|
||||
|
||||
@@ -37,7 +41,7 @@ public final class IronsSpellbooksCompatMM {
|
||||
if (tempo <= 0) {
|
||||
return;
|
||||
}
|
||||
double bonusPercent = (double) tempo / TEMPO_PER_PERCENT;
|
||||
double bonusPercent = (double) tempo / getTempoPerPercent();
|
||||
double multiplier = bonusPercent / 100.0;
|
||||
inst.addTransientModifier(new AttributeModifier(
|
||||
TEMPO_MANA_REGEN_UUID,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.fretux.mindmotion.client.effects;
|
||||
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.client.ClientData;
|
||||
import net.fretux.mindmotion.client.shader.VentShaderHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -37,8 +38,15 @@ public class SanityShaderHandler {
|
||||
|
||||
@SubscribeEvent
|
||||
public static void onRenderWorld(RenderLevelStageEvent event) {
|
||||
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_LEVEL) return;
|
||||
Minecraft mc = Minecraft.getInstance();
|
||||
if (ConfigMM.CLIENT.DISABLE_SHADERS.get()) {
|
||||
if (mc.gameRenderer.currentEffect() != null)
|
||||
mc.gameRenderer.shutdownEffect();
|
||||
return;
|
||||
}
|
||||
float flashMultiplier = ConfigMM.CLIENT.FLASH_STRENGTH_MULTIPLIER.get().floatValue();
|
||||
float desatMultiplier = ConfigMM.CLIENT.SANITY_DESAT_MULTIPLIER.get().floatValue();
|
||||
if (event.getStage() != RenderLevelStageEvent.Stage.AFTER_LEVEL) return;
|
||||
if (mc.player == null || mc.level == null) return;
|
||||
float sanity = ClientData.SANITY;
|
||||
float insanity = ClientData.INSANITY;
|
||||
@@ -75,7 +83,7 @@ public class SanityShaderHandler {
|
||||
EffectInstance effect = pass.getEffect();
|
||||
if (effect == null) continue;
|
||||
var uDesat = effect.getUniform("Desat");
|
||||
if (uDesat != null) uDesat.set(currentStrength);
|
||||
if (uDesat != null) uDesat.set(currentStrength * desatMultiplier);
|
||||
float blur = 0f;
|
||||
float vig = 0f;
|
||||
float fog = 0f;
|
||||
@@ -94,6 +102,7 @@ public class SanityShaderHandler {
|
||||
flash = Math.min(flash, 1f);
|
||||
}
|
||||
var uFlash = effect.getUniform("FlashStrength");
|
||||
flash *= flashMultiplier;
|
||||
if (uFlash != null) uFlash.set(flash);
|
||||
blur += insanityPct * 0.25f;
|
||||
vig += insanityPct * 0.35f;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.fretux.mindmotion.event;
|
||||
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.compat.AscendCompat;
|
||||
import net.fretux.mindmotion.network.ModMessages;
|
||||
import net.fretux.mindmotion.network.SyncStatsS2CPacket;
|
||||
@@ -25,7 +26,6 @@ public class PlayerTickHandler {
|
||||
|
||||
private static final int SANITY_TICK_INTERVAL = 20;
|
||||
private static final int TEMPO_TICK_INTERVAL = 15;
|
||||
private static final int COMBAT_DECAY_DELAY = 100;
|
||||
private static final Map<UUID, Integer> lastCombatTick = new ConcurrentHashMap<>();
|
||||
private static final Map<UUID, Integer> insanityDamageTicks = new ConcurrentHashMap<>();
|
||||
private static final Map<UUID, Integer> lowSanitySoundCooldown = new ConcurrentHashMap<>();
|
||||
@@ -77,7 +77,7 @@ public class PlayerTickHandler {
|
||||
boolean sleeping = player.isSleeping();
|
||||
boolean inLight = player.level().getMaxLocalRawBrightness(player.blockPosition()) > 12;
|
||||
boolean nearTorch = player.level().getBlockState(player.blockPosition().above()).is(Blocks.TORCH);
|
||||
if (inDark) delta -= 0.02f;
|
||||
if (inDark) delta -= ConfigMM.COMMON.BASE_SANITY_DECAY_DARK.get().floatValue();
|
||||
if (inRain) delta -= 0.04f;
|
||||
if (isHungry) delta -= 0.06f;
|
||||
if (nearLava) delta -= 0.05f;
|
||||
@@ -108,7 +108,7 @@ public class PlayerTickHandler {
|
||||
e -> e instanceof net.minecraft.world.entity.Mob && !(e instanceof net.minecraft.world.entity.animal.Animal)
|
||||
).size();
|
||||
delta -= hostileCount * 0.005f;
|
||||
if (inLight) delta += 0.03f;
|
||||
if (inLight) delta += ConfigMM.COMMON.BASE_SANITY_REGEN_LIGHT.get().floatValue();
|
||||
if (nearTorch) delta += 0.05f;
|
||||
if (sleeping) delta += 0.25f;
|
||||
if (player.getUseItem() != null && player.getUseItem().isEdible()) delta += 0.05f;
|
||||
@@ -161,22 +161,22 @@ public class PlayerTickHandler {
|
||||
if (percent <= 70 && Math.random() < 0.03) {
|
||||
applyShiver(player);
|
||||
}
|
||||
if (percent <= 50 && Math.random() < 0.015) {
|
||||
applyPanic(player);
|
||||
}
|
||||
if (percent <= 10 && Math.random() < 0.02) {
|
||||
if (percent <= 10 && Math.random() < ConfigMM.COMMON.SCRATCHING_CHANCE.get()) {
|
||||
applyScratching(player);
|
||||
}
|
||||
if (percent <= 50 && Math.random() < ConfigMM.COMMON.PANIC_CHANCE.get()) {
|
||||
applyPanic(player);
|
||||
}
|
||||
float insanityPercent = (insanity / sanity.getMaxSanity()) * 100f;
|
||||
if (insanityPercent > 0) {
|
||||
if (insanityPercent > 60 && Math.random() < 0.02) {
|
||||
if (insanityPercent > 60 && Math.random() < ConfigMM.COMMON.PANIC_CHANCE.get()) {
|
||||
applyPanic(player);
|
||||
}
|
||||
if (insanityPercent > 90 && Math.random() < 0.05) {
|
||||
if (insanityPercent > 90 && Math.random() < ConfigMM.COMMON.SCRATCHING_CHANCE.get()) {
|
||||
applyScratching(player);
|
||||
}
|
||||
}
|
||||
if (percent <= 30f) {
|
||||
if (ConfigMM.COMMON.ENABLE_LOW_SANITY_SOUNDS.get() && percent <= 30f) {
|
||||
UUID id = player.getUUID();
|
||||
int cd = lowSanitySoundCooldown.getOrDefault(id, 0) - SANITY_TICK_INTERVAL;
|
||||
if (cd <= 0) {
|
||||
@@ -200,7 +200,7 @@ public class PlayerTickHandler {
|
||||
int value = tempo.getTempo();
|
||||
int lastCombat = lastCombatTick.getOrDefault(player.getUUID(), -10000);
|
||||
int ticksSinceCombat = currentTick - lastCombat;
|
||||
if (ticksSinceCombat > COMBAT_DECAY_DELAY && value > 0) {
|
||||
if (ticksSinceCombat > ConfigMM.COMMON.TEMPO_DECAY_DELAY.get()) {
|
||||
tempo.setTempo(value - 1);
|
||||
}
|
||||
applyTempoToManaRegen(player, tempo.getTempo());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.fretux.mindmotion.network;
|
||||
|
||||
import net.fretux.mindmotion.ConfigMM;
|
||||
import net.fretux.mindmotion.event.VentHandler;
|
||||
import net.fretux.mindmotion.player.PlayerCapabilityProvider;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@@ -22,10 +23,11 @@ public class VentPacket {
|
||||
ctx.get().enqueueWork(() -> {
|
||||
ServerPlayer player = ctx.get().getSender();
|
||||
if (player == null) return;
|
||||
int ventCost = ConfigMM.COMMON.VENT_COST.get();
|
||||
player.getCapability(PlayerCapabilityProvider.TEMPO).ifPresent(tempo -> {
|
||||
if (tempo.getTempo() < 40) return;
|
||||
if (tempo.getTempo() < ventCost) return;
|
||||
if (tempo.getVentCooldown() > 0) return;
|
||||
tempo.setTempo(tempo.getTempo() - 40);
|
||||
tempo.setTempo(tempo.getTempo() - ConfigMM.COMMON.VENT_COST.get());
|
||||
tempo.setVentCooldown(20 * 15);
|
||||
VentHandler.performVent(player);
|
||||
player.level().playSound(
|
||||
|
||||
Reference in New Issue
Block a user