Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MidnightConfig replaced with owo-lib #61

Merged
merged 8 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ base {

repositories {
mavenCentral()
maven {
url = "https://api.modrinth.com/maven"
}
maven { url 'https://maven.wispforest.io/releases/' }
}

dependencies {
Expand All @@ -29,9 +27,13 @@ dependencies {
// Dependencies
modImplementation "com.ptsmods:devlogin:3.5"

modImplementation include ("maven.modrinth:midnightlib:${project.midnightlib_version}")
annotationProcessor modImplementation("io.wispforest:owo-lib:${project.owo_version}")
modImplementation "io.wispforest:owo-lib:${project.owo_version}"
include "io.wispforest:owo-sentinel:${project.owo_version}"
}



processResources {
inputs.property "version", project.version

Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ archives_base_name=harmony

# Dependencies
fabric_version=0.110.5+1.21.4
midnightlib_version = 1.6.6-fabric
# https://maven.wispforest.io/io/wispforest/owo-lib/
owo_version = 0.12.20+1.21.4
7 changes: 4 additions & 3 deletions src/main/java/dev/symphony/harmony/Harmony.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.symphony.harmony.item.ModifyItems;
import dev.symphony.harmony.loot.HarmonyLootContextTypes;
import dev.symphony.harmony.loot.HarmonyLootTables;
import eu.midnightdust.lib.config.MidnightConfig;
import net.fabricmc.api.ModInitializer;

import net.fabricmc.fabric.api.resource.conditions.v1.ResourceConditionType;
Expand All @@ -22,11 +21,13 @@ public static Identifier id (String path) {
return Identifier.of(Harmony.MOD_ID, path);
}

public static final HarmonyConfig CONFIG = HarmonyConfig.createAndLoad();


@Override
public void onInitialize() {
// Config
MidnightConfig.init(MOD_ID, HarmonyConfig.class);
HarmonyConfigCondition.init();
HarmonyConfigCondition.init(CONFIG);

ResourceConditionType<HarmonyConfigCondition> conditionType = ResourceConditionType.create(Identifier.of(Harmony.MOD_ID, "config"), HarmonyConfigCondition.CODEC);
ResourceConditions.register(conditionType);
Expand Down
64 changes: 0 additions & 64 deletions src/main/java/dev/symphony/harmony/config/HarmonyConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,30 @@ public record HarmonyConfigCondition(String config_name) implements ResourceCond
String config_name();
}

public static void init() {
Field[] fields = HarmonyConfig.class.getDeclaredFields();
HashMap<String, Boolean> map = new HashMap<>();
public static void init(dev.symphony.harmony.config.HarmonyConfig config) {
Field[] fields = HarmonyConfigModel.class.getDeclaredFields();
for (Field field : fields) {
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
if (field.isAnnotationPresent(ResourceConfigName.class)) {

ResourceConfigName configName = field.getAnnotation(ResourceConfigName.class);

try {
map.put(configName.config_name(), (Boolean) field.get(null));
} catch (IllegalAccessException e) {
Harmony.LOGGER.error("Failed to get resource config condition value for field {}", field.getName());
Harmony.LOGGER.error(Arrays.toString(e.getStackTrace()));
}
if (field.isAnnotationPresent(ResourceConfigName.class)) {
ResourceConfigName configName = field.getAnnotation(ResourceConfigName.class);
try {
// Because of owo lib config model, we use reflection to call the method of the same name as the field from model
// as owo lib doesn't copy annotations to the generated class
resourceMap.put(configName.config_name(), (Boolean) config.getClass().getDeclaredMethod(field.getName()).invoke(config));
} catch (Exception e) {
Harmony.LOGGER.error("Failed to get resource config condition value for field {}", field.getName());
Harmony.LOGGER.error(Arrays.toString(e.getStackTrace()));
}
}
}
resourceMap = map;
}

public static HashMap<String, Boolean> resourceMap = null;
public static HashMap<String, Boolean> resourceMap = new HashMap<>();

public static final MapCodec<HarmonyConfigCondition> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
Codec.STRING.fieldOf("config_name").forGetter(condition -> condition.config_name)
).apply(instance, HarmonyConfigCondition::new));




@Override
public ResourceConditionType<?> getType() {
return ResourceConditionType.create(Identifier.of(Harmony.MOD_ID, "config"), CODEC);
Expand Down
107 changes: 107 additions & 0 deletions src/main/java/dev/symphony/harmony/config/HarmonyConfigModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package dev.symphony.harmony.config;

import dev.symphony.harmony.Harmony;
import io.wispforest.owo.config.annotation.*;


import java.util.concurrent.TimeUnit;


@Modmenu(modId = Harmony.MOD_ID)
@Config(name = "harmony", wrapperName = "HarmonyConfig")
public class HarmonyConfigModel {

// Transportation 🏳️‍⚧️
@SectionHeader("Trans")
public boolean exitVehicleOnDamage = true;

@Nest @Expanded public TransElytraCat transElytraCat = new TransElytraCat();
public static class TransElytraCat {
public boolean liquidsDeactivateElytra = true;
}

@Nest @Expanded public TransMinecartCat transMinecartCat = new TransMinecartCat();
public static class TransMinecartCat {
public float furnaceMinecartSpeed = 1f;
public float furnaceMinecartSpeedInWater = 1f;
}

@Nest @Expanded public TransSaddledCat transSaddledCat = new TransSaddledCat();
public static class TransSaddledCat {
@HarmonyConfigCondition.ResourceConfigName(config_name = "recipe/saddle") public boolean saddleRecipe = true;
public boolean horseArmorPreventsBucking = true;
public boolean enderPearlsTeleportVehicles = true;
public boolean enderPearlsDamageVehicles = true;
}

@Nest @Expanded public TransRiptideCat transRiptideCat = new TransRiptideCat();
public static class TransRiptideCat {
@RangeConstraint(min = 0f, max = 1f) public float riptideAccelerationOnWater = 0.1f;
public boolean riptideCooldown = true;
public int riptideTimeMultiplier = 5;
public boolean reduceRiptideWaterDrag = true;
}




// Food
@SectionHeader("Food")
public int stewStackSize = 16;
public int glowBerryEffect = 10;



// Building
@SectionHeader("Building")
public boolean armorStandStickArms = true;
public int armorStandSticks = 1;



// Redstone
@SectionHeader("Redstone")
public boolean oneTickCopperBulbDelay = true;
public boolean removeRedstoneLampDelay = true;



// Potions
@SectionHeader("Potions")
public boolean beaconsAffectTamedMobs = true;



// Combat
@SectionHeader("Combat")
public boolean tridentsReturnFromVoid = true;
public boolean changeItemDespawnTime = true;

@Nest public ItemDespawnTimeCat itemDespawnTimeCat = new ItemDespawnTimeCat();
public static class ItemDespawnTimeCat {
private static final int ONE_HOUR = 60 * 60;
@RangeConstraint(min = 0, max = ONE_HOUR) public int
itemDespawnTimeEasy = (int) TimeUnit.MINUTES.toSeconds(20),
itemDespawnTimeNormal = (int) TimeUnit.MINUTES.toSeconds(10),
itemDespawnTimeHard = (int) TimeUnit.MINUTES.toSeconds(5);
}




// Mobs
@SectionHeader("Mobs")
public boolean husksDropSandOnConvert = true;

@Nest @Expanded public MobsHostileCat mobsHostileCat = new MobsHostileCat();
public static class MobsHostileCat {
public boolean mismatchedMobArmor = true;
}

@Nest @Expanded public MobsPetsCat mobsPetsCat = new MobsPetsCat();
public static class MobsPetsCat {
public boolean permissiveParrotPerching = true;
public boolean wolvesGrowlAtMonsters = true;
}
}

12 changes: 6 additions & 6 deletions src/main/java/dev/symphony/harmony/item/ModifyItems.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.symphony.harmony.item;

import dev.symphony.harmony.config.HarmonyConfig;
import dev.symphony.harmony.Harmony;
import net.fabricmc.fabric.api.item.v1.DefaultItemComponentEvents;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.item.Items;
Expand All @@ -14,21 +14,21 @@ public static void init() {
* @author Trigam
*/

if (HarmonyConfig.stewStackSize != 1) {
if (Harmony.CONFIG.stewStackSize() != 1) {
DefaultItemComponentEvents.MODIFY.register(context -> {
// Ok so, can't use an item tag since tags only exist
// on world load, while this is run on mod init
context.modify(Items.MUSHROOM_STEW, builder ->
builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.stewStackSize)
builder.add(DataComponentTypes.MAX_STACK_SIZE, Harmony.CONFIG.stewStackSize())
);
context.modify(Items.RABBIT_STEW, builder ->
builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.stewStackSize)
builder.add(DataComponentTypes.MAX_STACK_SIZE, Harmony.CONFIG.stewStackSize())
);
context.modify(Items.BEETROOT_SOUP, builder ->
builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.stewStackSize)
builder.add(DataComponentTypes.MAX_STACK_SIZE, Harmony.CONFIG.stewStackSize())
);
context.modify(Items.SUSPICIOUS_STEW, builder ->
builder.add(DataComponentTypes.MAX_STACK_SIZE, HarmonyConfig.stewStackSize)
builder.add(DataComponentTypes.MAX_STACK_SIZE, Harmony.CONFIG.stewStackSize())
);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.symphony.harmony.mixin.building.armor_stand_arms;

import dev.symphony.harmony.config.HarmonyConfig;
import dev.symphony.harmony.Harmony;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
Expand Down Expand Up @@ -38,12 +38,12 @@ public ToggleableArmorStandArms(EntityType<?> type, World world) {

@Inject(method = "interactAt", at = @At( value = "HEAD" ), cancellable = true)
public void stickArms(PlayerEntity player, Vec3d hitPos, Hand hand, CallbackInfoReturnable<ActionResult> callback) {
if (isMarker() || !HarmonyConfig.armorStandStickArms) return;
if (isMarker() || !Harmony.CONFIG.armorStandStickArms()) return;
if (player.isSneaking()) return;

ItemStack heldItem = player.getStackInHand(hand);
// Add arms
if (heldItem.getItem().equals(Items.STICK) && heldItem.getCount() >= HarmonyConfig.armorStandSticks && !shouldShowArms()) {
if (heldItem.getItem().equals(Items.STICK) && heldItem.getCount() >= Harmony.CONFIG.armorStandSticks() && !shouldShowArms()) {
equipArms(player, heldItem);

callback.setReturnValue(ActionResult.SUCCESS);
Expand All @@ -58,7 +58,7 @@ public void stickArms(PlayerEntity player, Vec3d hitPos, Hand hand, CallbackInfo
@Unique
public void equipArms(PlayerEntity player, ItemStack stickStack) {
setShowArms(true);
stickStack.decrementUnlessCreative(HarmonyConfig.armorStandSticks, player);
stickStack.decrementUnlessCreative(Harmony.CONFIG.armorStandSticks(), player);

player.playSound(SoundEvents.ITEM_ARMOR_EQUIP_GENERIC.value(), 1F, 1F);
}
Expand All @@ -69,7 +69,7 @@ public void shearArms(PlayerEntity player, ItemStack shearStack, Hand hand) {
shearStack.damage(1, player, LivingEntity.getSlotForHand(hand));

ItemStack sticksDrop = Items.STICK.getDefaultStack();
sticksDrop.setCount(HarmonyConfig.armorStandSticks);
sticksDrop.setCount(Harmony.CONFIG.armorStandSticks());

World world = this.getWorld();
BlockPos blockPos = this.getBlockPos().up();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.symphony.harmony.mixin.combat.slower_item_despawn;

import dev.symphony.harmony.config.HarmonyConfig;
import dev.symphony.harmony.Harmony;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.ItemEntity;
Expand All @@ -22,15 +22,15 @@ public ModifyItemDespawnTimes(EntityType<?> type, World world) {

@ModifyConstant(method = "tick", constant = @Constant(intValue = 6000))
private int modifyDespawnTime(int constant) {
if(!HarmonyConfig.changeItemDespawnTime){
if(!Harmony.CONFIG.changeItemDespawnTime()){
return constant;
}


int time = 20 * switch (this.getWorld().getDifficulty()) {
case PEACEFUL, EASY -> HarmonyConfig.itemDespawnTimeEasy;
case NORMAL -> HarmonyConfig.itemDespawnTimeNormal;
case HARD -> HarmonyConfig.itemDespawnTimeHard;
case PEACEFUL, EASY -> Harmony.CONFIG.itemDespawnTimeCat.itemDespawnTimeEasy();
case NORMAL -> Harmony.CONFIG.itemDespawnTimeCat.itemDespawnTimeNormal();
case HARD -> Harmony.CONFIG.itemDespawnTimeCat.itemDespawnTimeHard();
};

return time == 0 ? NEVER_DESPAWN_AGE : time;
Expand Down
Loading