Skip to content

Commit

Permalink
if mending is so good
Browse files Browse the repository at this point in the history
  • Loading branch information
yrsegal committed Oct 13, 2023
1 parent b80653e commit 2953cc2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@
import net.minecraft.network.chat.Component;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.gossip.GossipContainer;
import net.minecraft.world.entity.ai.gossip.GossipType;
import net.minecraft.world.entity.monster.ZombieVillager;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.enchantment.Enchantment;
Expand All @@ -28,9 +26,7 @@
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.event.entity.player.PlayerXpEvent;
import net.minecraftforge.eventbus.api.Event.Result;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import vazkii.quark.base.module.LoadModule;
import vazkii.quark.base.module.ModuleCategory;
Expand All @@ -41,6 +37,7 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.function.Predicate;

@LoadModule(category = ModuleCategory.EXPERIMENTAL, enabledByDefault = false, hasSubscriptions = true)
public class GameNerfsModule extends QuarkModule {
Expand All @@ -51,6 +48,10 @@ public class GameNerfsModule extends QuarkModule {
+ "https://www.curseforge.com/minecraft/mc-mods/unmending")
public static boolean nerfMending = true;

@Config(name = "No Nerf for Mending II", description = "Makes Mending II still work even if mending is nerfed.\n" +
"If you want Mending II, disable the sanity check on Ancient Tomes and add minecraft:mending to the tomes.")
public static boolean noNerfForMendingTwo = false;

@Config(description = "Resets all villager discounts when zombified to prevent reducing prices to ridiculous levels")
public static boolean nerfVillagerDiscount = true;

Expand Down Expand Up @@ -137,22 +138,17 @@ public void onMobGriefing(EntityMobGriefingEvent event) {
event.setResult(Result.DENY);
}

// stolen from King Lemming thanks mate
@SubscribeEvent(priority = EventPriority.LOWEST)
public void killMending(PlayerXpEvent.PickupXp event) {
if(!nerfMending)
return;
public static Predicate<ItemStack> limitMendingItems(Predicate<ItemStack> base) {
if (!staticEnabled || !nerfMending)
return base;

Player player = event.getEntity();
ExperienceOrb orb = event.getOrb();

player.takeXpDelay = 2;
player.take(orb, 1);
if(orb.value > 0)
player.giveExperiencePoints(orb.value);
if (noNerfForMendingTwo)
return (stack) -> base.test(stack) && stack.getEnchantmentLevel(Enchantments.MENDING) > 1;
return (stack) -> false;
}

orb.discard();
event.setCanceled(true);
private boolean isMending(Map<Enchantment, Integer> enchantments) {
return enchantments.containsKey(Enchantments.MENDING) && (!noNerfForMendingTwo || enchantments.get(Enchantments.MENDING) < 2);
}

@SubscribeEvent
Expand All @@ -172,7 +168,7 @@ public void onAnvilUpdate(AnvilUpdateEvent event) {
Map<Enchantment, Integer> enchLeft = EnchantmentHelper.getEnchantments(left);
Map<Enchantment, Integer> enchRight = EnchantmentHelper.getEnchantments(right);

if(enchLeft.containsKey(Enchantments.MENDING) || enchRight.containsKey(Enchantments.MENDING)) {
if(isMending(enchLeft) || isMending(enchRight)) {
if(left.getItem() == right.getItem())
isMended = true;

Expand Down Expand Up @@ -202,7 +198,8 @@ else if (level == levelPresent && enchantment.getMaxLevel() > level)
}
}
}
enchOutput.remove(Enchantments.MENDING);
if (isMending(enchOutput))
enchOutput.remove(Enchantments.MENDING);

EnchantmentHelper.setEnchantments(enchOutput, out);

Expand Down
20 changes: 7 additions & 13 deletions src/main/java/vazkii/quark/content/tools/item/AncientTomeItem.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
package vazkii.quark.content.tools.item;

import java.util.List;

import javax.annotation.Nonnull;

import net.minecraft.ChatFormatting;
import net.minecraft.core.NonNullList;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.EnchantedBookItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.*;
import net.minecraft.world.item.enchantment.Enchantment;
import net.minecraft.world.item.enchantment.EnchantmentInstance;
import net.minecraft.world.level.Level;
Expand All @@ -24,6 +15,9 @@
import vazkii.quark.content.experimental.module.EnchantmentsBegoneModule;
import vazkii.quark.content.tools.module.AncientTomesModule;

import javax.annotation.Nonnull;
import java.util.List;

public class AncientTomeItem extends QuarkItem {

public AncientTomeItem(QuarkModule module) {
Expand Down Expand Up @@ -57,7 +51,7 @@ public void fillItemCategory(@Nonnull CreativeModeTab group, @Nonnull NonNullLis
if (isEnabled() || group == CreativeModeTab.TAB_SEARCH) {
if (group == CreativeModeTab.TAB_SEARCH || group.getEnchantmentCategories().length != 0) {
ForgeRegistries.ENCHANTMENTS.forEach(ench -> {
if (!EnchantmentsBegoneModule.shouldBegone(ench) && ench.getMaxLevel() != 1) {
if (!EnchantmentsBegoneModule.shouldBegone(ench) && (!AncientTomesModule.sanityCheck || ench.getMaxLevel() != 1)) {
if (!AncientTomesModule.isInitialized() || AncientTomesModule.validEnchants.contains(ench)) {
if (group == CreativeModeTab.TAB_SEARCH || group.hasEnchantmentCategory(ench.category)) {
items.add(getEnchantedItemStack(ench));
Expand All @@ -81,9 +75,9 @@ public void appendHoverText(@Nonnull ItemStack stack, Level worldIn, @Nonnull Li
Enchantment ench = AncientTomesModule.getTomeEnchantment(stack);
if(ench != null)
tooltip.add(getFullTooltipText(ench));
else
else
tooltip.add(Component.translatable("quark.misc.ancient_tome_tooltip_any").withStyle(ChatFormatting.GRAY));

if(AncientTomesModule.curseGear){
tooltip.add(Component.translatable("quark.misc.ancient_tome_tooltip_curse").withStyle(ChatFormatting.RED));
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/vazkii/quark/mixin/ExperienceOrbMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package vazkii.quark.mixin;

import net.minecraft.world.entity.ExperienceOrb;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import vazkii.quark.content.experimental.module.GameNerfsModule;

import java.util.function.Predicate;

@Mixin(ExperienceOrb.class)
public class ExperienceOrbMixin {

@ModifyArg(method = "repairPlayerItems",
at = @At(value = "INVOKE", target = "Lnet/minecraft/world/item/enchantment/EnchantmentHelper;getRandomItemWith(Lnet/minecraft/world/item/enchantment/Enchantment;Lnet/minecraft/world/entity/LivingEntity;Ljava/util/function/Predicate;)Ljava/util/Map$Entry;"))
private Predicate<ItemStack> alterPredicateForMending(Predicate<ItemStack> predicate) {
return GameNerfsModule.limitMendingItems(predicate);
}

}
1 change: 1 addition & 0 deletions src/main/resources/quark.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"EnchantmentMixin",
"EnchantRandomlyFunctionMixin",
"EntityMixin",
"ExperienceOrbMixin",
"FallingBlockEntityMixin",
"HalfTransparentBlockMixin",
"HarvestFarmlandMixin",
Expand Down

0 comments on commit 2953cc2

Please sign in to comment.