From a39d028f5e3c26939c28efdddab281c7c91c3822 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 2 Jun 2021 15:55:21 +0800 Subject: InteractionResultHolder -> CompoundEventResult --- .../registry/display/DisplayRegistryImpl.java | 8 ++++---- .../client/registry/screen/ScreenRegistryImpl.java | 21 ++++++++++----------- .../rei/impl/common/compat/LBASupportPlugin.java | 8 +++----- .../impl/common/fluid/FluidSupportProviderImpl.java | 14 ++++++-------- .../plugin/client/DefaultClientRuntimePlugin.java | 6 +++--- 5 files changed, 26 insertions(+), 31 deletions(-) (limited to 'runtime/src/main') diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java index 6459963bc..fb5186dc1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.registry.display; +import dev.architectury.event.EventResult; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; @@ -33,7 +34,6 @@ import me.shedaniel.rei.api.client.registry.display.visibility.DisplayVisibility import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.impl.common.registry.RecipeManagerContextImpl; -import net.minecraft.world.InteractionResult; import net.minecraft.world.item.crafting.Recipe; import org.apache.commons.lang3.mutable.MutableInt; @@ -114,9 +114,9 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl category = (DisplayCategory) CategoryRegistry.getInstance().get(display.getCategoryIdentifier()).getCategory(); for (DisplayVisibilityPredicate predicate : visibilityPredicates) { try { - InteractionResult result = predicate.handleDisplay(category, display); - if (result != InteractionResult.PASS) { - return result == InteractionResult.SUCCESS; + EventResult result = predicate.handleDisplay(category, display); + if (result.interruptsFurtherEvaluation()) { + return result.isEmpty() || result.isTrue(); } } catch (Throwable throwable) { RoughlyEnoughItemsCore.LOGGER.error("Failed to check if the recipe is visible!", throwable); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java index 72aae4b0a..0577de76e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/screen/ScreenRegistryImpl.java @@ -26,6 +26,7 @@ package me.shedaniel.rei.impl.client.registry.screen; import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import com.mojang.blaze3d.platform.Window; +import dev.architectury.event.CompoundEventResult; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.config.DisplayPanelLocation; @@ -46,7 +47,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.world.InteractionResult; -import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.inventory.AbstractContainerMenu; import org.apache.commons.lang3.mutable.Mutable; import org.apache.commons.lang3.mutable.MutableObject; @@ -128,12 +128,12 @@ public class ScreenRegistryImpl implements ScreenRegistry { @Override public EntryStack getFocusedStack(T screen, Point mouse) { for (FocusedStackProvider provider : focusedStackProviders) { - InteractionResultHolder> result = Objects.requireNonNull(provider.provide(screen, mouse)); - if (result.getResult() == InteractionResult.SUCCESS) { - if (result != null && !result.getObject().isEmpty()) - return result.getObject(); + CompoundEventResult> result = Objects.requireNonNull(provider.provide(screen, mouse)); + if (result.isTrue()) { + if (result != null && !result.object().isEmpty()) + return result.object(); return null; - } else if (result.getResult() == InteractionResult.FAIL) + } else if (result.isFalse()) return null; } @@ -249,13 +249,12 @@ public class ScreenRegistryImpl implements ScreenRegistry { }); registerFocusedStack(new FocusedStackProvider() { @Override - public InteractionResultHolder> provide(Screen screen, Point mouse) { - if (screen instanceof AbstractContainerScreen) { - AbstractContainerScreen containerScreen = (AbstractContainerScreen) screen; + public CompoundEventResult> provide(Screen screen, Point mouse) { + if (screen instanceof AbstractContainerScreen containerScreen) { if (containerScreen.hoveredSlot != null && !containerScreen.hoveredSlot.getItem().isEmpty()) - return InteractionResultHolder.success(EntryStacks.of(containerScreen.hoveredSlot.getItem())); + return CompoundEventResult.interruptTrue(EntryStacks.of(containerScreen.hoveredSlot.getItem())); } - return InteractionResultHolder.pass(EntryStack.empty()); + return CompoundEventResult.pass(); } @Override diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/compat/LBASupportPlugin.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/compat/LBASupportPlugin.java index eba988a5d..fac34a62b 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/compat/LBASupportPlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/compat/LBASupportPlugin.java @@ -26,13 +26,11 @@ package me.shedaniel.rei.impl.common.compat; import alexiil.mc.lib.attributes.fluid.FluidAttributes; import alexiil.mc.lib.attributes.fluid.GroupedFluidInvView; import alexiil.mc.lib.attributes.fluid.amount.FluidAmount; +import dev.architectury.event.CompoundEventResult; import dev.architectury.hooks.fluid.FluidStackHooks; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; import me.shedaniel.rei.api.common.plugins.REIServerPlugin; import me.shedaniel.rei.api.common.util.EntryStacks; -import net.minecraft.world.InteractionResultHolder; - -import java.util.stream.Stream; public class LBASupportPlugin implements REIServerPlugin { @Override @@ -40,13 +38,13 @@ public class LBASupportPlugin implements REIServerPlugin { support.register(entry -> { GroupedFluidInvView view = FluidAttributes.GROUPED_INV_VIEW.get(entry.getValue()); if (view.getStoredFluids().size() > 0) - return InteractionResultHolder.success(view.getStoredFluids().stream() + return CompoundEventResult.interruptTrue(view.getStoredFluids().stream() .filter(fluidKey -> !fluidKey.isEmpty() && fluidKey.getRawFluid() != null) .map(fluidKey -> { FluidAmount amount = view.getAmount_F(fluidKey); return EntryStacks.of(fluidKey.getRawFluid(), amount.mul(FluidStackHooks.bucketAmount()).asLong(1)); })); - return InteractionResultHolder.pass(Stream.empty()); + return CompoundEventResult.pass(); }); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/fluid/FluidSupportProviderImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/fluid/FluidSupportProviderImpl.java index 4ed074f25..00ae2d0c4 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/fluid/FluidSupportProviderImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/fluid/FluidSupportProviderImpl.java @@ -25,12 +25,11 @@ package me.shedaniel.rei.impl.common.fluid; import com.google.common.collect.ForwardingList; import com.google.common.collect.Lists; +import dev.architectury.event.CompoundEventResult; import dev.architectury.fluid.FluidStack; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.fluid.FluidSupportProvider; import me.shedaniel.rei.api.common.plugins.REIPlugin; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -65,12 +64,11 @@ public class FluidSupportProviderImpl extends ForwardingList>> itemToFluids(EntryStack stack) { if (stack.isEmpty()) return Optional.empty(); for (Provider provider : providers) { - InteractionResultHolder<@Nullable Stream>> resultHolder = Objects.requireNonNull(provider.itemToFluid(stack)); - Stream> stream = resultHolder.getObject(); - if (stream != null) { - if (resultHolder.getResult().consumesAction()) { - return Optional.of(stream); - } else if (resultHolder.getResult() == InteractionResult.FAIL) { + CompoundEventResult<@Nullable Stream>> resultHolder = Objects.requireNonNull(provider.itemToFluid(stack)); + if (resultHolder.interruptsFurtherEvaluation()) { + if (resultHolder.isTrue()) { + return Optional.of(resultHolder.object()); + } else { return Optional.empty(); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java index ee03470e0..397fcb04e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientRuntimePlugin.java @@ -25,6 +25,7 @@ package me.shedaniel.rei.plugin.client; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; +import dev.architectury.event.CompoundEventResult; import dev.architectury.fluid.FluidStack; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; @@ -67,7 +68,6 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.TextComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.InteractionResult; -import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import org.jetbrains.annotations.ApiStatus; @@ -91,9 +91,9 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { registry.registerBridge(VanillaEntryTypes.ITEM, VanillaEntryTypes.FLUID, input -> { Optional>> stream = FluidSupportProvider.getInstance().itemToFluids(input); if (!stream.isPresent()) { - return InteractionResultHolder.pass(Stream.empty()); + return CompoundEventResult.pass(); } - return InteractionResultHolder.success(stream.get()); + return CompoundEventResult.interruptTrue(stream.get()); }); } -- cgit