diff --git a/CHANGELOG.md b/CHANGELOG.md index 6faa8e9e4..fc98875fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Ability to differentiate between insert and extract storage priorities. By default, the extract priority will match the insert priority unless configured otherwise. + ### Fixed - Fixed External Fluid not connecting properly to fluid storages. diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/AutocrafterPrioritySideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/AutocrafterPrioritySideButtonWidget.java new file mode 100644 index 000000000..e5841a42f --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/AutocrafterPrioritySideButtonWidget.java @@ -0,0 +1,61 @@ +package com.refinedmods.refinedstorage.common.autocrafting.autocrafter; + +import com.refinedmods.refinedstorage.common.support.amount.PriorityScreen; +import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; + +import java.util.List; + +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; + +class AutocrafterPrioritySideButtonWidget extends AbstractSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "priority"); + private static final Component HELP = createTranslation("gui", "priority.autocrafter_help"); + private static final ResourceLocation SPRITE = createIdentifier("widget/side_button/priority"); + + private final ClientProperty property; + + AutocrafterPrioritySideButtonWidget(final ClientProperty property, + final Inventory playerInventory, + final Screen parent) { + super(createPressAction(property, playerInventory, parent)); + this.property = property; + } + + private static OnPress createPressAction(final ClientProperty property, + final Inventory playerInventory, + final Screen parent) { + return btn -> Minecraft.getInstance().setScreen( + new PriorityScreen(TITLE, property.get(), property::setValue, parent, playerInventory) + ); + } + + @Override + protected ResourceLocation getSprite() { + return SPRITE; + } + + @Override + protected MutableComponent getTitle() { + return TITLE; + } + + @Override + protected List getSubText() { + return List.of(Component.literal(String.valueOf(property.getValue())).withStyle(ChatFormatting.GRAY)); + } + + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/AutocrafterScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/AutocrafterScreen.java index ac8e67b6a..db1122fc0 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/AutocrafterScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/AutocrafterScreen.java @@ -6,7 +6,6 @@ import com.refinedmods.refinedstorage.common.support.AbstractFilterScreen; import com.refinedmods.refinedstorage.common.support.tooltip.HelpClientTooltipComponent; import com.refinedmods.refinedstorage.common.support.widget.History; -import com.refinedmods.refinedstorage.common.support.widget.PrioritySideButtonWidget; import com.refinedmods.refinedstorage.common.support.widget.SearchFieldWidget; import com.refinedmods.refinedstorage.common.support.widget.TextMarquee; @@ -108,7 +107,7 @@ protected void init() { }); addSideButton(new LockModeSideButtonWidget(getMenu().getProperty(AutocrafterPropertyTypes.LOCK_MODE))); - addSideButton(PrioritySideButtonWidget.forCrafter( + addSideButton(new AutocrafterPrioritySideButtonWidget( getMenu().getProperty(AutocrafterPropertyTypes.PRIORITY), playerInventory, this diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/LockModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/LockModeSideButtonWidget.java index 77bea2ee8..d775acfda 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/LockModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/LockModeSideButtonWidget.java @@ -3,6 +3,9 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -30,22 +33,24 @@ class LockModeSideButtonWidget extends AbstractSideButtonWidget { "widget/side_button/autocrafter/lock_mode/lock_until_low_redstone_signal" ); - private static final MutableComponent NEVER_TITLE = createTranslation("gui", PREFIX + ".never"); - private static final MutableComponent LOCK_UNTIL_REDSTONE_PULSE_RECEIVED_TITLE = createTranslation( - "gui", PREFIX + ".lock_until_redstone_pulse_received" + private static final List NEVER_TITLE = List.of( + createTranslation("gui", PREFIX + ".never").withStyle(ChatFormatting.GRAY) ); - private static final MutableComponent LOCK_UNTIL_CONNECTED_MACHINE_IS_EMPTY_TITLE = createTranslation( + private static final List LOCK_UNTIL_REDSTONE_PULSE_RECEIVED_TITLE = List.of(createTranslation( + "gui", PREFIX + ".lock_until_redstone_pulse_received" + ).withStyle(ChatFormatting.GRAY)); + private static final List LOCK_UNTIL_CONNECTED_MACHINE_IS_EMPTY_TITLE = List.of(createTranslation( "gui", PREFIX + ".lock_until_connected_machine_is_empty" - ); - private static final MutableComponent LOCK_UNTIL_ALL_OUTPUTS_ARE_RECEIVED_TITLE = createTranslation( + ).withStyle(ChatFormatting.GRAY)); + private static final List LOCK_UNTIL_ALL_OUTPUTS_ARE_RECEIVED_TITLE = List.of(createTranslation( "gui", PREFIX + ".lock_until_all_outputs_are_received" - ); - private static final MutableComponent LOCK_UNTIL_HIGH_REDSTONE_SIGNAL_TITLE = createTranslation( + ).withStyle(ChatFormatting.GRAY)); + private static final List LOCK_UNTIL_HIGH_REDSTONE_SIGNAL_TITLE = List.of(createTranslation( "gui", PREFIX + ".lock_until_high_redstone_signal" - ); - private static final MutableComponent LOCK_UNTIL_LOW_REDSTONE_SIGNAL_TITLE = createTranslation( + ).withStyle(ChatFormatting.GRAY)); + private static final List LOCK_UNTIL_LOW_REDSTONE_SIGNAL_TITLE = List.of(createTranslation( "gui", PREFIX + ".lock_until_low_redstone_signal" - ); + ).withStyle(ChatFormatting.GRAY)); private final ClientProperty property; @@ -76,7 +81,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (property.getValue()) { case NEVER -> NEVER_TITLE; case LOCK_UNTIL_REDSTONE_PULSE_RECEIVED -> LOCK_UNTIL_REDSTONE_PULSE_RECEIVED_TITLE; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/VisibleToTheAutocrafterManagerSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/VisibleToTheAutocrafterManagerSideButtonWidget.java index ef6d4f2d9..440ca6882 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/VisibleToTheAutocrafterManagerSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocrafter/VisibleToTheAutocrafterManagerSideButtonWidget.java @@ -3,8 +3,6 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; import com.refinedmods.refinedstorage.common.support.widget.AbstractYesNoSideButtonWidget; -import javax.annotation.Nullable; - import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -26,7 +24,6 @@ class VisibleToTheAutocrafterManagerSideButtonWidget extends AbstractYesNoSideBu super(property, TITLE, YES, NO); } - @Nullable @Override protected Component getHelpText() { return HELP; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java index 2cdef6a5d..203077ed4 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/SearchModeSideButtonWidget.java @@ -2,8 +2,10 @@ import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; import java.util.function.Supplier; +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -13,13 +15,18 @@ class SearchModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "autocrafter_manager.search_mode"); - private static final MutableComponent SUBTEXT_ALL = createTranslation("gui", "autocrafter_manager.search_mode.all"); - private static final MutableComponent SUBTEXT_PATTERN_INPUTS = - createTranslation("gui", "autocrafter_manager.search_mode.pattern_inputs"); - private static final MutableComponent SUBTEXT_PATTERN_OUTPUTS = - createTranslation("gui", "autocrafter_manager.search_mode.pattern_outputs"); - private static final MutableComponent SUBTEXT_AUTOCRAFTER_NAMES = - createTranslation("gui", "autocrafter_manager.search_mode.autocrafter_names"); + private static final List SUBTEXT_ALL = List.of( + createTranslation("gui", "autocrafter_manager.search_mode.all").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_PATTERN_INPUTS = List.of( + createTranslation("gui", "autocrafter_manager.search_mode.pattern_inputs").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_PATTERN_OUTPUTS = List.of( + createTranslation("gui", "autocrafter_manager.search_mode.pattern_outputs").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_AUTOCRAFTER_NAMES = List.of( + createTranslation("gui", "autocrafter_manager.search_mode.autocrafter_names").withStyle(ChatFormatting.GRAY) + ); private static final ResourceLocation SPRITE_ALL = createIdentifier("widget/side_button/autocrafter_manager/search_mode/all"); private static final ResourceLocation SPRITE_PATTERN_INPUTS = @@ -59,7 +66,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (containerMenu.getSearchMode()) { case ALL -> SUBTEXT_ALL; case PATTERN_INPUTS -> SUBTEXT_PATTERN_INPUTS; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/ViewTypeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/ViewTypeSideButtonWidget.java index 9cf4c022a..f4bbd9275 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/ViewTypeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/autocrafting/autocraftermanager/ViewTypeSideButtonWidget.java @@ -2,6 +2,9 @@ import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -11,16 +14,19 @@ class ViewTypeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "autocrafter_manager.view_type"); - private static final MutableComponent SUBTEXT_VISIBLE = - createTranslation("gui", "autocrafter_manager.view_type.visible"); + private static final List SUBTEXT_VISIBLE = List.of( + createTranslation("gui", "autocrafter_manager.view_type.visible").withStyle(ChatFormatting.GRAY) + ); private static final MutableComponent HELP_VISIBLE = createTranslation("gui", "autocrafter_manager.view_type.visible.help"); - private static final MutableComponent SUBTEXT_NOT_FULL = - createTranslation("gui", "autocrafter_manager.view_type.not_full"); + private static final List SUBTEXT_NOT_FULL = List.of( + createTranslation("gui", "autocrafter_manager.view_type.not_full").withStyle(ChatFormatting.GRAY) + ); private static final MutableComponent HELP_NOT_FULL = createTranslation("gui", "autocrafter_manager.view_type.not_full.help"); - private static final MutableComponent SUBTEXT_ALL = - createTranslation("gui", "autocrafter_manager.view_type.all"); + private static final List SUBTEXT_ALL = List.of( + createTranslation("gui", "autocrafter_manager.view_type.all").withStyle(ChatFormatting.GRAY) + ); private static final MutableComponent HELP_ALL = createTranslation("gui", "autocrafter_manager.view_type.all.help"); private static final ResourceLocation SPRITE_VISIBLE = @@ -56,7 +62,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (containerMenu.getViewType()) { case VISIBLE -> SUBTEXT_VISIBLE; case NOT_FULL -> SUBTEXT_NOT_FULL; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorModeSideButtonWidget.java index c8bb167ad..d6b24bfc6 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/detector/DetectorModeSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -12,9 +15,15 @@ class DetectorModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "detector.mode"); - private static final MutableComponent SUBTEXT_EQUAL = createTranslation("gui", "detector.mode.equal"); - private static final MutableComponent SUBTEXT_ABOVE = createTranslation("gui", "detector.mode.above"); - private static final MutableComponent SUBTEXT_UNDER = createTranslation("gui", "detector.mode.under"); + private static final List SUBTEXT_EQUAL = List.of( + createTranslation("gui", "detector.mode.equal").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_ABOVE = List.of( + createTranslation("gui", "detector.mode.above").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_UNDER = List.of( + createTranslation("gui", "detector.mode.under").withStyle(ChatFormatting.GRAY) + ); private static final ResourceLocation EQUAL = createIdentifier("widget/side_button/detector_mode/equal"); private static final ResourceLocation ABOVE = createIdentifier("widget/side_button/detector_mode/above"); private static final ResourceLocation UNDER = createIdentifier("widget/side_button/detector_mode/under"); @@ -53,7 +62,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (property.getValue()) { case UNDER -> SUBTEXT_UNDER; case EQUAL -> SUBTEXT_EQUAL; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ResourceTypeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ResourceTypeSideButtonWidget.java index ef800fb44..f7a889eb7 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ResourceTypeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ResourceTypeSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -12,7 +15,8 @@ class ResourceTypeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "grid.resource_type"); - private static final MutableComponent SUBTEXT_ALL = createTranslation("gui", "grid.resource_type.all"); + private static final List SUBTEXT_ALL = + List.of(createTranslation("gui", "grid.resource_type.all").withStyle(ChatFormatting.GRAY)); private static final ResourceLocation ALL = createIdentifier("widget/side_button/resource_type/all"); private final AbstractGridContainerMenu menu; @@ -41,11 +45,11 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { final ResourceType resourceType = menu.getResourceType(); if (resourceType == null) { return SUBTEXT_ALL; } - return resourceType.getTitle(); + return List.of(resourceType.getTitle().withStyle(ChatFormatting.GRAY)); } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingDirectionSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingDirectionSideButtonWidget.java index ccf8999da..fe59cdd5d 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingDirectionSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingDirectionSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -12,10 +15,10 @@ class SortingDirectionSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "grid.sorting.direction"); - private static final MutableComponent SUBTEXT_ASCENDING = - createTranslation("gui", "grid.sorting.direction.ascending"); - private static final MutableComponent SUBTEXT_DESCENDING = - createTranslation("gui", "grid.sorting.direction.descending"); + private static final List SUBTEXT_ASCENDING = List.of( + createTranslation("gui", "grid.sorting.direction.ascending").withStyle(ChatFormatting.GRAY)); + private static final List SUBTEXT_DESCENDING = List.of( + createTranslation("gui", "grid.sorting.direction.descending").withStyle(ChatFormatting.GRAY)); private static final ResourceLocation ASCENDING = createIdentifier("widget/side_button/grid/sorting_direction/ascending"); private static final ResourceLocation DESCENDING = @@ -49,7 +52,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (menu.getSortingDirection()) { case ASCENDING -> SUBTEXT_ASCENDING; case DESCENDING -> SUBTEXT_DESCENDING; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingTypeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingTypeSideButtonWidget.java index 8337db028..62e0f2e22 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingTypeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SortingTypeSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.grid.GridSortingTypes; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -12,11 +15,18 @@ class SortingTypeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "grid.sorting.type"); - private static final MutableComponent SUBTEXT_QUANTITY = createTranslation("gui", "grid.sorting.type.quantity"); - private static final MutableComponent SUBTEXT_NAME = createTranslation("gui", "grid.sorting.type.name"); - private static final MutableComponent SUBTEXT_ID = createTranslation("gui", "grid.sorting.type.id"); - private static final MutableComponent SUBTEXT_LAST_MODIFIED = - createTranslation("gui", "grid.sorting.type.last_modified"); + private static final List SUBTEXT_QUANTITY = List.of( + createTranslation("gui", "grid.sorting.type.quantity").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_NAME = List.of( + createTranslation("gui", "grid.sorting.type.name").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_ID = List.of( + createTranslation("gui", "grid.sorting.type.id").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_LAST_MODIFIED = List.of( + createTranslation("gui", "grid.sorting.type.last_modified").withStyle(ChatFormatting.GRAY) + ); private static final ResourceLocation QUANTITY = createIdentifier("widget/side_button/grid/sorting_type/quantity"); private static final ResourceLocation NAME = createIdentifier("widget/side_button/grid/sorting_type/name"); private static final ResourceLocation ID = createIdentifier("widget/side_button/grid/sorting_type/id"); @@ -59,7 +69,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (menu.getSortingType()) { case QUANTITY -> SUBTEXT_QUANTITY; case NAME -> SUBTEXT_NAME; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SynchronizationModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SynchronizationModeSideButtonWidget.java index 3f811f5ca..d3255a7f4 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SynchronizationModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/SynchronizationModeSideButtonWidget.java @@ -3,6 +3,9 @@ import com.refinedmods.refinedstorage.common.grid.AbstractGridContainerMenu; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -34,8 +37,8 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { - return menu.getSynchronizer().getTitle(); + protected List getSubText() { + return List.of(menu.getSynchronizer().getTitle().withStyle(ChatFormatting.GRAY)); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ViewTypeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ViewTypeSideButtonWidget.java index 16c7badf6..372cb8e93 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ViewTypeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/grid/screen/ViewTypeSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.grid.GridViewType; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -12,11 +15,15 @@ class ViewTypeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "grid.view_type"); - private static final MutableComponent SUBTEXT_ALL = createTranslation("gui", "grid.view_type.all"); - private static final MutableComponent SUBTEXT_AUTOCRAFTABLE = - createTranslation("gui", "grid.view_type.autocraftable"); - private static final MutableComponent SUBTEXT_NON_AUTOCRAFTABLE = - createTranslation("gui", "grid.view_type.non_autocraftable"); + private static final List SUBTEXT_ALL = List.of( + createTranslation("gui", "grid.view_type.all").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_AUTOCRAFTABLE = List.of( + createTranslation("gui", "grid.view_type.autocraftable").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_NON_AUTOCRAFTABLE = List.of( + createTranslation("gui", "grid.view_type.non_autocraftable").withStyle(ChatFormatting.GRAY) + ); private static final ResourceLocation ALL = createIdentifier("widget/side_button/grid/view_type/all"); private static final ResourceLocation CRAFTABLE = createIdentifier("widget/side_button/grid/view_type/autocraftable"); @@ -57,7 +64,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (menu.getViewType()) { case ALL -> SUBTEXT_ALL; case AUTOCRAFTABLE -> SUBTEXT_AUTOCRAFTABLE; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java index 24a84c0ef..2898b7ab3 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayBlockEntity.java @@ -48,7 +48,8 @@ public class RelayBlockEntity extends AbstractBaseNetworkNodeContainerBlockEntit private static final String TAG_PASS_AUTOCRAFTING = "passautocrafting"; private static final String TAG_FILTER_MODE = "fim"; private static final String TAG_ACCESS_MODE = "am"; - private static final String TAG_PRIORITY = "pri"; + private static final String TAG_INSERT_PRIORITY = "pri"; + private static final String TAG_EXTRACT_PRIORITY = "epri"; private final FilterWithFuzzyMode filter; private final RelayOutputNetworkNode outputNode; @@ -56,7 +57,8 @@ public class RelayBlockEntity extends AbstractBaseNetworkNodeContainerBlockEntit private boolean passThrough = true; private FilterMode filterMode = FilterMode.BLOCK; private AccessMode accessMode = AccessMode.INSERT_EXTRACT; - private int priority = 0; + private int insertPriority = 0; + private int extractPriority = 0; public RelayBlockEntity(final BlockPos pos, final BlockState state) { super(BlockEntities.INSTANCE.getRelay(), pos, state, new RelayInputNetworkNode( @@ -101,13 +103,23 @@ private void filterContainerChanged(final Set filters) { setChanged(); } - int getPriority() { - return priority; + int getInsertPriority() { + return insertPriority; } - void setPriority(final int priority) { - this.priority = priority; - this.mainNetworkNode.setPriority(priority); + void setInsertPriority(final int insertPriority) { + this.insertPriority = insertPriority; + this.mainNetworkNode.setInsertPriority(insertPriority); + setChanged(); + } + + int getExtractPriority() { + return extractPriority; + } + + void setExtractPriority(final int extractPriority) { + this.extractPriority = extractPriority; + this.mainNetworkNode.setExtractPriority(extractPriority); setChanged(); } @@ -233,7 +245,8 @@ public void writeConfiguration(final CompoundTag tag, final HolderLookup.Provide tag.putBoolean(TAG_PASS_SECURITY, mainNetworkNode.hasComponentType(RelayComponentType.SECURITY)); tag.putBoolean(TAG_PASS_AUTOCRAFTING, mainNetworkNode.hasComponentType(RelayComponentType.AUTOCRAFTING)); tag.putInt(TAG_ACCESS_MODE, AccessModeSettings.getAccessMode(accessMode)); - tag.putInt(TAG_PRIORITY, priority); + tag.putInt(TAG_INSERT_PRIORITY, insertPriority); + tag.putInt(TAG_EXTRACT_PRIORITY, extractPriority); } @Override @@ -252,10 +265,16 @@ public void readConfiguration(final CompoundTag tag, final HolderLookup.Provider accessMode = AccessModeSettings.getAccessMode(tag.getInt(TAG_ACCESS_MODE)); } mainNetworkNode.setAccessMode(accessMode); - if (tag.contains(TAG_PRIORITY)) { - priority = tag.getInt(TAG_PRIORITY); + if (tag.contains(TAG_INSERT_PRIORITY)) { + insertPriority = tag.getInt(TAG_INSERT_PRIORITY); + } + mainNetworkNode.setInsertPriority(insertPriority); + if (tag.contains(TAG_EXTRACT_PRIORITY)) { + extractPriority = tag.getInt(TAG_EXTRACT_PRIORITY); + } else { + extractPriority = insertPriority; // bit of compat } - mainNetworkNode.setPriority(priority); + mainNetworkNode.setExtractPriority(extractPriority); } private Set> getComponentTypes(final CompoundTag tag) { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java index cf0cf88e6..3b2e97cb5 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayContainerMenu.java @@ -100,7 +100,8 @@ protected void onChangedOnClient(final Boolean newValue) { }); registerProperty(new ClientProperty<>(PropertyTypes.FILTER_MODE, FilterMode.BLOCK)); registerProperty(new ClientProperty<>(StoragePropertyTypes.ACCESS_MODE, AccessMode.INSERT_EXTRACT)); - registerProperty(new ClientProperty<>(StoragePropertyTypes.PRIORITY, 0)); + registerProperty(new ClientProperty<>(StoragePropertyTypes.INSERT_PRIORITY, 0)); + registerProperty(new ClientProperty<>(StoragePropertyTypes.EXTRACT_PRIORITY, 0)); registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); } @@ -147,9 +148,14 @@ protected void registerServerProperties(final RelayBlockEntity blockEntity) { blockEntity::setAccessMode )); registerProperty(new ServerProperty<>( - StoragePropertyTypes.PRIORITY, - blockEntity::getPriority, - blockEntity::setPriority + StoragePropertyTypes.INSERT_PRIORITY, + blockEntity::getInsertPriority, + blockEntity::setInsertPriority + )); + registerProperty(new ServerProperty<>( + StoragePropertyTypes.EXTRACT_PRIORITY, + blockEntity::getExtractPriority, + blockEntity::setExtractPriority )); registerProperty(new ServerProperty<>( PropertyTypes.FUZZY_MODE, diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java index 848997dca..d84ea9d62 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/networking/RelayScreen.java @@ -7,7 +7,7 @@ import com.refinedmods.refinedstorage.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; import com.refinedmods.refinedstorage.common.support.widget.FuzzyModeSideButtonWidget; -import com.refinedmods.refinedstorage.common.support.widget.PrioritySideButtonWidget; +import com.refinedmods.refinedstorage.common.support.widget.StoragePrioritySideButtonWidget; import javax.annotation.Nullable; @@ -114,8 +114,9 @@ private void addStorageButtons(final boolean visible) { accessModeButton.visible = visible; addSideButton(accessModeButton); - priorityButton = PrioritySideButtonWidget.forStorage( - getMenu().getProperty(StoragePropertyTypes.PRIORITY), + priorityButton = new StoragePrioritySideButtonWidget( + getMenu().getProperty(StoragePropertyTypes.INSERT_PRIORITY), + getMenu().getProperty(StoragePropertyTypes.EXTRACT_PRIORITY), playerInventory, this ); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageContainerMenu.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageContainerMenu.java index e1a01a0b8..bfd0092ee 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageContainerMenu.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageContainerMenu.java @@ -14,7 +14,8 @@ public abstract class AbstractStorageContainerMenu extends AbstractResourceContainerMenu { protected AbstractStorageContainerMenu(final MenuType type, final int syncId) { super(type, syncId); - registerProperty(new ClientProperty<>(StoragePropertyTypes.PRIORITY, 0)); + registerProperty(new ClientProperty<>(StoragePropertyTypes.INSERT_PRIORITY, 0)); + registerProperty(new ClientProperty<>(StoragePropertyTypes.EXTRACT_PRIORITY, 0)); registerProperty(new ClientProperty<>(PropertyTypes.FILTER_MODE, FilterMode.BLOCK)); registerProperty(new ClientProperty<>(PropertyTypes.FUZZY_MODE, false)); registerProperty(new ClientProperty<>(StoragePropertyTypes.ACCESS_MODE, AccessMode.INSERT_EXTRACT)); @@ -28,9 +29,14 @@ protected AbstractStorageContainerMenu(final MenuType type, final StorageConfigurationContainer configContainer) { super(type, syncId, player); registerProperty(new ServerProperty<>( - StoragePropertyTypes.PRIORITY, - configContainer::getPriority, - configContainer::setPriority + StoragePropertyTypes.INSERT_PRIORITY, + configContainer::getInsertPriority, + configContainer::setInsertPriority + )); + registerProperty(new ServerProperty<>( + StoragePropertyTypes.EXTRACT_PRIORITY, + configContainer::getExtractPriority, + configContainer::setExtractPriority )); registerProperty(new ServerProperty<>( PropertyTypes.FILTER_MODE, diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageScreen.java index f45e3fd1d..dae757f08 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AbstractStorageScreen.java @@ -3,8 +3,8 @@ import com.refinedmods.refinedstorage.common.support.AbstractBaseScreen; import com.refinedmods.refinedstorage.common.support.containermenu.PropertyTypes; import com.refinedmods.refinedstorage.common.support.widget.FuzzyModeSideButtonWidget; -import com.refinedmods.refinedstorage.common.support.widget.PrioritySideButtonWidget; import com.refinedmods.refinedstorage.common.support.widget.RedstoneModeSideButtonWidget; +import com.refinedmods.refinedstorage.common.support.widget.StoragePrioritySideButtonWidget; import javax.annotation.Nullable; @@ -48,8 +48,9 @@ protected void init() { () -> FuzzyModeSideButtonWidget.Type.STORAGE )); addSideButton(new AccessModeSideButtonWidget(getMenu().getProperty(StoragePropertyTypes.ACCESS_MODE))); - addSideButton(PrioritySideButtonWidget.forStorage( - getMenu().getProperty(StoragePropertyTypes.PRIORITY), + addSideButton(new StoragePrioritySideButtonWidget( + getMenu().getProperty(StoragePropertyTypes.INSERT_PRIORITY), + getMenu().getProperty(StoragePropertyTypes.EXTRACT_PRIORITY), playerInventory, this )); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AccessModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AccessModeSideButtonWidget.java index 54ea2f77b..5c23f1fa0 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AccessModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/AccessModeSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -13,10 +16,12 @@ public class AccessModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "access_mode"); - private static final MutableComponent SUBTEXT_INSERT = createTranslation("gui", "access_mode.insert"); - private static final MutableComponent SUBTEXT_EXTRACT = createTranslation("gui", "access_mode.extract"); - private static final MutableComponent SUBTEXT_INSERT_EXTRACT = - createTranslation("gui", "access_mode.insert_extract"); + private static final List SUBTEXT_INSERT = + List.of(createTranslation("gui", "access_mode.insert").withStyle(ChatFormatting.GRAY)); + private static final List SUBTEXT_EXTRACT = + List.of(createTranslation("gui", "access_mode.extract").withStyle(ChatFormatting.GRAY)); + private static final List SUBTEXT_INSERT_EXTRACT = + List.of(createTranslation("gui", "access_mode.insert_extract").withStyle(ChatFormatting.GRAY)); private static final Component HELP_INSERT = createTranslation("gui", "access_mode.insert.help"); private static final Component HELP_EXTRACT = @@ -62,7 +67,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (property.getValue()) { case INSERT_EXTRACT -> SUBTEXT_INSERT_EXTRACT; case INSERT -> SUBTEXT_INSERT; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/FilterModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/FilterModeSideButtonWidget.java index 3fe64c6fe..daf115b9a 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/FilterModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/FilterModeSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -13,8 +16,12 @@ public class FilterModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "filter_mode"); - private static final MutableComponent SUBTEXT_BLOCK = createTranslation("gui", "filter_mode.block"); - private static final MutableComponent SUBTEXT_ALLOW = createTranslation("gui", "filter_mode.allow"); + private static final List SUBTEXT_BLOCK = List.of( + createTranslation("gui", "filter_mode.block").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_ALLOW = List.of( + createTranslation("gui", "filter_mode.allow").withStyle(ChatFormatting.GRAY) + ); private static final Component FILTER_MODE_WARNING = createTranslation("gui", "storage.filter_mode.empty_warning"); private static final ResourceLocation ALLOW = createIdentifier("widget/side_button/storage/filter_mode/allow"); private static final ResourceLocation BLOCK = createIdentifier("widget/side_button/storage/filter_mode/block"); @@ -59,7 +66,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return property.getValue() == FilterMode.BLOCK ? SUBTEXT_BLOCK : SUBTEXT_ALLOW; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainer.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainer.java index 1ddf6fa8f..854e090aa 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainer.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainer.java @@ -5,9 +5,13 @@ import com.refinedmods.refinedstorage.common.support.RedstoneMode; public interface StorageConfigurationContainer { - int getPriority(); + int getInsertPriority(); - void setPriority(int priority); + void setInsertPriority(int insertPriority); + + int getExtractPriority(); + + void setExtractPriority(int extractPriority); FilterMode getFilterMode(); diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainerImpl.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainerImpl.java index e544a6ba0..c2636c7e9 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainerImpl.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StorageConfigurationContainerImpl.java @@ -13,7 +13,8 @@ import net.minecraft.nbt.CompoundTag; public final class StorageConfigurationContainerImpl implements StorageConfigurationContainer { - private static final String TAG_PRIORITY = "pri"; + private static final String TAG_INSERT_PRIORITY = "pri"; + private static final String TAG_EXTRACT_PRIORITY = "epri"; private static final String TAG_FILTER_MODE = "fim"; private static final String TAG_ACCESS_MODE = "am"; private static final String TAG_VOID_EXCESS = "ve"; @@ -37,8 +38,13 @@ public StorageConfigurationContainerImpl(final StorageConfiguration config, } public void load(final CompoundTag tag) { - if (tag.contains(TAG_PRIORITY)) { - config.setPriority(tag.getInt(TAG_PRIORITY)); + if (tag.contains(TAG_INSERT_PRIORITY)) { + config.setInsertPriority(tag.getInt(TAG_INSERT_PRIORITY)); + } + if (tag.contains(TAG_EXTRACT_PRIORITY)) { + config.setExtractPriority(tag.getInt(TAG_EXTRACT_PRIORITY)); + } else { + config.setExtractPriority(config.getInsertPriority()); // bit of compat } if (tag.contains(TAG_FILTER_MODE)) { config.setFilterMode(FilterModeSettings.getFilterMode(tag.getInt(TAG_FILTER_MODE))); @@ -53,19 +59,31 @@ public void load(final CompoundTag tag) { public void save(final CompoundTag tag) { tag.putInt(TAG_FILTER_MODE, FilterModeSettings.getFilterMode(config.getFilterMode())); - tag.putInt(TAG_PRIORITY, config.getPriority()); + tag.putInt(TAG_INSERT_PRIORITY, config.getInsertPriority()); + tag.putInt(TAG_EXTRACT_PRIORITY, config.getExtractPriority()); tag.putInt(TAG_ACCESS_MODE, AccessModeSettings.getAccessMode(config.getAccessMode())); tag.putBoolean(TAG_VOID_EXCESS, config.isVoidExcess()); } @Override - public int getPriority() { - return config.getPriority(); + public int getInsertPriority() { + return config.getInsertPriority(); + } + + @Override + public void setInsertPriority(final int insertPriority) { + config.setInsertPriority(insertPriority); + listener.run(); + } + + @Override + public int getExtractPriority() { + return config.getExtractPriority(); } @Override - public void setPriority(final int priority) { - config.setPriority(priority); + public void setExtractPriority(final int extractPriority) { + config.setExtractPriority(extractPriority); listener.run(); } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StoragePropertyTypes.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StoragePropertyTypes.java index a388d1c6e..e5f8a0beb 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StoragePropertyTypes.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/StoragePropertyTypes.java @@ -7,8 +7,11 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; public final class StoragePropertyTypes { - public static final PropertyType PRIORITY = PropertyTypes.createIntegerProperty( - createIdentifier("priority") + public static final PropertyType INSERT_PRIORITY = PropertyTypes.createIntegerProperty( + createIdentifier("insert_priority") + ); + public static final PropertyType EXTRACT_PRIORITY = PropertyTypes.createIntegerProperty( + createIdentifier("extract_priority") ); public static final PropertyType ACCESS_MODE = new PropertyType<>( diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/TransferModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/TransferModeSideButtonWidget.java index c7de37a81..b776d5bfa 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/TransferModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/diskinterface/TransferModeSideButtonWidget.java @@ -4,6 +4,9 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -13,10 +16,12 @@ class TransferModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "disk_interface.transfer_mode"); - private static final MutableComponent SUBTEXT_INSERT_INTO_NETWORK = - createTranslation("gui", "disk_interface.transfer_mode.insert_into_network"); - private static final MutableComponent SUBTEXT_EXTRACT_FROM_NETWORK = - createTranslation("gui", "disk_interface.transfer_mode.extract_from_network"); + private static final List SUBTEXT_INSERT_INTO_NETWORK = List.of( + createTranslation("gui", "disk_interface.transfer_mode.insert_into_network").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_EXTRACT_FROM_NETWORK = List.of( + createTranslation("gui", "disk_interface.transfer_mode.extract_from_network").withStyle(ChatFormatting.GRAY) + ); private static final Component HELP_INSERT_INTO_NETWORK = createTranslation("gui", "disk_interface.transfer_mode.insert_into_network.help"); private static final Component HELP_EXTRACT_FROM_NETWORK = @@ -58,7 +63,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (property.getValue()) { case INSERT_INTO_NETWORK -> SUBTEXT_INSERT_INTO_NETWORK; case EXTRACT_FROM_NETWORK -> SUBTEXT_EXTRACT_FROM_NETWORK; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/externalstorage/AbstractExternalStorageBlockEntity.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/externalstorage/AbstractExternalStorageBlockEntity.java index adc39467e..d1be9647f 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/externalstorage/AbstractExternalStorageBlockEntity.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/storage/externalstorage/AbstractExternalStorageBlockEntity.java @@ -167,7 +167,7 @@ void setAccessMode(final AccessMode accessMode) { } void setPriority(final int priority) { - mainNetworkNode.getStorageConfiguration().setPriority(priority); + mainNetworkNode.getStorageConfiguration().setInsertPriority(priority); } void setVoidExcess(final boolean voidExcess) { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/PriorityScreen.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/PriorityScreen.java index 2e008372c..76c72f713 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/PriorityScreen.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/amount/PriorityScreen.java @@ -1,6 +1,6 @@ package com.refinedmods.refinedstorage.common.support.amount; -import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import java.util.function.IntConsumer; import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.MutableComponent; @@ -9,24 +9,24 @@ import org.joml.Vector3f; import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; public class PriorityScreen extends AbstractAmountScreen { private static final ResourceLocation TEXTURE = createIdentifier("textures/gui/priority.png"); - private static final MutableComponent PRIORITY_TEXT = createTranslation("gui", "priority"); - private final ClientProperty property; + private final IntConsumer priorityChanged; - public PriorityScreen(final ClientProperty property, + public PriorityScreen(final MutableComponent title, + final int priority, + final IntConsumer priorityChanged, final Screen parent, final Inventory playerInventory) { super( new DefaultDummyContainerMenu(), parent, playerInventory, - PRIORITY_TEXT, + title, AmountScreenConfiguration.AmountScreenConfigurationBuilder.create() - .withInitialAmount(property.get()) + .withInitialAmount(priority) .withIncrementsTop(1, 5, 10) .withIncrementsBottom(-1, -5, -10) .withAmountFieldPosition(new Vector3f(19, 48, 0)) @@ -37,14 +37,14 @@ public PriorityScreen(final ClientProperty property, .build(), IntegerAmountOperations.INSTANCE ); - this.property = property; + this.priorityChanged = priorityChanged; this.imageWidth = 164; this.imageHeight = 92; } @Override protected boolean confirm(final Integer amount) { - property.setValue(amount); + priorityChanged.accept(amount); return true; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/stretching/ScreenSizeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/stretching/ScreenSizeSideButtonWidget.java index 168e523d8..8277a045e 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/stretching/ScreenSizeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/stretching/ScreenSizeSideButtonWidget.java @@ -3,6 +3,9 @@ import com.refinedmods.refinedstorage.common.Platform; import com.refinedmods.refinedstorage.common.support.widget.AbstractSideButtonWidget; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -11,11 +14,21 @@ public class ScreenSizeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "screen_size"); - private static final MutableComponent SUBTEXT_STRETCH = createTranslation("gui", "screen_size.stretch"); - private static final MutableComponent SUBTEXT_SMALL = createTranslation("gui", "screen_size.small"); - private static final MutableComponent SUBTEXT_MEDIUM = createTranslation("gui", "screen_size.medium"); - private static final MutableComponent SUBTEXT_LARGE = createTranslation("gui", "screen_size.large"); - private static final MutableComponent SUBTEXT_EXTRA_LARGE = createTranslation("gui", "screen_size.extra_large"); + private static final List SUBTEXT_STRETCH = List.of( + createTranslation("gui", "screen_size.stretch").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_SMALL = List.of( + createTranslation("gui", "screen_size.small").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_MEDIUM = List.of( + createTranslation("gui", "screen_size.medium").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_LARGE = List.of( + createTranslation("gui", "screen_size.large").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_EXTRA_LARGE = List.of( + createTranslation("gui", "screen_size.extra_large").withStyle(ChatFormatting.GRAY) + ); private static final ResourceLocation STRETCH = createIdentifier("widget/side_button/screen_size/stretch"); private static final ResourceLocation SMALL = createIdentifier("widget/side_button/screen_size/small"); private static final ResourceLocation MEDIUM = createIdentifier("widget/side_button/screen_size/medium"); @@ -49,7 +62,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { final ScreenSize screenSize = Platform.INSTANCE.getConfig().getScreenSize(); return switch (screenSize) { case STRETCH -> SUBTEXT_STRETCH; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java index 0a5630782..383de68f9 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractSideButtonWidget.java @@ -96,10 +96,7 @@ protected List buildTooltip() { getTitle().getVisualOrderText() ); lines.add(title); - final ClientTooltipComponent subText = ClientTooltipComponent.create( - getSubText().withStyle(ChatFormatting.GRAY).getVisualOrderText() - ); - lines.add(subText); + getSubText().forEach(line -> lines.add(ClientTooltipComponent.create(line.getVisualOrderText()))); if (warning != null) { lines.add(warning); } @@ -112,7 +109,7 @@ protected List buildTooltip() { protected abstract MutableComponent getTitle(); - protected abstract MutableComponent getSubText(); + protected abstract List getSubText(); @Nullable protected Component getHelpText() { diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractYesNoSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractYesNoSideButtonWidget.java index eb1d5ee19..5a87639ff 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractYesNoSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AbstractYesNoSideButtonWidget.java @@ -2,6 +2,9 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -9,6 +12,9 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.YES; public abstract class AbstractYesNoSideButtonWidget extends AbstractSideButtonWidget { + private static final List YES_LINES = List.of(YES.copy().withStyle(ChatFormatting.GRAY)); + private static final List NO_LINES = List.of(NO.copy().withStyle(ChatFormatting.GRAY)); + private final ClientProperty property; private final MutableComponent title; private final ResourceLocation yesSprite; @@ -40,7 +46,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { - return Boolean.TRUE.equals(property.getValue()) ? YES : NO; + protected List getSubText() { + return Boolean.TRUE.equals(property.getValue()) ? YES_LINES : NO_LINES; } } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AutoSelectedSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AutoSelectedSideButtonWidget.java index 7a0c8dec2..db2f0ecbd 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AutoSelectedSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/AutoSelectedSideButtonWidget.java @@ -3,6 +3,9 @@ import com.refinedmods.refinedstorage.common.Platform; import com.refinedmods.refinedstorage.common.util.IdentifierUtil; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -11,6 +14,13 @@ import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; public class AutoSelectedSideButtonWidget extends AbstractSideButtonWidget { + private static final List YES_LINES = List.of( + IdentifierUtil.YES.copy().withStyle(ChatFormatting.GRAY) + ); + private static final List NO_LINES = List.of( + IdentifierUtil.NO.copy().withStyle(ChatFormatting.GRAY) + ); + private static final MutableComponent TITLE = createTranslation("gui", "search_box_auto_selected"); private static final ResourceLocation YES = createIdentifier("widget/side_button/search_box_auto_selected/yes"); private static final ResourceLocation NO = createIdentifier("widget/side_button/search_box_auto_selected/no"); @@ -39,8 +49,8 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { - return Platform.INSTANCE.getConfig().isSearchBoxAutoSelected() ? IdentifierUtil.YES : IdentifierUtil.NO; + protected List getSubText() { + return Platform.INSTANCE.getConfig().isSearchBoxAutoSelected() ? YES_LINES : NO_LINES; } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/FuzzyModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/FuzzyModeSideButtonWidget.java index f8ed65a81..cd572e5ab 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/FuzzyModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/FuzzyModeSideButtonWidget.java @@ -2,8 +2,10 @@ import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import java.util.List; import java.util.function.Supplier; +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -13,8 +15,12 @@ public class FuzzyModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "fuzzy_mode"); - private static final MutableComponent SUBTEXT_ON = createTranslation("gui", "fuzzy_mode.on"); - private static final MutableComponent SUBTEXT_OFF = createTranslation("gui", "fuzzy_mode.off"); + private static final List SUBTEXT_ON = List.of( + createTranslation("gui", "fuzzy_mode.on").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_OFF = List.of( + createTranslation("gui", "fuzzy_mode.off").withStyle(ChatFormatting.GRAY) + ); private static final ResourceLocation ON = createIdentifier("widget/side_button/fuzzy_mode/on"); private static final ResourceLocation OFF = createIdentifier("widget/side_button/fuzzy_mode/off"); @@ -42,7 +48,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return Boolean.TRUE.equals(property.getValue()) ? SUBTEXT_ON : SUBTEXT_OFF; } diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/PrioritySideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/PrioritySideButtonWidget.java deleted file mode 100644 index 494b76bef..000000000 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/PrioritySideButtonWidget.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.refinedmods.refinedstorage.common.support.widget; - -import com.refinedmods.refinedstorage.common.support.amount.PriorityScreen; -import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; - -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.player.Inventory; - -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; -import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; - -public class PrioritySideButtonWidget extends AbstractSideButtonWidget { - private static final MutableComponent TITLE = createTranslation("gui", "priority"); - private static final Component STORAGE_HELP = createTranslation("gui", "priority.storage_help"); - private static final Component CRAFTER_HELP = createTranslation("gui", "priority.crafter_help"); - private static final ResourceLocation SPRITE = createIdentifier("widget/side_button/priority"); - - private final ClientProperty property; - private final Component helpText; - - private PrioritySideButtonWidget(final ClientProperty property, - final Inventory playerInventory, - final Screen parent, - final Component helpText) { - super(createPressAction(property, playerInventory, parent)); - this.property = property; - this.helpText = helpText; - } - - public static PrioritySideButtonWidget forStorage(final ClientProperty property, - final Inventory playerInventory, - final Screen parent) { - return new PrioritySideButtonWidget(property, playerInventory, parent, STORAGE_HELP); - } - - public static PrioritySideButtonWidget forCrafter(final ClientProperty property, - final Inventory playerInventory, - final Screen parent) { - return new PrioritySideButtonWidget(property, playerInventory, parent, CRAFTER_HELP); - } - - private static OnPress createPressAction(final ClientProperty property, - final Inventory playerInventory, - final Screen parent) { - return btn -> Minecraft.getInstance().setScreen(new PriorityScreen(property, parent, playerInventory)); - } - - @Override - protected ResourceLocation getSprite() { - return SPRITE; - } - - @Override - protected MutableComponent getTitle() { - return TITLE; - } - - @Override - protected MutableComponent getSubText() { - return Component.literal(String.valueOf(property.getValue())); - } - - @Override - protected Component getHelpText() { - return helpText; - } -} diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/RedstoneModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/RedstoneModeSideButtonWidget.java index d24739d26..971f39228 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/RedstoneModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/RedstoneModeSideButtonWidget.java @@ -3,8 +3,10 @@ import com.refinedmods.refinedstorage.common.support.RedstoneMode; import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import java.util.List; import javax.annotation.Nullable; +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -14,9 +16,15 @@ public class RedstoneModeSideButtonWidget extends AbstractSideButtonWidget { private static final MutableComponent TITLE = createTranslation("gui", "redstone_mode"); - private static final MutableComponent SUBTEXT_IGNORE = createTranslation("gui", "redstone_mode.ignore"); - private static final MutableComponent SUBTEXT_HIGH = createTranslation("gui", "redstone_mode.high"); - private static final MutableComponent SUBTEXT_LOW = createTranslation("gui", "redstone_mode.low"); + private static final List SUBTEXT_IGNORE = List.of( + createTranslation("gui", "redstone_mode.ignore").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_HIGH = List.of( + createTranslation("gui", "redstone_mode.high").withStyle(ChatFormatting.GRAY) + ); + private static final List SUBTEXT_LOW = List.of( + createTranslation("gui", "redstone_mode.low").withStyle(ChatFormatting.GRAY) + ); private static final Component HELP_IGNORE = createTranslation("gui", "redstone_mode.ignore.help"); private static final Component HELP_HIGH = createTranslation("gui", "redstone_mode.high.help"); private static final Component HELP_LOW = createTranslation("gui", "redstone_mode.low.help"); @@ -61,7 +69,7 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { + protected List getSubText() { return switch (property.getValue()) { case IGNORE -> SUBTEXT_IGNORE; case HIGH -> SUBTEXT_HIGH; diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SchedulingModeSideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SchedulingModeSideButtonWidget.java index 4127b10c3..b67f460be 100644 --- a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SchedulingModeSideButtonWidget.java +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/SchedulingModeSideButtonWidget.java @@ -3,6 +3,9 @@ import com.refinedmods.refinedstorage.common.support.SchedulingModeType; import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; +import java.util.List; + +import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import net.minecraft.resources.ResourceLocation; @@ -51,8 +54,8 @@ protected MutableComponent getTitle() { } @Override - protected MutableComponent getSubText() { - return property.getValue().getName(); + protected List getSubText() { + return List.of(property.getValue().getName().copy().withStyle(ChatFormatting.GRAY)); } @Override diff --git a/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/StoragePrioritySideButtonWidget.java b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/StoragePrioritySideButtonWidget.java new file mode 100644 index 000000000..86537ab53 --- /dev/null +++ b/refinedstorage-common/src/main/java/com/refinedmods/refinedstorage/common/support/widget/StoragePrioritySideButtonWidget.java @@ -0,0 +1,113 @@ +package com.refinedmods.refinedstorage.common.support.widget; + +import com.refinedmods.refinedstorage.common.support.amount.PriorityScreen; +import com.refinedmods.refinedstorage.common.support.containermenu.ClientProperty; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.function.IntConsumer; + +import net.minecraft.ChatFormatting; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.MutableComponent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.player.Inventory; + +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createIdentifier; +import static com.refinedmods.refinedstorage.common.util.IdentifierUtil.createTranslation; +import static net.minecraft.client.gui.screens.Screen.hasAltDown; +import static net.minecraft.client.gui.screens.Screen.hasControlDown; + +public class StoragePrioritySideButtonWidget extends AbstractSideButtonWidget { + private static final MutableComponent TITLE = createTranslation("gui", "priority"); + private static final MutableComponent INSERT_EXTRACT_TITLE = createTranslation("gui", "insert_extract_priority"); + private static final MutableComponent INSERT_TITLE = createTranslation("gui", "insert_priority"); + private static final MutableComponent EXTRACT_TITLE = createTranslation("gui", "extract_priority"); + private static final Component HELP = createTranslation("gui", "priority.storage_help"); + private static final ResourceLocation SPRITE = createIdentifier("widget/side_button/priority"); + + private final ClientProperty insertProperty; + private final ClientProperty extractProperty; + + public StoragePrioritySideButtonWidget(final ClientProperty insertProperty, + final ClientProperty extractProperty, + final Inventory playerInventory, + final Screen parent) { + super(createPressAction(insertProperty, extractProperty, playerInventory, parent)); + this.insertProperty = insertProperty; + this.extractProperty = extractProperty; + } + + private static OnPress createPressAction(final ClientProperty insertProperty, + final ClientProperty extractProperty, + final Inventory playerInventory, + final Screen parent) { + return btn -> { + final MutableComponent title; + final int priority; + final IntConsumer listener; + if (isModifyingInsert()) { + title = INSERT_TITLE; + priority = insertProperty.get(); + listener = insertProperty::setValue; + } else if (isModifyingExtract()) { + title = EXTRACT_TITLE; + priority = extractProperty.get(); + listener = extractProperty::setValue; + } else { + title = INSERT_EXTRACT_TITLE; + priority = insertProperty.get(); + listener = value -> { + insertProperty.setValue(value); + extractProperty.setValue(value); + }; + } + Minecraft.getInstance().setScreen(new PriorityScreen(title, priority, listener, parent, playerInventory)); + }; + } + + @Override + protected ResourceLocation getSprite() { + return SPRITE; + } + + @Override + protected MutableComponent getTitle() { + return TITLE; + } + + @Override + protected List getSubText() { + final List subText = new ArrayList<>(); + final boolean modifyingInsert = isModifyingInsert(); + final boolean modifyingExtract = isModifyingExtract(); + if (Objects.equals(insertProperty.getValue(), extractProperty.getValue()) + && !modifyingInsert + && !modifyingExtract) { + subText.add(createTranslation("gui", "priority.insert_extract", insertProperty.getValue()) + .withStyle(ChatFormatting.GRAY)); + } else { + subText.add(createTranslation("gui", "priority.insert", insertProperty.getValue()) + .withStyle(modifyingInsert ? ChatFormatting.YELLOW : ChatFormatting.GRAY)); + subText.add(createTranslation("gui", "priority.extract", extractProperty.getValue()) + .withStyle(!modifyingInsert && modifyingExtract ? ChatFormatting.YELLOW : ChatFormatting.GRAY)); + } + return subText; + } + + private static boolean isModifyingInsert() { + return hasControlDown(); + } + + private static boolean isModifyingExtract() { + return hasAltDown(); + } + + @Override + protected Component getHelpText() { + return HELP; + } +} diff --git a/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json b/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json index 15ec7c0ff..5ec7d5adc 100644 --- a/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json +++ b/refinedstorage-common/src/main/resources/assets/refinedstorage/lang/en_us.json @@ -130,8 +130,14 @@ "gui.refinedstorage.scheduling_mode.random": "Random", "gui.refinedstorage.scheduling_mode.random.help": "Use a random filter.", "gui.refinedstorage.priority": "Priority", - "gui.refinedstorage.priority.storage_help": "The order in which the storage network will insert or extract resources, highest-first.", - "gui.refinedstorage.priority.crafter_help": "If multiple patterns exist for one resource, crafting tasks will prioritize the pattern in the autocrafter with the highest priority.", + "gui.refinedstorage.insert_extract_priority": "Insert/extract priority", + "gui.refinedstorage.insert_priority": "Insert priority", + "gui.refinedstorage.extract_priority": "Extract priority", + "gui.refinedstorage.priority.insert_extract": "Insert/extract: %d", + "gui.refinedstorage.priority.insert": "Insert: %d", + "gui.refinedstorage.priority.extract": "Extract: %d", + "gui.refinedstorage.priority.storage_help": "The order in which the storage network will insert or extract resources, highest-first. Click to modify the insert/extract priority. Press CTRL and click to modify the insert priority. Press ALT and click to modify the extract priority.", + "gui.refinedstorage.priority.autocrafter_help": "If multiple patterns exist for one resource, crafting tasks will prioritize the pattern in the autocrafter with the highest priority.", "gui.refinedstorage.configure_amount": "Configure amount", "gui.refinedstorage.configure_amount.reset": "Reset", "gui.refinedstorage.configure_amount.set": "Set", diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java index 734b82bff..7620f09f7 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayInputNetworkNode.java @@ -73,9 +73,15 @@ public void setAccessMode(final AccessMode accessMode) { } } - public void setPriority(final int priority) { + public void setInsertPriority(final int insertPriority) { if (outputNode != null) { - outputNode.setPriority(priority); + outputNode.setInsertPriority(insertPriority); + } + } + + public void setExtractPriority(final int extractPriority) { + if (outputNode != null) { + outputNode.setExtractPriority(extractPriority); } } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java index a4ef2b8a2..9424bb9c5 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputNetworkNode.java @@ -57,8 +57,15 @@ void setAccessMode(final AccessMode accessMode) { this.storage.setAccessMode(accessMode); } - void setPriority(final int priority) { - this.storage.setPriority(priority); + void setInsertPriority(final int insertPriority) { + this.storage.setInsertPriority(insertPriority); + if (network != null) { + network.getComponent(StorageNetworkComponent.class).sortSources(); + } + } + + void setExtractPriority(final int extractPriority) { + this.storage.setExtractPriority(extractPriority); if (network != null) { network.getComponent(StorageNetworkComponent.class).sortSources(); } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputStorage.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputStorage.java index 836b1001a..10f191028 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputStorage.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayOutputStorage.java @@ -29,7 +29,8 @@ class RelayOutputStorage implements CompositeAwareChild, ResourceListListener, P @Nullable private StorageNetworkComponent delegate; private AccessMode accessMode = AccessMode.INSERT_EXTRACT; - private int priority; + private int insertPriority; + private int extractPriority; boolean hasDelegate() { return delegate != null; @@ -39,8 +40,12 @@ void setAccessMode(final AccessMode accessMode) { this.accessMode = accessMode; } - void setPriority(final int priority) { - this.priority = priority; + void setInsertPriority(final int insertPriority) { + this.insertPriority = insertPriority; + } + + void setExtractPriority(final int extractPriority) { + this.extractPriority = extractPriority; } void setFilters(final Set filters) { @@ -175,7 +180,12 @@ public void onChanged(final MutableResourceList.OperationResult change) { } @Override - public int getPriority() { - return priority; + public int getInsertPriority() { + return insertPriority; + } + + @Override + public int getExtractPriority() { + return extractPriority; } } diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/AbstractConfiguredProxyStorage.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/AbstractConfiguredProxyStorage.java index eac3f8872..f4f7797de 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/AbstractConfiguredProxyStorage.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/AbstractConfiguredProxyStorage.java @@ -84,8 +84,13 @@ public long getStored() { } @Override - public int getPriority() { - return config.getPriority(); + public int getInsertPriority() { + return config.getInsertPriority(); + } + + @Override + public int getExtractPriority() { + return config.getExtractPriority(); } protected S getDelegate() { diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/NetworkNodeStorageConfiguration.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/NetworkNodeStorageConfiguration.java index d2ede1e4c..5b95c775c 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/NetworkNodeStorageConfiguration.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/NetworkNodeStorageConfiguration.java @@ -15,7 +15,8 @@ public class NetworkNodeStorageConfiguration implements StorageConfiguration { private final AbstractNetworkNode node; private final Filter filter = new Filter(); - private int priority; + private int insertPriority; + private int extractPriority; private AccessMode accessMode = AccessMode.INSERT_EXTRACT; private boolean voidExcess; @@ -69,8 +70,14 @@ public void setFilterMode(final FilterMode filterMode) { } @Override - public void setPriority(final int priority) { - this.priority = priority; + public void setInsertPriority(final int insertPriority) { + this.insertPriority = insertPriority; + trySortSources(); + } + + @Override + public void setExtractPriority(final int extractPriority) { + this.extractPriority = extractPriority; trySortSources(); } @@ -84,8 +91,13 @@ private void trySortSources() { } @Override - public int getPriority() { - return priority; + public int getInsertPriority() { + return insertPriority; + } + + @Override + public int getExtractPriority() { + return extractPriority; } @Override diff --git a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageConfiguration.java b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageConfiguration.java index e878d2880..e6c6533ed 100644 --- a/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageConfiguration.java +++ b/refinedstorage-network/src/main/java/com/refinedmods/refinedstorage/api/network/impl/storage/StorageConfiguration.java @@ -30,7 +30,9 @@ public interface StorageConfiguration extends PriorityProvider { void setFilterMode(FilterMode filterMode); - void setPriority(int priority); + void setInsertPriority(int insertPriority); + + void setExtractPriority(int extractPriority); boolean isActive(); } diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java index f0cbd3de8..89d46e10d 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/externalstorage/ExternalStorageNetworkNodeTest.java @@ -58,7 +58,7 @@ void testInitialState(@InjectNetworkStorageComponent final StorageNetworkCompone assertThat(extracted).isZero(); assertThat(sut.getStorageConfiguration().getAccessMode()).isEqualTo(AccessMode.INSERT_EXTRACT); assertThat(sut.getEnergyUsage()).isEqualTo(ENERGY_USAGE); - assertThat(sut.getStorageConfiguration().getPriority()).isZero(); + assertThat(sut.getStorageConfiguration().getInsertPriority()).isZero(); assertThat(sut.getStorageConfiguration().getFilterMode()).isEqualTo(FilterMode.BLOCK); assertThat(networkStorage.getAll()).isEmpty(); assertThat(networkStorage.getStored()).isZero(); @@ -649,11 +649,11 @@ void shouldRespectPriority(final boolean oneHasPriority, otherStorage.initialize(new ExternalStorageProviderFactoryImpl(provider2)); if (oneHasPriority) { - sut.getStorageConfiguration().setPriority(5); - otherStorage.getStorageConfiguration().setPriority(2); + sut.getStorageConfiguration().setInsertPriority(5); + otherStorage.getStorageConfiguration().setInsertPriority(2); } else { - sut.getStorageConfiguration().setPriority(2); - otherStorage.getStorageConfiguration().setPriority(5); + sut.getStorageConfiguration().setInsertPriority(2); + otherStorage.getStorageConfiguration().setInsertPriority(5); } // Act diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java index 133a1c205..78135c04e 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayNetworkNodeTest.java @@ -86,7 +86,7 @@ void shouldNotPassComponentsIfOutputNodeIsNotSet( addPattern(inputAutocrafting, A); input.setAccessMode(AccessMode.INSERT_EXTRACT); - input.setPriority(5); + input.setInsertPriority(5); input.setFilters(Set.of(A, B, C)); // Act diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java index 538df1919..c3cf5f873 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/relay/RelayStorageNetworkNodeTest.java @@ -278,36 +278,67 @@ void shouldNotExtractInInsertOnlyMode( } @Test - void shouldRespectPriorityOfOutput( + void shouldRespectInsertPriorityOfOutput( @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setOutputNode(output); - input.setPriority(3); + input.setInsertPriority(3); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.addSource(new LimitedStorageImpl(10)); + + final Storage fallbackStorage1 = PriorityStorage.of(new LimitedStorageImpl(10), 2, 1); + outputStorage.addSource(fallbackStorage1); + + final Storage fallbackStorage2 = PriorityStorage.of(new LimitedStorageImpl(10), 1, 2); + outputStorage.addSource(fallbackStorage2); + + // Act + final long inserted = outputStorage.insert(A, 12, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(inserted).isEqualTo(12); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 10) + ); + assertThat(fallbackStorage1.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 2) + ); + assertThat(fallbackStorage2.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); + } + + @Test + void shouldRespectExtractPriorityOfOutput( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setExtractPriority(3); input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); inputStorage.addSource(new StorageImpl()); inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); - final Storage fallbackStorage1 = PriorityStorage.of(new StorageImpl(), 2); + final Storage fallbackStorage1 = PriorityStorage.of(new StorageImpl(), 2, 1); fallbackStorage1.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); outputStorage.addSource(fallbackStorage1); - final Storage fallbackStorage2 = PriorityStorage.of(new StorageImpl(), 1); + final Storage fallbackStorage2 = PriorityStorage.of(new StorageImpl(), 1, 2); fallbackStorage2.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); outputStorage.addSource(fallbackStorage2); // Act - final long inserted = outputStorage.insert(A, 2, Action.EXECUTE, EmptyActor.INSTANCE); final long extracted = outputStorage.extract(A, 3, Action.EXECUTE, EmptyActor.INSTANCE); // Assert - assertThat(inserted).isEqualTo(2); assertThat(extracted).isEqualTo(3); assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( - new ResourceAmount(A, 9) + new ResourceAmount(A, 7) ); assertThat(fallbackStorage1.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) @@ -318,25 +349,25 @@ void shouldRespectPriorityOfOutput( } @Test - void shouldModifyPriorityOfOutput( + void shouldModifyInsertPriorityOfOutput( @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage ) { // Arrange input.setActive(true); input.setOutputNode(output); - input.setPriority(3); + input.setInsertPriority(3); input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); inputStorage.addSource(new LimitedStorageImpl(10)); - final Storage fallbackStorage1 = PriorityStorage.of(new LimitedStorageImpl(5), 1); + final Storage fallbackStorage1 = PriorityStorage.of(new LimitedStorageImpl(5), 1, 3); outputStorage.addSource(fallbackStorage1); - final Storage fallbackStorage2 = PriorityStorage.of(new LimitedStorageImpl(5), 3); + final Storage fallbackStorage2 = PriorityStorage.of(new LimitedStorageImpl(5), 3, 1); outputStorage.addSource(fallbackStorage2); // Act - input.setPriority(2); + input.setInsertPriority(2); // Assert final long inserted = outputStorage.insert(A, 7, Action.EXECUTE, EmptyActor.INSTANCE); @@ -354,6 +385,43 @@ void shouldModifyPriorityOfOutput( ); } + @Test + void shouldModifyExtractPriorityOfOutput( + @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, + @InjectNetworkStorageComponent(networkId = "output") final StorageNetworkComponent outputStorage + ) { + // Arrange + input.setActive(true); + input.setOutputNode(output); + input.setExtractPriority(4); + input.setComponentTypes(Set.of(RelayComponentType.STORAGE)); + inputStorage.addSource(new LimitedStorageImpl(10)); + inputStorage.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); + + final Storage fallbackStorage1 = PriorityStorage.of(new LimitedStorageImpl(5), 1, 3); + fallbackStorage1.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); + outputStorage.addSource(fallbackStorage1); + + final Storage fallbackStorage2 = PriorityStorage.of(new LimitedStorageImpl(5), 3, 1); + fallbackStorage2.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); + outputStorage.addSource(fallbackStorage2); + + // Act + input.setExtractPriority(2); + final long extracted = outputStorage.extract(A, 6, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(extracted).isEqualTo(6); + + assertThat(inputStorage.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 9) + ); + assertThat(fallbackStorage1.getAll()).usingRecursiveFieldByFieldElementComparator().isEmpty(); + assertThat(fallbackStorage2.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 5) + ); + } + @Test void shouldRespectBlocklistFilter( @InjectNetworkStorageComponent(networkId = "input") final StorageNetworkComponent inputStorage, diff --git a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java index 63ddf20b3..dab057d5b 100644 --- a/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java +++ b/refinedstorage-network/src/test/java/com/refinedmods/refinedstorage/api/network/impl/node/storage/PriorityStorageNetworkNodeTest.java @@ -54,11 +54,11 @@ void shouldRespectPriority( b.setActive(true); if (storageAHasPriority) { - a.getStorageConfiguration().setPriority(5); - b.getStorageConfiguration().setPriority(2); + a.getStorageConfiguration().setInsertPriority(5); + b.getStorageConfiguration().setInsertPriority(2); } else { - a.getStorageConfiguration().setPriority(2); - b.getStorageConfiguration().setPriority(5); + a.getStorageConfiguration().setInsertPriority(2); + b.getStorageConfiguration().setInsertPriority(5); } // Act diff --git a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImpl.java b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImpl.java index 8bd73f4a3..3d71adddc 100644 --- a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImpl.java +++ b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImpl.java @@ -25,7 +25,8 @@ */ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public class CompositeStorageImpl implements CompositeStorage, CompositeAwareChild, ParentComposite { - private final List sources = new ArrayList<>(); + private final List insertSources = new ArrayList<>(); + private final List extractSources = new ArrayList<>(); private final MutableResourceList list; private final Set parentComposites = new HashSet<>(); @@ -38,12 +39,14 @@ public CompositeStorageImpl(final MutableResourceList list) { @Override public void sortSources() { - sources.sort(PrioritizedStorageComparator.INSTANCE); + insertSources.sort(PrioritizedStorageComparator.INSERT); + extractSources.sort(PrioritizedStorageComparator.EXTRACT); } @Override public void addSource(final Storage source) { - sources.add(source); + insertSources.add(source); + extractSources.add(source); sortSources(); addContentOfSourceToList(source); parentComposites.forEach(parentComposite -> parentComposite.onSourceAddedToChild(source)); @@ -54,7 +57,8 @@ public void addSource(final Storage source) { @Override public void removeSource(final Storage source) { - sources.remove(source); + insertSources.remove(source); + extractSources.remove(source); // Re-sort isn't necessary, since they are ordered when added. removeContentOfSourceFromList(source); parentComposites.forEach(parentComposite -> parentComposite.onSourceRemovedFromChild(source)); @@ -65,18 +69,18 @@ public void removeSource(final Storage source) { @Override public List getSources() { - return Collections.unmodifiableList(sources); + return Collections.unmodifiableList(insertSources); } @Override public void clearSources() { - final Set oldSources = new HashSet<>(sources); + final Set oldSources = new HashSet<>(insertSources); oldSources.forEach(this::removeSource); } @Override public boolean contains(final Storage storage) { - for (final Storage source : sources) { + for (final Storage source : insertSources) { if (source instanceof CompositeAwareChild compositeAwareChild && compositeAwareChild.contains(storage)) { return true; } @@ -88,7 +92,7 @@ public boolean contains(final Storage storage) { public long extract(final ResourceKey resource, final long amount, final Action action, final Actor actor) { long remaining = amount; long toRemoveFromList = 0; - for (final Storage source : sources) { + for (final Storage source : extractSources) { if (source instanceof CompositeAwareChild compositeAwareChild) { final Amount extracted = compositeAwareChild.compositeExtract(resource, remaining, action, actor); remaining -= extracted.amount(); @@ -113,7 +117,7 @@ public long extract(final ResourceKey resource, final long amount, final Action public long insert(final ResourceKey resource, final long amount, final Action action, final Actor actor) { long inserted = 0; long toInsertIntoList = 0; - for (final Storage source : sources) { + for (final Storage source : insertSources) { if (source instanceof CompositeAwareChild compositeAwareChild) { final Amount insertedAmount = compositeAwareChild.compositeInsert( resource, @@ -145,13 +149,13 @@ public Collection getAll() { @Override public long getStored() { - return sources.stream().mapToLong(Storage::getStored).sum(); + return insertSources.stream().mapToLong(Storage::getStored).sum(); } @Override public Optional findTrackedResourceByActorType(final ResourceKey resource, final Class actorType) { - return sources + return insertSources .stream() .filter(TrackedStorage.class::isInstance) .map(TrackedStorage.class::cast) diff --git a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PrioritizedStorageComparator.java b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PrioritizedStorageComparator.java index c92d604e0..238e5001a 100644 --- a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PrioritizedStorageComparator.java +++ b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PrioritizedStorageComparator.java @@ -5,17 +5,29 @@ import java.util.Comparator; class PrioritizedStorageComparator implements Comparator { - static final Comparator INSTANCE = new PrioritizedStorageComparator(); + static final Comparator INSERT = new PrioritizedStorageComparator(PriorityProvider::getInsertPriority); + static final Comparator EXTRACT = new PrioritizedStorageComparator(PriorityProvider::getExtractPriority); - private static int getPriority(final Storage storage) { + private final PriorityExtractor priorityExtractor; + + private PrioritizedStorageComparator(final PriorityExtractor priorityExtractor) { + this.priorityExtractor = priorityExtractor; + } + + private int extractPriority(final Storage storage) { if (storage instanceof PriorityProvider priorityProvider) { - return priorityProvider.getPriority(); + return priorityExtractor.getPriority(priorityProvider); } return 0; } @Override public int compare(final Storage a, final Storage b) { - return Integer.compare(getPriority(b), getPriority(a)); + return Integer.compare(extractPriority(b), extractPriority(a)); + } + + @FunctionalInterface + private interface PriorityExtractor { + int getPriority(PriorityProvider provider); } } diff --git a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityProvider.java b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityProvider.java index c30797e59..a81212289 100644 --- a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityProvider.java +++ b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityProvider.java @@ -9,9 +9,16 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.1.0") public interface PriorityProvider { /** - * The priority. Higher priority storages will be inserted into and extracted from first. + * The priority, higher priority storages will be inserted into first. * * @return the priority */ - int getPriority(); + int getInsertPriority(); + + /** + * The priority, higher priority storages will be extracted from first. + * + * @return the priority + */ + int getExtractPriority(); } diff --git a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityStorage.java b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityStorage.java index 75d244def..520a274aa 100644 --- a/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityStorage.java +++ b/refinedstorage-storage-api/src/main/java/com/refinedmods/refinedstorage/api/storage/composite/PriorityStorage.java @@ -7,24 +7,35 @@ @API(status = API.Status.STABLE, since = "2.0.0-milestone.3.6") public class PriorityStorage extends AbstractProxyStorage implements PriorityProvider { - private int priority; + private int insertPriority; + private int extractPriority; - private PriorityStorage(final int priority, final Storage delegate) { + private PriorityStorage(final int insertPriority, final int extractPriority, final Storage delegate) { super(delegate); - this.priority = priority; + this.insertPriority = insertPriority; + this.extractPriority = extractPriority; } - public static PriorityStorage of(final Storage delegate, final int priority) { - return new PriorityStorage(priority, delegate); + public static PriorityStorage of(final Storage delegate, final int insertPriority, final int extractPriority) { + return new PriorityStorage(insertPriority, extractPriority, delegate); } - public void setPriority(final int priority) { - this.priority = priority; + public void setInsertPriority(final int insertPriority) { + this.insertPriority = insertPriority; + } + + public void setExtractPriority(final int extractPriority) { + this.extractPriority = extractPriority; + } + + @Override + public int getInsertPriority() { + return insertPriority; } @Override - public int getPriority() { - return priority; + public int getExtractPriority() { + return extractPriority; } } diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java index 638b30d27..1f2b16f25 100644 --- a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java +++ b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/CompositeStorageImplTest.java @@ -127,11 +127,11 @@ void shouldClearSources() { } @Test - void shouldRespectPriorityWhenAddingNewSources() { + void shouldRespectInsertPriorityWhenAddingNewSources() { // Arrange - final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20); - final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10); - final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30); + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20, 30); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10, 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30, 20); // Act sut.addSource(storage1); @@ -152,11 +152,37 @@ void shouldRespectPriorityWhenAddingNewSources() { } @Test - void shouldRespectPriorityWhenRemovingSources() { + void shouldRespectExtractPriorityWhenAddingNewSources() { // Arrange - final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20); - final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10); - final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30); + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20, 30); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10, 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30, 20); + + // Act + sut.addSource(storage1); + sut.addSource(storage2); + sut.addSource(storage3); + sut.insert(A, 30, Action.EXECUTE, EmptyActor.INSTANCE); + + final long extracted = sut.extract(A, 12, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 18) + ); + assertThat(sut.getSources()).containsExactly(storage3, storage1, storage2); + assertThat(extracted).isEqualTo(12); + assertThat(storage1.getStored()).isZero(); + assertThat(storage3.getStored()).isEqualTo(8); + assertThat(storage2.getStored()).isEqualTo(10); + } + + @Test + void shouldRespectInsertPriorityWhenRemovingSources() { + // Arrange + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20, 30); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10, 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30, 20); sut.addSource(storage1); sut.addSource(storage2); @@ -178,10 +204,37 @@ void shouldRespectPriorityWhenRemovingSources() { } @Test - void shouldOnlyRespectPriorityWhenSortingSourcesExplicitlyWhenChangingPriorityAfterAddingSource() { + void shouldRespectExtractPriorityWhenRemovingSources() { + // Arrange + final Storage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 20, 30); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 10, 10); + final Storage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 30, 20); + + sut.addSource(storage1); + sut.addSource(storage2); + sut.addSource(storage3); + sut.insert(A, 30, Action.EXECUTE, EmptyActor.INSTANCE); + sut.removeSource(storage3); + + // Act + final long extracted = sut.extract(A, 12, Action.EXECUTE, EmptyActor.INSTANCE); + + // Assert + assertThat(sut.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactlyInAnyOrder( + new ResourceAmount(A, 8) + ); + assertThat(sut.getSources()).containsExactly(storage1, storage2); + assertThat(extracted).isEqualTo(12); + assertThat(storage1.getStored()).isZero(); + assertThat(storage2.getStored()).isEqualTo(8); + assertThat(storage3.getStored()).isEqualTo(10); + } + + @Test + void shouldOnlyRespectInsertPriorityWhenSortingSourcesExplicitlyWhenChangingPriorityAfterAddingSource() { // Arrange - final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 1); - final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 2); + final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 1, 2); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 2, 1); sut.addSource(storage1); sut.addSource(storage2); @@ -191,7 +244,7 @@ void shouldOnlyRespectPriorityWhenSortingSourcesExplicitlyWhenChangingPriorityAf assertThat(storage1.getStored()).isZero(); assertThat(storage2.getStored()).isEqualTo(1); - storage1.setPriority(3); + storage1.setInsertPriority(3); sut.insert(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); assertThat(storage1.getStored()).isZero(); @@ -204,6 +257,34 @@ void shouldOnlyRespectPriorityWhenSortingSourcesExplicitlyWhenChangingPriorityAf assertThat(storage2.getStored()).isEqualTo(2); } + @Test + void shouldOnlyRespectExtractPriorityWhenSortingSourcesExplicitlyWhenChangingPriorityAfterAddingSource() { + // Arrange + final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 1, 2); + final Storage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 2, 1); + + sut.addSource(storage1); + sut.addSource(storage2); + sut.insert(A, 20, Action.EXECUTE, EmptyActor.INSTANCE); + + // Act & assert + sut.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + assertThat(storage1.getStored()).isEqualTo(9); + assertThat(storage2.getStored()).isEqualTo(10); + + storage1.setExtractPriority(0); + + sut.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + assertThat(storage1.getStored()).isEqualTo(8); + assertThat(storage2.getStored()).isEqualTo(10); + + sut.sortSources(); + + sut.extract(A, 1, Action.EXECUTE, EmptyActor.INSTANCE); + assertThat(storage1.getStored()).isEqualTo(8); + assertThat(storage2.getStored()).isEqualTo(9); + } + @SuppressWarnings("AssertBetweenInconvertibleTypes") // intellij bug @Test void shouldFindMostRecentChange() { diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/ExtractCompositeStorageImplTest.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/ExtractCompositeStorageImplTest.java index 45227e855..9da90dd22 100644 --- a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/ExtractCompositeStorageImplTest.java +++ b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/ExtractCompositeStorageImplTest.java @@ -281,8 +281,8 @@ void shouldNotExtractWithoutAnySourcesPresent() { @Test void shouldRespectPriorityWhenExtracting() { // Arrange - final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5); - final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10); + final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10, 5); + final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5, 10); lowestPriority.insert(A, 5, Action.EXECUTE, EmptyActor.INSTANCE); highestPriority.insert(A, 10, Action.EXECUTE, EmptyActor.INSTANCE); diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/InsertCompositeStorageImplTest.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/InsertCompositeStorageImplTest.java index 076d100a0..3df3cabbe 100644 --- a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/InsertCompositeStorageImplTest.java +++ b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/composite/InsertCompositeStorageImplTest.java @@ -185,8 +185,8 @@ void shouldNotInsertWithoutAnySourcesPresent() { @Test void shouldRespectPriorityWhenInserting() { // Arrange - final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5); - final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10); + final PriorityStorage lowestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 5, 10); + final PriorityStorage highestPriority = PriorityStorage.of(new LimitedStorageImpl(10), 10, 5); sut.addSource(lowestPriority); sut.addSource(highestPriority); diff --git a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/root/RootStorageImplTest.java b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/root/RootStorageImplTest.java index a8ae7cba2..d562ace60 100644 --- a/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/root/RootStorageImplTest.java +++ b/refinedstorage-storage-api/src/test/java/com/refinedmods/refinedstorage/api/storage/root/RootStorageImplTest.java @@ -258,24 +258,26 @@ void shouldRetrieveTrackedResource() { @Test void shouldSortSources() { // Arrange - final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 0); - final PriorityStorage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 0); - final PriorityStorage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 0); + final PriorityStorage storage1 = PriorityStorage.of(new LimitedStorageImpl(10), 0, 0); + final PriorityStorage storage2 = PriorityStorage.of(new LimitedStorageImpl(10), 0, 0); + final PriorityStorage storage3 = PriorityStorage.of(new LimitedStorageImpl(10), 0, 0); sut.addSource(storage1); sut.addSource(storage2); sut.addSource(storage3); - storage1.setPriority(8); - storage2.setPriority(15); - storage3.setPriority(2); + storage1.setInsertPriority(8); + storage2.setInsertPriority(15); + storage3.setInsertPriority(2); - // Act + storage1.setExtractPriority(8); + storage2.setExtractPriority(2); + storage3.setExtractPriority(15); + + // Act & assert sut.sortSources(); sut.insert(A, 15, Action.EXECUTE, EmptyActor.INSTANCE); - - // Assert assertThat(storage2.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( new ResourceAmount(A, 10) ); @@ -283,5 +285,12 @@ void shouldSortSources() { new ResourceAmount(A, 5) ); assertThat(storage3.getAll()).isEmpty(); + + sut.extract(A, 12, Action.EXECUTE, EmptyActor.INSTANCE); + assertThat(storage2.getAll()).usingRecursiveFieldByFieldElementComparator().containsExactly( + new ResourceAmount(A, 3) + ); + assertThat(storage1.getAll()).isEmpty(); + assertThat(storage3.getAll()).isEmpty(); } }