-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7596df1
commit f216a7c
Showing
28 changed files
with
155 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 0 additions & 28 deletions
28
src/main/java/de/dafuqs/spectrum/enchantments/ImprovedCriticalEnchantment.java
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/main/java/de/dafuqs/spectrum/enchantments/IndestructibleEnchantment.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 27 additions & 10 deletions
37
src/main/java/de/dafuqs/spectrum/mixin/EnchantmentMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,42 @@ | ||
package de.dafuqs.spectrum.mixin; | ||
|
||
import de.dafuqs.spectrum.api.item.*; | ||
import de.dafuqs.spectrum.helpers.SpectrumEnchantmentHelper; | ||
import net.minecraft.enchantment.*; | ||
import net.minecraft.item.*; | ||
import net.minecraft.registry.entry.RegistryEntryList; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.*; | ||
import org.spongepowered.asm.mixin.injection.callback.*; | ||
|
||
@Mixin(Enchantment.class) | ||
public abstract class EnchantmentMixin { | ||
|
||
|
||
@Inject(method = "getApplicableItems()Lnet/minecraft/registry/entry/RegistryEntryList;", at = @At("RETURN"), cancellable = true) | ||
public void spectrum$getAcceptableItems(CallbackInfoReturnable<RegistryEntryList<Item>> cir) { | ||
var enchantment = (Enchantment) (Object) this; | ||
var items = cir.getReturnValue(); | ||
var blacklist = SpectrumEnchantmentHelper.getBlacklist(enchantment); | ||
var withoutBlacklisted = blacklist.stream().filter(b -> !items.contains(b)).toList(); | ||
cir.setReturnValue(RegistryEntryList.of(withoutBlacklisted)); | ||
} | ||
|
||
@Inject(method = "isSupportedItem(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true) | ||
public void spectrum$isSupportedItems(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { | ||
cir.setReturnValue(spectrum$modifyIsSupported((Enchantment) (Object) this, stack, cir.getReturnValue())); | ||
} | ||
|
||
@Inject(method = "isAcceptableItem(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true) | ||
public void isAcceptableItem(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { | ||
var accepted = cir.getReturnValue(); | ||
|
||
if (!accepted) { | ||
var enchantment = (Enchantment) (Object) this; | ||
if (stack.getItem() instanceof ExtendedEnchantable extendedEnchantable && extendedEnchantable.acceptsEnchantment(enchantment)) { | ||
cir.setReturnValue(true); | ||
} | ||
} | ||
public void spectrum$isAcceptableItem(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { | ||
cir.setReturnValue(spectrum$modifyIsSupported((Enchantment) (Object) this, stack, cir.getReturnValue())); | ||
} | ||
|
||
@Unique | ||
private static boolean spectrum$modifyIsSupported(Enchantment enchantment, ItemStack stack, boolean original) { | ||
var isExtendedEnchantable = stack.getItem() instanceof ExtendedEnchantable extendedEnchantable | ||
&& extendedEnchantable.acceptsEnchantment(enchantment); | ||
var isBlacklisted = stack.isIn(SpectrumEnchantmentHelper.getBlacklist(enchantment)); | ||
return (original || isExtendedEnchantable) && !isBlacklisted; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.