Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ public static boolean isValidCenterEnchantingSetup(@NotNull EnchanterBlockEntity
Map<Enchantment, Integer> currentEnchantedBookEnchantments = EnchantmentHelper.get(virtualSlotStack);
for (Enchantment enchantment : currentEnchantedBookEnchantments.keySet()) {
if ((isEnchantableBookInCenter || enchantment.isAcceptableItem(centerStack)) && (!existingEnchantments.containsKey(enchantment) || existingEnchantments.get(enchantment) < currentEnchantedBookEnchantments.get(enchantment))) {
if(SpectrumEnchantmentTags.isIn(SpectrumEnchantmentTags.IGNORED_BY_ENCHANTER_ENCHANTING, enchantment)) {
continue;
}
if (enchanterBlockEntity.canOwnerApplyConflictingEnchantments) {
enchantedBookWithAdditionalEnchantmentsFound = true;
break;
Expand Down Expand Up @@ -338,10 +341,13 @@ public static void enchantCenterItem(@NotNull EnchanterBlockEntity enchanterBloc
public static Map<Enchantment, Integer> getHighestEnchantmentsInItemBowls(@NotNull EnchanterBlockEntity enchanterBlockEntity) {
List<ItemStack> bowlStacks = new ArrayList<>();
for (int i = 0; i < 8; i++) {
bowlStacks.add(enchanterBlockEntity.virtualInventoryIncludingBowlStacks.getStack(2 + i));
ItemStack bowlStack = enchanterBlockEntity.virtualInventoryIncludingBowlStacks.getStack(2 + i);
if (!bowlStack.isIn(SpectrumItemTags.ENCHANTER_ENCHANTMENT_SOURCE_BLACKLISTED)) {
bowlStacks.add(bowlStack);
}
}

return SpectrumEnchantmentHelper.collectHighestEnchantments(bowlStacks);
return SpectrumEnchantmentHelper.collectHighestEnchantments(bowlStacks, SpectrumEnchantmentTags.IGNORED_BY_ENCHANTER_ENCHANTING);
}

public static int getRequiredExperienceToEnchantCenterItem(@NotNull EnchanterBlockEntity enchanterBlockEntity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,18 @@ public static void register() {
registerIntegrationPack(CREATE_ID, () -> new CreateCompat());
registerIntegrationPack(FARMERSDELIGHT_ID, () -> new FDCompat());
registerIntegrationPack(GOBBER_ID, () -> new GobberCompat());
registerIntegrationPack(MALUM_ID, () -> new MalumCompat());
registerIntegrationPack(NEEPMEAT_ID, () -> new NEEPMeatCompat());

if (!CONNECTOR_LOADED) {
// Traveler's Backpack for Forge crashes due to Fabric lacking Fluid#getFluidType (a Forge method)
// This cannot be reasonably worked around AFAIK
// ~unilock, 2025

//Malum for Fabric uses Create Porter Lib, Atemps to register enchantments though it create NoSuchField errors
// Needs replacement or hacky workaround
// ~Shibva, 2026
registerIntegrationPack(TRAVELERS_BACKPACK_ID, () -> new TravelersBackpackCompat());
registerIntegrationPack(MALUM_ID, () -> new MalumCompat());
}

for (ModIntegrationPack container : INTEGRATION_PACKS.values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.item.*;
import net.minecraft.nbt.*;
import net.minecraft.registry.*;
import net.minecraft.registry.tag.*;
import net.minecraft.util.*;
import org.jetbrains.annotations.*;

Expand Down Expand Up @@ -141,13 +142,18 @@ public static boolean hasEnchantmentThatConflictsWith(ItemStack itemStack, Encha
return false;
}

public static Map<Enchantment, Integer> collectHighestEnchantments(List<ItemStack> itemStacks) {
//This instance of collectHighestEnchantments is to enable the use of an optional filter
public static Map<Enchantment, Integer> collectHighestEnchantments(List<ItemStack> itemStacks, @Nullable TagKey<Enchantment> ignoreList) {
Map<Enchantment, Integer> enchantmentLevelMap = new LinkedHashMap<>();

for (ItemStack itemStack : itemStacks) {
Map<Enchantment, Integer> itemStackEnchantments = EnchantmentHelper.get(itemStack);
for (Enchantment enchantment : itemStackEnchantments.keySet()) {
int level = itemStackEnchantments.get(enchantment);

if (ignoreList != null && SpectrumEnchantmentTags.isIn(ignoreList, enchantment)) {
continue;
}

if (enchantmentLevelMap.containsKey(enchantment)) {
int storedLevel = enchantmentLevelMap.get(enchantment);
if (level > storedLevel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public class SpectrumEnchantmentTags {

public static final TagKey<Enchantment> SPECTRUM_ENCHANTMENT = of("enchantments");
public static final TagKey<Enchantment> IGNORED_BY_ENCHANTER_ENCHANTING = of("ignored_by_enchanter_enchanting");

private static TagKey<Enchantment> of(String id) {
return TagKey.of(RegistryKeys.ENCHANTMENT, SpectrumCommon.locate(id));
Expand All @@ -22,10 +23,7 @@ public static boolean isIn(TagKey<Enchantment> tag, Enchantment enchantment) {
return false;
}
Optional<RegistryEntry.Reference<Enchantment>> registryEntry = Registries.ENCHANTMENT.getEntry(optionalKey.get());
if (registryEntry.isEmpty()) {
return false;
}
return Registries.ENCHANTMENT.getOrCreateEntryList(tag).contains(registryEntry.get());
return registryEntry.filter(enchantmentReference -> Registries.ENCHANTMENT.getOrCreateEntryList(tag).contains(enchantmentReference)).isPresent();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class SpectrumItemTags {
public static final TagKey<Item> TAG_FILTERING_ITEMS = of("tag_filtering_items");
public static final TagKey<Item> WEEPING_GALA_LOGS = of("weeping_gala_logs");
public static final TagKey<Item> PLAYER_ATTRIBUTED_PLACEMENT = of("player_attributed_placement");

public static final TagKey<Item> ENCHANTER_ENCHANTMENT_SOURCE_BLACKLISTED = of("enchanter_enchantment_source_blacklisted");

private static TagKey<Item> of(String id) {
return TagKey.of(RegistryKeys.ITEM, SpectrumCommon.locate(id));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}