Refactor config

This commit is contained in:
Cynthia Foxwell 2024-03-14 19:55:37 -06:00
parent b803b794f8
commit a42bb0507e
7 changed files with 22 additions and 37 deletions

View file

@ -12,7 +12,6 @@ import net.minecraft.util.Identifier;
import org.quiltmc.loader.api.ModContainer; import org.quiltmc.loader.api.ModContainer;
import org.quiltmc.qsl.base.api.entrypoint.ModInitializer; import org.quiltmc.qsl.base.api.entrypoint.ModInitializer;
import pm.c7.scout.config.ScoutConfigHandler;
import pm.c7.scout.registry.ScoutItems; import pm.c7.scout.registry.ScoutItems;
public class Scout implements ModInitializer { public class Scout implements ModInitializer {
@ -32,7 +31,6 @@ public class Scout implements ModInitializer {
@Override @Override
public void onInitialize(ModContainer mod) { public void onInitialize(ModContainer mod) {
new ScoutConfigHandler();
ScoutItems.init(); ScoutItems.init();
Registry.register(Registries.ITEM_GROUP, new Identifier(ScoutUtil.MOD_ID, "itemgroup"), ITEM_GROUP); Registry.register(Registries.ITEM_GROUP, new Identifier(ScoutUtil.MOD_ID, "itemgroup"), ITEM_GROUP);
} }

View file

@ -0,0 +1,16 @@
package pm.c7.scout;
import org.quiltmc.config.api.ReflectiveConfig;
import org.quiltmc.config.api.annotations.Comment;
import org.quiltmc.config.api.values.TrackedValue;
import org.quiltmc.loader.api.config.v2.QuiltConfig;
public class ScoutConfig extends ReflectiveConfig {
public static final ScoutConfig CONFIG = QuiltConfig.create("", ScoutUtil.MOD_ID, ScoutConfig.class);
@Comment("Allow shulker boxes to be placed in bags. Bags are already blacklisted from shulker boxes with no toggle.")
public final TrackedValue<Boolean> allowShulkers = this.value(true);
@Comment("Allow bags to act as a quiver and pull arrows.")
public final TrackedValue<Boolean> useArrows = this.value(true);
}

View file

@ -1,12 +0,0 @@
package pm.c7.scout.config;
import org.quiltmc.config.api.WrappedConfig;
import org.quiltmc.config.api.annotations.Comment;
public class ScoutConfig extends WrappedConfig {
@Comment("Allow shulker boxes to be placed in bags. Bags are already blacklisted from shulker boxes with no toggle.")
public final boolean allowShulkers = true;
@Comment("Allow bags to act as a quiver and pull arrows.")
public final boolean useArrows = true;
}

View file

@ -1,17 +0,0 @@
package pm.c7.scout.config;
import org.quiltmc.config.api.values.TrackedValue;
import org.quiltmc.loader.api.config.QuiltConfig;
import pm.c7.scout.ScoutUtil;
import java.util.List;
public class ScoutConfigHandler {
public static final ScoutConfig CONFIG = QuiltConfig.create("", ScoutUtil.MOD_ID, ScoutConfig.class);
public ScoutConfigHandler() {}
public static TrackedValue<?> getConfigValue(String key) {
return CONFIG.getValue(List.of(key));
}
}

View file

@ -12,14 +12,14 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import pm.c7.scout.ScoutUtil; import pm.c7.scout.ScoutUtil;
import pm.c7.scout.config.ScoutConfigHandler; import pm.c7.scout.ScoutConfig;
import pm.c7.scout.item.BaseBagItem; import pm.c7.scout.item.BaseBagItem;
@Mixin(BowItem.class) @Mixin(BowItem.class)
public class BowItemMixin { public class BowItemMixin {
@Inject(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V"), locals = LocalCapture.CAPTURE_FAILHARD) @Inject(method = "onStoppedUsing", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;playSound(Lnet/minecraft/entity/player/PlayerEntity;DDDLnet/minecraft/sound/SoundEvent;Lnet/minecraft/sound/SoundCategory;FF)V"), locals = LocalCapture.CAPTURE_FAILHARD)
public void scout$arrowsFromBags(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo ci, PlayerEntity playerEntity, boolean bl, ItemStack itemStack, int maxTime, float f) { public void scout$arrowsFromBags(ItemStack stack, World world, LivingEntity user, int remainingUseTicks, CallbackInfo ci, PlayerEntity playerEntity, boolean bl, ItemStack itemStack, int maxTime, float f) {
if ((boolean) ScoutConfigHandler.getConfigValue("useArrows").value()) { if (ScoutConfig.CONFIG.useArrows.value()) {
boolean infinity = bl && itemStack.isOf(Items.ARROW); boolean infinity = bl && itemStack.isOf(Items.ARROW);
boolean hasRan = false; boolean hasRan = false;

View file

@ -8,7 +8,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture; import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import pm.c7.scout.ScoutUtil; import pm.c7.scout.ScoutUtil;
import pm.c7.scout.config.ScoutConfigHandler; import pm.c7.scout.ScoutConfig;
import pm.c7.scout.item.BaseBagItem; import pm.c7.scout.item.BaseBagItem;
import java.util.function.Predicate; import java.util.function.Predicate;
@ -17,7 +17,7 @@ import java.util.function.Predicate;
public class PlayerEntityMixin { public class PlayerEntityMixin {
@Inject(method = "getArrowType", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/RangedWeaponItem;getProjectiles()Ljava/util/function/Predicate;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) @Inject(method = "getArrowType", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/RangedWeaponItem;getProjectiles()Ljava/util/function/Predicate;"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true)
public void scout$arrowsFromBags(ItemStack stack, CallbackInfoReturnable<ItemStack> cir, Predicate<ItemStack> predicate, ItemStack itemStack) { public void scout$arrowsFromBags(ItemStack stack, CallbackInfoReturnable<ItemStack> cir, Predicate<ItemStack> predicate, ItemStack itemStack) {
if ((boolean) ScoutConfigHandler.getConfigValue("useArrows").value()) { if (ScoutConfig.CONFIG.useArrows.value()) {
var self = (PlayerEntity) (Object) this; var self = (PlayerEntity) (Object) this;
var leftPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, false); var leftPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, false);
var rightPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, true); var rightPouch = ScoutUtil.findBagItem(self, BaseBagItem.BagType.POUCH, true);

View file

@ -6,7 +6,7 @@ import net.minecraft.inventory.Inventory;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.Slot;
import pm.c7.scout.config.ScoutConfigHandler; import pm.c7.scout.ScoutConfig;
import pm.c7.scout.item.BaseBagItem; import pm.c7.scout.item.BaseBagItem;
public class BagSlot extends Slot { public class BagSlot extends Slot {
@ -38,7 +38,7 @@ public class BagSlot extends Slot {
if (stack.getItem() instanceof BlockItem blockItem) { if (stack.getItem() instanceof BlockItem blockItem) {
if (blockItem.getBlock() instanceof ShulkerBoxBlock) if (blockItem.getBlock() instanceof ShulkerBoxBlock)
return (boolean) ScoutConfigHandler.getConfigValue("allowShulkers").value(); return enabled && inventory != null && ScoutConfig.CONFIG.allowShulkers.value();
} }
return enabled && inventory != null; return enabled && inventory != null;