Skip to content

Commit

Permalink
Repair Cost and Fair Pricing
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyMialee committed Jan 4, 2022
1 parent 3c3debf commit 0e44228
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 32 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Removes the anvil experience limit. (Enabled by default)<br>
<img src="https://github.com/AmyMialeeMods/no-enchant-cap/raw/main/assets/anvilXPCap.png"><br><br>
Allows any enchantment on any item. (Enabled by default)<br>
<img src="https://github.com/AmyMialeeMods/no-enchant-cap/raw/main/assets/incompatibleItem.png"><br><br>
Anvil costs are calculated assuming you have the minimum required amount of levels. (Enabled by default)<br>
<img src="https://github.com/AmyMialeeMods/no-enchant-cap/raw/main/assets/fairCosts.png"><br><br>
Repair costs will not increase when using anvils. (Enabled by default)<br>
<img src="https://github.com/AmyMialeeMods/no-enchant-cap/raw/main/assets/noRepairCost.png"><br><br>
Enchantments over X (10) will use number levels.<br>
<img src="https://github.com/AmyMialeeMods/no-enchant-cap/raw/main/assets/numberLevels.png"><br><br>
Removes all limits on the /enchant command.<br>
Expand Down
Binary file added assets/fairCosts.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/noRepairCost.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 0 additions & 29 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
}
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/amymialee/noenchantcap/EnchantModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"noenchantcap.mixins.json"
],
"depends": {
"cloth-config": "*"
"cloth-config": "*",
"fabric": "*"
},
"custom": {
"modupdater": {
Expand Down

0 comments on commit 0e44228

Please sign in to comment.