fixed emerald removal for existing valid configs

This commit is contained in:
alterNERDtive 2023-06-21 00:18:24 +02:00
parent 9682721291
commit 143e3ce862
Signed by: alterNERDtive
GPG key ID: 547787A4FE6533F1

View file

@ -17,7 +17,6 @@
*/ */
package tv.alterNERD.VaultModTweaks.integration.mixin; package tv.alterNERD.VaultModTweaks.integration.mixin;
import java.util.LinkedList;
import java.util.List; import java.util.List;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@ -26,6 +25,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import com.google.gson.JsonObject;
import iskallia.vault.util.EnchantmentCost; import iskallia.vault.util.EnchantmentCost;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import tv.alterNERD.VaultModTweaks.Configuration; import tv.alterNERD.VaultModTweaks.Configuration;
@ -44,7 +45,8 @@ public class MixinEnchantmentCost {
private List<ItemStack> items; private List<ItemStack> items;
/** /**
* Removes the Emerald cost from all Vault Enchanter enchantments. * Removes the Emerald cost from all Vault Enchanter enchantments when
* creating a new configuration.
* *
* @param items * @param items
* @param levels * @param levels
@ -58,7 +60,27 @@ public class MixinEnchantmentCost {
private void initCallback(List<ItemStack> items, int levels, CallbackInfo ci) { private void initCallback(List<ItemStack> items, int levels, CallbackInfo ci) {
if (Configuration.ENCHANTS_FORFREE.get()) { if (Configuration.ENCHANTS_FORFREE.get()) {
VaultModTweaks.LOGGER.info("the_vault_tweaks.log.inject.enchanter.forfree"); VaultModTweaks.LOGGER.info("the_vault_tweaks.log.inject.enchanter.forfree");
this.items = new LinkedList<ItemStack>(); this.items.clear();
} }
} }
/**
* Removes the Emerald cost from all Vault Enchanter enchantments when
* reading an existing JSON configuration.
*
* @param json
* @param ci
*/
@Inject(
method = "readJson",
at = @At("RETURN"),
remap = false
)
private void readJsonCallback(JsonObject json, CallbackInfo ci) {
if (Configuration.ENCHANTS_FORFREE.get()) {
VaultModTweaks.LOGGER.info("the_vault_tweaks.log.inject.enchanter.forfree");
this.items.clear();
}
}
} }