-
Notifications
You must be signed in to change notification settings - Fork 68
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
Showing
8 changed files
with
77 additions
and
85 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
src/main/java/de/dafuqs/spectrum/api/item/ExtendedEnchantable.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
69 changes: 40 additions & 29 deletions
69
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,47 +1,58 @@ | ||
package de.dafuqs.spectrum.mixin; | ||
|
||
import de.dafuqs.spectrum.SpectrumCommon; | ||
import de.dafuqs.spectrum.api.item.*; | ||
import de.dafuqs.spectrum.helpers.SpectrumEnchantmentHelper; | ||
import com.llamalad7.mixinextras.injector.*; | ||
import de.dafuqs.spectrum.*; | ||
import net.minecraft.enchantment.*; | ||
import net.minecraft.item.*; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.registry.entry.RegistryEntryList; | ||
import net.minecraft.registry.*; | ||
import net.minecraft.registry.entry.*; | ||
import net.minecraft.registry.tag.*; | ||
import org.spongepowered.asm.mixin.*; | ||
import org.spongepowered.asm.mixin.injection.*; | ||
import org.spongepowered.asm.mixin.injection.callback.*; | ||
|
||
import java.util.*; | ||
|
||
@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)); | ||
|
||
@ModifyReturnValue(method = "getApplicableItems()Lnet/minecraft/registry/entry/RegistryEntryList;", at = @At("RETURN")) | ||
public RegistryEntryList<Item> spectrum$getAcceptableItems(RegistryEntryList<Item> original) { | ||
Enchantment enchantment = (Enchantment) (Object) this; | ||
|
||
RegistryEntry<Enchantment> entry = RegistryEntry.of(enchantment); | ||
TagKey<Item> blacklistedEnchantableTag = TagKey.of(RegistryKeys.ITEM, SpectrumCommon.locate("enchantable/blacklisted/" + entry.getIdAsString().replace(':', '_'))); | ||
List<RegistryEntry<Item>> modified = original.stream().filter(itemRegistryEntry -> itemRegistryEntry.isIn(blacklistedEnchantableTag)).toList(); | ||
|
||
return RegistryEntryList.of(modified); | ||
} | ||
|
||
@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())); | ||
@ModifyReturnValue(method = "isSupportedItem(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN")) | ||
public boolean spectrum$isSupportedItems(boolean original, ItemStack stack) { | ||
return spectrum$modifyIsSupported((Enchantment) (Object) this, stack, original); | ||
} | ||
|
||
@Inject(method = "isAcceptableItem(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN"), cancellable = true) | ||
public void spectrum$isAcceptableItem(ItemStack stack, CallbackInfoReturnable<Boolean> cir) { | ||
cir.setReturnValue(spectrum$modifyIsSupported((Enchantment) (Object) this, stack, cir.getReturnValue())); | ||
@ModifyReturnValue(method = "isAcceptableItem(Lnet/minecraft/item/ItemStack;)Z", at = @At("RETURN")) | ||
public boolean spectrum$isAcceptableItem(boolean original, ItemStack stack) { | ||
return spectrum$modifyIsSupported((Enchantment) (Object) this, stack, original); | ||
} | ||
|
||
@Unique | ||
private static boolean spectrum$modifyIsSupported(Enchantment enchantment, ItemStack stack, boolean original) { | ||
var isExtendedEnchantable = stack.getItem() instanceof ExtendedEnchantable extendedEnchantable | ||
&& SpectrumCommon.getRegistryLookup() | ||
.flatMap(r -> r.getOptionalWrapper(RegistryKeys.ENCHANTMENT)) | ||
.map(impl -> extendedEnchantable.acceptsEnchantment(impl, enchantment)) | ||
.orElse(false); | ||
var isBlacklisted = stack.isIn(SpectrumEnchantmentHelper.getBlacklist(enchantment)); | ||
return (original || isExtendedEnchantable) && !isBlacklisted; | ||
if (original) { | ||
RegistryEntry<Enchantment> entry = RegistryEntry.of(enchantment); | ||
TagKey<Item> blacklistedEnchantableTag = TagKey.of(RegistryKeys.ITEM, SpectrumCommon.locate("enchantable/blacklisted/" + entry.getIdAsString().replace(':', '_'))); | ||
if (stack.isIn(blacklistedEnchantableTag)) { | ||
original = false; | ||
} | ||
} else { | ||
RegistryEntry<Enchantment> entry = RegistryEntry.of(enchantment); | ||
TagKey<Item> extendedEnchantableTag = TagKey.of(RegistryKeys.ITEM, SpectrumCommon.locate("enchantable/extended/" + entry.getIdAsString().replace(':', '_'))); | ||
if (stack.isIn(extendedEnchantableTag)) { | ||
original = true; | ||
} | ||
} | ||
|
||
return original; | ||
} | ||
|
||
} |
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
5 changes: 5 additions & 0 deletions
5
...ain/resources/data/spectrum/tags/item/enchantable/extended/minecraft_feather_falling.json
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"values": [ | ||
"spectrum:takeoff_belt" | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/resources/data/spectrum/tags/item/enchantable/extended/minecraft_power.json
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"values": [ | ||
"spectrum:takeoff_belt", | ||
"spectrum:seven_league_boots" | ||
] | ||
} |