Skip to content

Commit a99b43b

Browse files
committed
Filter out enchantments that the server doesn't know
1 parent 95e4869 commit a99b43b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main/java/net/earthcomputer/clientcommands/mixin/MixinEnchantmentHelper.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
package net.earthcomputer.clientcommands.mixin;
22

3+
import com.google.common.collect.Iterators;
34
import com.google.common.collect.Lists;
45
import net.earthcomputer.multiconnect.api.MultiConnectAPI;
56
import net.earthcomputer.multiconnect.api.Protocols;
7+
import net.minecraft.enchantment.Enchantment;
68
import net.minecraft.enchantment.EnchantmentHelper;
79
import net.minecraft.enchantment.EnchantmentLevelEntry;
810
import net.minecraft.item.Item;
911
import net.minecraft.item.ItemStack;
1012
import net.minecraft.util.collection.WeightedPicker;
1113
import net.minecraft.util.math.MathHelper;
14+
import net.minecraft.util.registry.Registry;
1215
import org.spongepowered.asm.mixin.Mixin;
1316
import org.spongepowered.asm.mixin.injection.At;
1417
import org.spongepowered.asm.mixin.injection.Inject;
18+
import org.spongepowered.asm.mixin.injection.ModifyVariable;
1519
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1620

21+
import java.util.Iterator;
1722
import java.util.List;
1823
import java.util.Random;
1924

@@ -59,4 +64,9 @@ private static void getEnchantments1140(Random rand, ItemStack stack, int level,
5964
}
6065
}
6166

67+
@ModifyVariable(method = "getPossibleEntries", ordinal = 0, at = @At(value = "STORE", ordinal = 0))
68+
private static Iterator<Enchantment> filterServerUnknwonEnchantments(Iterator<Enchantment> itr) {
69+
return Iterators.filter(itr, enchantment -> MultiConnectAPI.instance().doesServerKnow(Registry.ENCHANTMENT, enchantment));
70+
}
71+
6272
}

0 commit comments

Comments
 (0)