Skip to content

Commit

Permalink
may this work?
Browse files Browse the repository at this point in the history
  • Loading branch information
DaFuqs committed Jan 20, 2025
1 parent 0dbe57a commit c0105b0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 85 deletions.
14 changes: 0 additions & 14 deletions src/main/java/de/dafuqs/spectrum/api/item/ExtendedEnchantable.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package de.dafuqs.spectrum.helpers;

import de.dafuqs.spectrum.SpectrumCommon;
import de.dafuqs.spectrum.api.item.*;
import de.dafuqs.spectrum.mixin.accessors.EnchantmentAccessor;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.mixin.accessors.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.component.type.ItemEnchantmentsComponent;
import net.minecraft.component.*;
import net.minecraft.component.type.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.*;
import net.minecraft.item.*;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.*;
import net.minecraft.registry.*;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.entry.RegistryEntryList;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.registry.entry.*;
import net.minecraft.server.network.*;
import net.minecraft.server.world.*;
import net.minecraft.util.*;
import org.jetbrains.annotations.*;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.*;

public class SpectrumEnchantmentHelper {

Expand Down Expand Up @@ -185,15 +184,17 @@ public static <T extends RegistryEntry<Enchantment>> Pair<ItemStack, Integer> re
return new Pair<>(itemStack, removals.get());
}

public static <T extends Item & ExtendedEnchantable> ItemStack getMaxEnchantedStack(@NotNull T item) {
ItemStack itemStack = item.getDefaultStack();
for (Enchantment enchantment : Registries.ENCHANTMENT.stream().toList()) {
if (item.acceptsEnchantment(enchantment)) {
int maxLevel = enchantment.getMaxLevel();
itemStack = addOrUpgradeEnchantment(itemStack, enchantment, maxLevel, true, true).getRight();
}
public static ItemStack getEnchantedStack(RegistryWrapper.WrapperLookup lookup, Item item, Map<RegistryKey<Enchantment>, Integer> enchantments) {
RegistryWrapper<Enchantment> wrapper = lookup.getWrapperOrThrow(RegistryKeys.ENCHANTMENT);
ItemEnchantmentsComponent.Builder builder = new ItemEnchantmentsComponent.Builder(ItemEnchantmentsComponent.DEFAULT);

for (Map.Entry<RegistryKey<Enchantment>, Integer> e : enchantments.entrySet()) {
builder.add(wrapper.getOrThrow(e.getKey()), 5);
}
return itemStack;
ItemStack stack = item.getDefaultStack();
stack.set(DataComponentTypes.ENCHANTMENTS, builder.build());

return stack;
}

public static int getLevel(RegistryWrapper.WrapperLookup registryLookup, RegistryKey<Enchantment> enchantment, ItemStack stack) {
Expand Down Expand Up @@ -243,10 +244,4 @@ public static float getAddtionalCritDamageMultiplier(int improvedCriticalLevel)
return SpectrumCommon.CONFIG.ImprovedCriticalExtraDamageMultiplierPerLevel * improvedCriticalLevel;
}

public static RegistryEntryList<Item> getBlacklist(Enchantment enchantment) {
return enchantment.effects().getOrDefault(
SpectrumEnchantmentEffectComponentTypes.BLACKLISTED_ITEMS,
RegistryEntryList.empty());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.collect.*;
import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.api.item.*;
import dev.emi.trinkets.api.*;
import net.minecraft.enchantment.*;
import net.minecraft.entity.*;
Expand All @@ -11,7 +10,7 @@
import net.minecraft.registry.entry.*;
import net.minecraft.util.*;

public class SevenLeagueBootsItem extends SpectrumTrinketItem implements ExtendedEnchantable {
public class SevenLeagueBootsItem extends SpectrumTrinketItem {

public static final Identifier MOVEMENT_SPEED_ATTRIBUTE_ID = SpectrumCommon.locate("seven_league_boots_movement_speed");
public static final Identifier STEP_UP_ATTRIBUTE_ID = SpectrumCommon.locate("seven_league_boots_step_up");
Expand All @@ -37,11 +36,6 @@ public boolean isEnchantable(ItemStack stack) {
return stack.getCount() == 1;
}

@Override
public boolean acceptsEnchantment(Enchantment enchantment) {
return enchantment == Enchantments.POWER;
}

@Override
public int getEnchantability() {
return 8;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.dafuqs.spectrum.items.trinkets;

import de.dafuqs.spectrum.*;
import de.dafuqs.spectrum.api.item.*;
import de.dafuqs.spectrum.networking.s2c_payloads.*;
import de.dafuqs.spectrum.particle.*;
import de.dafuqs.spectrum.registries.*;
Expand All @@ -12,7 +11,7 @@
import net.minecraft.entity.effect.*;
import net.minecraft.entity.player.*;
import net.minecraft.item.*;
import net.minecraft.item.tooltip.TooltipType;
import net.minecraft.item.tooltip.*;
import net.minecraft.server.network.*;
import net.minecraft.server.world.*;
import net.minecraft.sound.*;
Expand All @@ -23,7 +22,7 @@

import java.util.*;

public class TakeOffBeltItem extends SpectrumTrinketItem implements ExtendedEnchantable {
public class TakeOffBeltItem extends SpectrumTrinketItem {

public static final int CHARGE_TIME_TICKS = 20;
public static final int MAX_CHARGES = 8;
Expand Down Expand Up @@ -102,15 +101,9 @@ public boolean isEnchantable(ItemStack stack) {
return stack.getCount() == 1;
}


@Override
public int getEnchantability() {
return 8;
}

@Override
public boolean acceptsEnchantment(Enchantment enchantment) {
return enchantment == Enchantments.POWER || enchantment == Enchantments.FEATHER_FALLING;
}

}
69 changes: 40 additions & 29 deletions src/main/java/de/dafuqs/spectrum/mixin/EnchantmentMixin.java
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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import net.minecraft.registry.*;
import net.minecraft.text.*;

import java.util.*;

@SuppressWarnings("unused")
public class SpectrumItemGroups {

Expand Down Expand Up @@ -113,7 +115,7 @@ public static void register() {
addEquipmentEntry(SpectrumItems.GLOW_VISION_GOGGLES, entries);
addEquipmentEntry(SpectrumItems.JEOPARDANT, entries);
addEquipmentEntry(SpectrumItems.SEVEN_LEAGUE_BOOTS, entries);
entries.add(SpectrumEnchantmentHelper.getMaxEnchantedStack(SpectrumItems.SEVEN_LEAGUE_BOOTS));
entries.add(SpectrumEnchantmentHelper.getEnchantedStack(displayContext.lookup(), SpectrumItems.SEVEN_LEAGUE_BOOTS, Map.of(Enchantments.POWER, 5)));
entries.add(SpectrumItems.COTTON_CLOUD_BOOTS);
entries.add(SpectrumItems.RADIANCE_PIN);
entries.add(SpectrumItems.TOTEM_PENDANT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"spectrum:takeoff_belt"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"values": [
"spectrum:takeoff_belt",
"spectrum:seven_league_boots"
]
}

0 comments on commit c0105b0

Please sign in to comment.