blob: 0e694d3387a03b2d40c2d9e0741744f7953320ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
package kubatech.mixin.mixins.minecraft;
import static kubatech.loaders.MobRecipeLoader.randomEnchantmentDetectedString;
import java.util.Random;
import kubatech.api.utils.FastRandom;
import kubatech.loaders.MobRecipeLoader;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagInt;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@SuppressWarnings("unused")
@Mixin(value = EnchantmentHelper.class)
public class EnchantmentHelperMixin {
private static final Random rnd = new FastRandom();
@Inject(method = "addRandomEnchantment", at = @At("HEAD"), require = 1)
private static void addRandomEnchantmentDetector(Random random, ItemStack itemStack, int enchantabilityLevel,
CallbackInfoReturnable<ItemStack> callbackInfoReturnable) {
if (MobRecipeLoader.isInGenerationProcess && random instanceof MobRecipeLoader.fakeRand) {
itemStack.setTagInfo(randomEnchantmentDetectedString, new NBTTagInt(enchantabilityLevel));
}
}
@ModifyVariable(method = "addRandomEnchantment", at = @At("HEAD"), ordinal = 0, argsOnly = true, require = 1)
private static Random addRandomEnchantmentModifier(Random random) {
if (!MobRecipeLoader.isInGenerationProcess) return random;
if (random instanceof MobRecipeLoader.fakeRand) return rnd;
return random;
}
}
|