diff --git a/README.md b/README.md index 3fcf0eb..a24ff12 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ Removes the anvil experience limit. (Enabled by default)


Allows any enchantment on any item. (Enabled by default)


+Anvil costs are calculated assuming you have the minimum required amount of levels. (Enabled by default)
+

+Repair costs will not increase when using anvils. (Enabled by default)
+

Enchantments over X (10) will use number levels.


Removes all limits on the /enchant command.
diff --git a/assets/fairCosts.png b/assets/fairCosts.png new file mode 100644 index 0000000..3a54cd7 Binary files /dev/null and b/assets/fairCosts.png differ diff --git a/assets/noRepairCost.png b/assets/noRepairCost.png new file mode 100644 index 0000000..6424ca1 Binary files /dev/null and b/assets/noRepairCost.png differ diff --git a/build.gradle b/build.gradle index 395ddf4..3eeae02 100644 --- a/build.gradle +++ b/build.gradle @@ -26,33 +26,4 @@ processResources { filesMatching("fabric.mod.json") { expand "version": project.version } -} -def targetJavaVersion = 17 -tasks.withType(JavaCompile).configureEach { - it.options.encoding = "UTF-8" - if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { - it.options.release = targetJavaVersion - } -} -java { - def javaVersion = JavaVersion.toVersion(targetJavaVersion) - if (JavaVersion.current() < javaVersion) { - toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion as String) - } - archivesBaseName = project.archives_base_name - withSourcesJar() -} -jar { - from("LICENSE") { - rename { "${it}_${project.archivesBaseName}" } - } -} -publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } - repositories { - } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 56bd905..b849edb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,7 @@ minecraft_version=1.18.1 yarn_mappings=1.18.1+build.11 loader_version=0.12.12 # Mod Properties -mod_version=1.18.1-fabric-2.0.2 +mod_version=1.18.1-fabric-2.1.0 maven_group=amymialee archives_base_name=noenchantcap # Dependencies diff --git a/src/main/java/amymialee/noenchantcap/EnchantModConfig.java b/src/main/java/amymialee/noenchantcap/EnchantModConfig.java index 56f1eb1..a90db43 100644 --- a/src/main/java/amymialee/noenchantcap/EnchantModConfig.java +++ b/src/main/java/amymialee/noenchantcap/EnchantModConfig.java @@ -9,5 +9,7 @@ public class EnchantModConfig implements ConfigData { public boolean allowAllEnchantmentCombinations = false; public boolean allowAnyEnchantOnAnyItem = true; public boolean removeAnvilLevelLimit = false; + public boolean fairLevelCost = true; + public boolean removeRepairCostIncrease = true; public int newAnvilLevelLimit = 255; -} +} \ No newline at end of file diff --git a/src/main/java/amymialee/noenchantcap/mixin/NECMixin_AnvilScreenHandler.java b/src/main/java/amymialee/noenchantcap/mixin/NECMixin_AnvilScreenHandler.java index eb5b6f3..7c2ec94 100644 --- a/src/main/java/amymialee/noenchantcap/mixin/NECMixin_AnvilScreenHandler.java +++ b/src/main/java/amymialee/noenchantcap/mixin/NECMixin_AnvilScreenHandler.java @@ -1,6 +1,8 @@ package amymialee.noenchantcap.mixin; import net.minecraft.enchantment.Enchantment; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.screen.AnvilScreenHandler; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -43,4 +45,36 @@ private int modifyMaxCost(int original) { return original; } } + + //Removes repair cost increase. + @Redirect(method = "updateResult", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/ItemStack;setRepairCost(I)V")) + private void removeRepairCostIncrease(ItemStack instance, int repairCost) { + if (!config.removeRepairCostIncrease) { + String REPAIR_COST_KEY = "RepairCost"; + instance.getOrCreateNbt().putInt(REPAIR_COST_KEY, repairCost); + } + } + + //Takes fair numbers of levels. + @Redirect(method = "onTakeOutput", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerEntity;addExperienceLevels(I)V")) + private void fairLevelCost(PlayerEntity instance, int levels) { + if (!config.fairLevelCost) { + instance.addExperienceLevels(levels); + } else { + instance.addExperience(-getLevelTotal(-levels)); + } + } + private static int getLevelTotal(int level) { + int total = 0; + for (int i = 1; i <= level; i++) { + if (i >= 30) { + total += 112 + (i - 30) * 9; + } else if (i >= 15) { + total += 37 + (i - 15) * 5; + } else { + total += 7 + i * 2; + } + } + return total; + } } diff --git a/src/main/java/amymialee/noenchantcap/mixin/NECMixin_ItemStack.java b/src/main/java/amymialee/noenchantcap/mixin/NECMixin_ItemStack.java index 77fe7dd..397e698 100644 --- a/src/main/java/amymialee/noenchantcap/mixin/NECMixin_ItemStack.java +++ b/src/main/java/amymialee/noenchantcap/mixin/NECMixin_ItemStack.java @@ -23,6 +23,7 @@ public abstract class NECMixin_ItemStack { @Inject(method = "addEnchantment", at = @At("HEAD"), cancellable = true) public void addEnchantment(Enchantment enchantment, int level, CallbackInfo ci) { getOrCreateNbt(); + assert nbt != null; if (!nbt.contains(ENCHANTMENTS_KEY, 9)) { nbt.put(ENCHANTMENTS_KEY, new NbtList()); } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2671fd1..abb3fe9 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -26,7 +26,8 @@ "noenchantcap.mixins.json" ], "depends": { - "cloth-config": "*" + "cloth-config": "*", + "fabric": "*" }, "custom": { "modupdater": {