Skip to content

Commit

Permalink
attempted to use cloth config and cleaned up some config code
Browse files Browse the repository at this point in the history
  • Loading branch information
lever1209 committed Jan 28, 2024
1 parent 2ecaecb commit 7b48e15
Show file tree
Hide file tree
Showing 20 changed files with 441 additions and 188 deletions.
11 changes: 11 additions & 0 deletions NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@

wrapper block to contain all perishable light blocks and run custom things on em
^^ make that a library? at the very least include an api to add custom logic on it

protective gear for dogs and horses

suggestions: trade for ink sacs to emeralds

amethyst glow squids phantom membrane conduit

make an advanced config file that contains everything that needs to sync

add button on worlds menu to recalculate all blocks lighting, potentially dangerous with non vanilla, so throw up a warning, this "solves" the lighting artifacts when changing lighting values without needing too much cpu power in game, should only be used when editing these values or when converting world to pandora since all lighting values are cached
create a utility to load all chunks within a world, update all block luminance values with the ones stored in configs

Expand Down
1 change: 1 addition & 0 deletions blockbench/the_witch.bbmodel

Large diffs are not rendered by default.

20 changes: 12 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ repositories {
mavenCentral()

maven { url 'https://maven.terraformersmc.com/releases' }
maven { url "https://maven.shedaniel.me/" }
maven { url 'https://jitpack.io' }
maven { url 'https://maven.gegy.dev' }
// maven { url 'https://maven.isxander.dev/releases' }
// maven { url "https://maven.shedaniel.me/" }
// maven { url 'https://jitpack.io' }
// maven { url 'https://maven.gegy.dev' }
}

dependencies {
Expand All @@ -33,12 +34,15 @@ dependencies {
exclude(group: "net.fabricmc.fabric-api")
}

include modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { // one or the other, most likely spruce
exclude(group: "net.fabricmc.fabric-api")
}
include modApi("dev.lambdaurora:spruceui:${project.spruceui_version}")
// modImplementation("dev.isxander.yacl:yet-another-config-lib-fabric:3.1.0+1.19.4")


// include modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { // one or the other, most likely spruce
// exclude(group: "net.fabricmc.fabric-api")
// }

// include modApi("dev.lambdaurora:spruceui:${project.spruceui_version}")

// apparently this is bundled in fabric loader 15+? check how to use that version instead
include(implementation(annotationProcessor("io.github.llamalad7:mixinextras-fabric:${project.mixinextras_versions}")))

// include modApi("com.github.LlamaLad7:MixinExtras:0.1.0-rc5")
Expand Down
12 changes: 8 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ archives_base_name = pandora

# Dependencies
modmenu_version=4.0.4
slf4j_simple_version=1.7.9 # will crash if updated
# will crash if updated
#slf4j_simple_version=1.7.9
snakeyaml_engine_version=2.4
cloth_config_version=8.2.88
spruceui_version=3.3.3+1.18
architectury_version=5.12.44
# 8.2.88
#cloth_config_version=8.3.103
# https://maven.gegy.dev/dev/lambdaurora/spruceui/
#spruceui_version=4.0.0+1.19
#architectury_version=5.12.44
mixinextras_versions=0.3.5
#yacl_version=2.1.0
28 changes: 14 additions & 14 deletions src/main/java/pkg/deepCurse/pandora/core/Pandora.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,49 @@
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import pkg.deepCurse.pandora.core.util.callbacks.AfterServerPlayerRespawnCallback;
import pkg.deepCurse.pandora.core.util.callbacks.BlockRegisterCallback;
import pkg.deepCurse.pandora.core.util.callbacks.EndServerWorldTickCallback;
import pkg.deepCurse.pandora.core.util.tools.PandoraTools;

public class Pandora implements ModInitializer, PreLaunchEntrypoint {

public static Logger log = LoggerFactory.getLogger(Pandora.class);

@Override
public void onPreLaunch() {
log.info("[Pandora] Running pre launch initializers. . .");
log.info("[Pandora] Running pre launch tasks. . .");

MixinExtrasBootstrap.init();
log.info("[Pandora] Finished pre launch initializers.");

log.info("[Pandora] Finished pre launch tasks.");
}

@Override
public void onInitialize() {

log.info("[Pandora] Initializing mod. . .");

// PandoraRegistry.init();

log.info("[Pandora] Loading and applying config. . .");
PandoraConfig.loadConfig();
log.info("[Pandora] Loaded and applied config.");

registerHooks();
registerCallbacks();

log.info("[Pandora] Finished initializing mod.");

}

public static void registerHooks() {
ServerTickEvents.END_WORLD_TICK.register(new EndServerWorldTickCallback());
public static void registerCallbacks() {
log.info("[Pandora] Registering callbacks.");

ServerTickEvents.END_WORLD_TICK.register(new EndServerWorldTickCallback());
ServerPlayerEvents.AFTER_RESPAWN.register(new AfterServerPlayerRespawnCallback());

// we need both because the mod is not guaranteed to load before other mods, and
// the vanilla registries do not use fabric api
for (Entry<RegistryKey<Block>, Block> entry : Registry.BLOCK.getEntrySet()) {
PandoraTools.overrideLuminance(entry.getKey().getValue(), entry.getValue());
BlockRegisterCallback.overrideLuminance(entry.getKey().getValue(), entry.getValue());
}
RegistryEntryAddedCallback.event(Registry.BLOCK).register((rawId, id, block) -> {
PandoraTools.overrideLuminance(id, block);
});
RegistryEntryAddedCallback.event(Registry.BLOCK).register(new BlockRegisterCallback());

log.info("[Pandora] Finished registering callbacks.");
}

}
115 changes: 81 additions & 34 deletions src/main/java/pkg/deepCurse/pandora/core/PandoraConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,38 +20,70 @@
import net.minecraft.block.BlockState;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d;
import pkg.deepCurse.pandora.core.PandoraConfig.General.BlockLightLevelSettings;
import pkg.deepCurse.pandora.core.util.interfaces.ConditionalToIntFunction;
import pkg.deepCurse.pandora.core.util.tools.CalculateFogFunction;

public class PandoraConfig {

public static class General {
public static class Enabled {
public static boolean EnablePandora = true;
public static boolean EnableCustomFog = true;
public static boolean EnableCustomAI = true;
public static boolean EnableCustomLightmap = true;
public static boolean EnableGrueWards = true;
}

public static boolean IgnoreSkyLight = false;
public static boolean IgnoreMoonPhase = false;

public static int MinimumSafeLightLevel = 5;
public static int MinimumFadeLightLevel = 3;

public static boolean HardcoreAffectsOtherMobs = true;
// public static boolean HardcoreAffectsOtherMobs = true;

public static boolean ResetGamma = true;
public static double GammaValue = 1.0f;

public static boolean GruesAttackInWater = false;
public static boolean GruesEatItems = true;

public static HashMap<Identifier, BlockLightLevelSettings> BlockLightLevelSettings = null;
public static class DifficultySettings {
public static class HardCore {
public static float DamageAmount;
public static short tutorialCount;
public static short tutorialGracePeriod;
public static short GrueMaxTickWait;
public static short GrueMinTickWait;
}

public static class Hard {
public static float DamageAmount;
public static short tutorialCount;
public static short tutorialGracePeriod;
public static short GrueMaxTickWait;
public static short GrueMinTickWait;
}

public static class Normal {
public static float DamageAmount;
public static short tutorialCount;
public static short tutorialGracePeriod;
public static short GrueMaxTickWait;
public static short GrueMinTickWait;
}

public static class Easy {
public static float DamageAmount;
public static short tutorialCount;
public static short tutorialGracePeriod;
public static short GrueMaxTickWait;
public static short GrueMinTickWait;
}

public static class Peaceful {
public static float DamageAmount;
public static short tutorialCount;
public static short tutorialGracePeriod;
public static short GrueMaxTickWait;
public static short GrueMinTickWait;
}
}

public static class BlockLightLevelSettings {
public static HashMap<Identifier, General.BlockLightLevelSettings> CONFIG = null;

public BlockLightLevelSettings(ConditionalToIntFunction<BlockState> level) {
this.LightLevel = level;
Expand All @@ -60,9 +92,8 @@ public BlockLightLevelSettings(ConditionalToIntFunction<BlockState> level) {
public ConditionalToIntFunction<BlockState> LightLevel;
}

public static HashMap<Identifier, DimensionSettings> DimensionSettings = null;

public static class DimensionSettings {
public static HashMap<Identifier, DimensionSettings> CONFIG = null;

public DimensionSettings(CalculateFogFunction fog, boolean infested) {
this.FogLevel = fog;
Expand All @@ -73,29 +104,39 @@ public DimensionSettings(CalculateFogFunction fog, boolean infested) {
public boolean Infested;
}

public static HashMap<Identifier, GrueWardSettings> GrueWards = null;

public static class GrueWardSettings {
public static HashMap<Identifier, GrueWardSettings> CONFIG = null;

public double Potency;

public GrueWardSettings(double potency) {
this.Potency = potency;
}
}

public static HashMap<Identifier, MobSettings> MobSettings = null;

public static class MobSettings {
public static HashMap<Identifier, MobSettings> CONFIG = null;

public double DamageMultiplier;
public boolean FearDarkness; // TODO look into making this a float for the ai weight?
public boolean IsHardcore;

public MobSettings(double damageMultiplier, boolean fearsDarkness) {
public MobSettings(double damageMultiplier, boolean fearsDarkness, boolean isHardcore) {
this.DamageMultiplier = damageMultiplier;
this.FearDarkness = fearsDarkness;
this.IsHardcore = isHardcore;
}
}
}

public static class Enabled {
public static boolean EnablePandora = true;
public static boolean EnableCustomFog = true;
public static boolean EnableCustomAI = true;
public static boolean EnableCustomLightmap = true;
public static boolean EnableGrueWards = true;
}

public class Debug {
public static double FlameLightSourceDecayRate = 1.0f;
public static boolean ForceGruesAlwaysAttack = false;
Expand All @@ -115,12 +156,14 @@ public static File getConfigFile() {
public static void loadConfig() { // TODO write yaml parser to get spans and line numbers, and to add more user
// friendly errors

// log.info("start");
// ASAP stop casting and start parsing!

General.DimensionSettings = new HashMap<>();
General.MobSettings = new HashMap<>();
General.BlockLightLevelSettings = new HashMap<>();
General.GrueWards = new HashMap<>();
log.info("[Pandora] Loading and applying config. . .");

General.DimensionSettings.CONFIG = new HashMap<>();
General.MobSettings.CONFIG = new HashMap<>();
General.BlockLightLevelSettings.CONFIG = new HashMap<>();
General.GrueWardSettings.CONFIG = new HashMap<>();

Load load = new Load(settings);
HashMap<?, ?> yamlHashMap;
Expand Down Expand Up @@ -152,23 +195,23 @@ public static void loadConfig() { // TODO write yaml parser to get spans and lin
ArrayList<?> mobGroups = (ArrayList<?>) general.get("mob group settings");
HashMap<?, ?> debug = (HashMap<?, ?>) yamlHashMap.get("debug settings");

General.Enabled.EnablePandora = (boolean) enabled.get("enable pandora");
General.Enabled.EnableCustomFog = (boolean) enabled.get("enable custom fog");
General.Enabled.EnableCustomAI = (boolean) enabled.get("enable pandora ai");
General.Enabled.EnableCustomLightmap = (boolean) enabled.get("enable light modifications");
General.Enabled.EnableGrueWards = (boolean) enabled.get("enable grue wards");
PandoraConfig.Enabled.EnablePandora = (boolean) enabled.get("enable pandora");
PandoraConfig.Enabled.EnableCustomFog = (boolean) enabled.get("enable custom fog");
PandoraConfig.Enabled.EnableCustomAI = (boolean) enabled.get("enable pandora ai");
PandoraConfig.Enabled.EnableCustomLightmap = (boolean) enabled.get("enable light modifications");
PandoraConfig.Enabled.EnableGrueWards = (boolean) enabled.get("enable grue wards");

General.IgnoreSkyLight = (boolean) general.get("ignore sky light");
General.IgnoreMoonPhase = (boolean) general.get("ignore moon phase");
General.MinimumSafeLightLevel = (int) general.get("minimum safe light level");
General.MinimumFadeLightLevel = (int) general.get("minimum fade light level");
General.HardcoreAffectsOtherMobs = (boolean) general.get("hardcore affects other mobs");
// General.HardcoreAffectsOtherMobs = (boolean) general.get("hardcore affects other mobs");
General.ResetGamma = (boolean) general.get("reset gamma");
General.GammaValue = (double) general.get("gamma value");
General.GruesAttackInWater = (boolean) general.get("grues attack in water");
General.GruesEatItems = (boolean) general.get("grues eat items");

General.BlockLightLevelSettings = new HashMap<>();
General.BlockLightLevelSettings.CONFIG = new HashMap<>();
for (HashMap<String, ?> i : (ArrayList<HashMap<String, ?>>) blockLightSettings) {

if (!i.containsKey("light level")) {
Expand Down Expand Up @@ -197,7 +240,7 @@ public static void loadConfig() { // TODO write yaml parser to get spans and lin
return lightLevel;
};

General.BlockLightLevelSettings.put(id, new BlockLightLevelSettings(conditional_to_int_function));
General.BlockLightLevelSettings.CONFIG.put(id, new General.BlockLightLevelSettings(conditional_to_int_function));
}

for (HashMap<String, ?> dim : (ArrayList<HashMap<String, ?>>) dimensionSettings) {
Expand All @@ -221,7 +264,7 @@ public static void loadConfig() { // TODO write yaml parser to get spans and lin
// + ")");
// }
for (var id : identifiers) {
General.DimensionSettings.put(new Identifier(id), new General.DimensionSettings(
General.DimensionSettings.CONFIG.put(new Identifier(id), new General.DimensionSettings(
(owner, color, sun_angle, oldValue, world, biome_access, sun_height, i, j, k) -> {
final double MIN = 0;
Vec3d result = oldValue;
Expand Down Expand Up @@ -250,18 +293,20 @@ public static void loadConfig() { // TODO write yaml parser to get spans and lin
var potency = (double) i.get("potency");
var ids = (ArrayList<String>) i.get("ids");
for (var id : ids) {
General.GrueWards.put(new Identifier(id), new General.GrueWardSettings(potency));
General.GrueWardSettings.CONFIG.put(new Identifier(id), new General.GrueWardSettings(potency));
}
}

for (HashMap<String, ?> i : (ArrayList<HashMap<String, ?>>) mobGroups) {
var ids = (ArrayList<String>) i.get("ids");
var damageMultiplier = (double) i.get("damage multiplier");
var fearsDarkness = (boolean) i.get("fears darkness");
var isHardcore = (boolean) i.get("is hardcore");

for (var id : ids) {
// log.info("{} {} {}", id, damageMultiplier, fearsDarkness);
General.MobSettings.put(new Identifier(id), new General.MobSettings(damageMultiplier, fearsDarkness));
General.MobSettings.CONFIG.put(new Identifier(id),
new General.MobSettings(damageMultiplier, fearsDarkness, isHardcore));
}
}

Expand All @@ -285,6 +330,8 @@ public static void loadConfig() { // TODO write yaml parser to get spans and lin
if (Debug.GrueMinimumTickWait <= 0) {
throw new IllegalArgumentException("Key \"GrueMinimumTickWait\" must be larger than 0");
}

log.info("[Pandora] Loaded and applied config.");
}

public static void saveConfigs() { // TODO finish save configs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class BackgroundRendererMixin {
private static Vec3d overrideFog(DimensionEffects effects, Vec3d color, float f, Operation<Vec3d> operation,
ClientWorld world, BiomeAccess access, float sunHeight, int i, int j, int k) {

var settings = PandoraConfig.General.DimensionSettings.get(world.getDimensionKey().getValue());
var settings = PandoraConfig.General.DimensionSettings.CONFIG.get(world.getDimensionKey().getValue());

var result = operation.call(effects, color, f);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void pandora_constructorReturn(EntityType<? extends MobEntity> entityTyp
// TODO give a slight regen effect when near light?
var type = self.getType();
var identifier = Registry.ENTITY_TYPE.getId(type);
var mobSettings = PandoraConfig.General.MobSettings.get(identifier);
var mobSettings = PandoraConfig.General.MobSettings.CONFIG.get(identifier);

// log.info("initGoals: {} {} {}", type, identifier, mobSettings);

Expand Down
Loading

0 comments on commit 7b48e15

Please sign in to comment.