Skip to content

Commit

Permalink
Change EnhancerAccessor to use HolderSet instead of List
Browse files Browse the repository at this point in the history
  • Loading branch information
stal111 committed Oct 27, 2024
1 parent 3b6b3bf commit 2540844
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
import com.stal111.forbidden_arcanus.core.init.ModRecipeTypes;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.*;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
Expand Down Expand Up @@ -133,7 +131,7 @@ public int getCount() {
private boolean wasLit = false;

private ClibanoSmeltLogic logic = new DefaultSmeltLogic(this, null, null);
private @Nullable EnhancerDefinition enhancer;
private @Nullable Holder<EnhancerDefinition> enhancer;

public ClibanoMainBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.CLIBANO_MAIN.get(), pos, state, ClibanoMenu.SLOT_COUNT, (slot, stack) -> {
Expand All @@ -145,7 +143,7 @@ public ClibanoMainBlockEntity(BlockPos pos, BlockState state) {

return !slot.equals(ClibanoMenu.RESULT_SLOTS.getFirst()) && !slot.equals(ClibanoMenu.RESULT_SLOTS.getSecond());
});
this.quickCheck = new CachedRecipeCheck(() -> this.enhancer != null ? List.of(this.enhancer) : Collections.emptyList());
this.quickCheck = new CachedRecipeCheck(() -> this.enhancer != null ? HolderSet.direct(this.enhancer) : HolderSet.empty());
}

@Override
Expand Down Expand Up @@ -422,7 +420,7 @@ private void consumeSoul(Level level) {
this.soulTime = SOUL_DURATION;

if (this.enhancer != null) {
this.enhancer.getEffects(EnhancerTarget.CLIBANO).forEach(enhancerEffect -> {
this.enhancer.value().getEffects(EnhancerTarget.CLIBANO).forEach(enhancerEffect -> {
if (enhancerEffect instanceof MultiplySoulDurationEffect effect) {
this.soulTime = effect.getModifiedValue(this.soulTime);
}
Expand Down Expand Up @@ -459,8 +457,8 @@ protected void onSlotChanged(int slot) {
}
}

private @Nullable EnhancerDefinition updateEnhancer() {
return EnhancerHelper.getEnhancer(this.level.registryAccess(), this.getStack(ClibanoMenu.ENHANCER_SLOT)).orElse(null);
private @Nullable Holder<EnhancerDefinition> updateEnhancer() {
return EnhancerHelper.getEnhancerHolder(this.level.registryAccess(), this.getStack(ClibanoMenu.ENHANCER_SLOT)).orElse(null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.stal111.forbidden_arcanus.core.init.ModRecipeTypes;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderSet;
import net.minecraft.core.NonNullList;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.codec.ByteBufCodecs;
Expand All @@ -39,16 +40,16 @@ public record ClibanoRecipe(String group,

public static final ClibanoCookingTimes DEFAULT_COOKING_TIMES = ClibanoCookingTimes.of(100);

public boolean matches(@NotNull ClibanoRecipeInput recipeInput, @NotNull Level level, List<EnhancerDefinition> enhancers) {
public boolean matches(@NotNull ClibanoRecipeInput recipeInput, @NotNull Level level, HolderSet<EnhancerDefinition> enhancers) {
if (!enhancerMatches(enhancers)) {
return false;
}

return this.matches(recipeInput, level);
}

private boolean enhancerMatches(List<EnhancerDefinition> enhancers) {
return this.requiredEnhancer.isEmpty() || enhancers.contains(this.requiredEnhancer.get().value());
private boolean enhancerMatches(HolderSet<EnhancerDefinition> enhancers) {
return this.requiredEnhancer.isEmpty() || enhancers.contains(this.requiredEnhancer.get());
}

@DoNotCall
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.stal111.forbidden_arcanus.common.item.enhancer;

import java.util.List;
import net.minecraft.core.HolderSet;

/**
* @author stal111
* @since 2023-03-18
*/
public interface EnhancerAccessor {
List<EnhancerDefinition> getEnhancers();
HolderSet<EnhancerDefinition> getEnhancers();
}

0 comments on commit 2540844

Please sign in to comment.