3131import codechicken .lib .render .pipeline .IVertexOperation ;
3232import codechicken .lib .vec .Cuboid6 ;
3333import codechicken .lib .vec .Matrix4 ;
34+ import com .cleanroommc .modularui .api .drawable .IKey ;
3435import com .cleanroommc .modularui .drawable .Rectangle ;
3536import com .cleanroommc .modularui .factory .SidedPosGuiData ;
3637import com .cleanroommc .modularui .screen .ModularPanel ;
3738import com .cleanroommc .modularui .utils .Alignment ;
39+ import com .cleanroommc .modularui .utils .Color ;
40+ import com .cleanroommc .modularui .value .sync .BooleanSyncValue ;
3841import com .cleanroommc .modularui .value .sync .EnumSyncValue ;
3942import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
4043import com .cleanroommc .modularui .widgets .SlotGroupWidget ;
44+ import com .cleanroommc .modularui .widgets .ToggleButton ;
4145import com .cleanroommc .modularui .widgets .layout .Column ;
46+ import com .cleanroommc .modularui .widgets .layout .Row ;
4247import org .jetbrains .annotations .NotNull ;
4348import org .jetbrains .annotations .Nullable ;
4449
@@ -50,7 +55,8 @@ public class CoverItemFilter extends CoverBase implements CoverWithUI {
5055 protected final SimpleOverlayRenderer texture ;
5156 protected final ItemFilterContainer itemFilterContainer ;
5257 protected ItemFilterMode filterMode = ItemFilterMode .FILTER_INSERT ;
53- protected ItemHandlerFiltered itemHandler ;
58+ protected boolean allowFlow = false ;
59+ protected ItemHandlerDelegate itemHandler ;
5460
5561 public CoverItemFilter (@ NotNull CoverDefinition definition , @ NotNull CoverableView coverableView ,
5662 @ NotNull EnumFacing attachedSide , String titleLocale , SimpleOverlayRenderer texture ) {
@@ -148,14 +154,32 @@ public ModularPanel buildUI(SidedPosGuiData guiData, PanelSyncManager guiSyncMan
148154 guiSyncManager .syncValue ("filtering_mode" , filteringMode );
149155
150156 return getFilter ().createPanel (guiSyncManager )
151- .size (176 , 194 ).padding (7 )
157+ .size (176 , 212 ).padding (7 )
152158 .child (CoverWithUI .createTitleRow (getFilterContainer ().getFilterStack ()).left (4 ))
153159 .child (new Column ().widthRel (1f ).align (Alignment .TopLeft ).top (22 ).coverChildrenHeight ()
154160 .child (new EnumRowBuilder <>(ItemFilterMode .class )
155161 .value (filteringMode )
156162 .lang ("cover.filter.mode.title" )
157163 .overlay (16 , GTGuiTextures .FILTER_MODE_OVERLAY )
158164 .build ())
165+ .child (new Row ()
166+ .marginBottom (2 )
167+ .widthRel (1f )
168+ .coverChildrenHeight ()
169+ .setEnabledIf (b -> getFilterMode () != ItemFilterMode .FILTER_BOTH )
170+ .child (new ToggleButton ()
171+ .overlay (IKey .dynamic (() -> IKey .lang (allowFlow ?
172+ "cover.generic.enabled" :
173+ "cover.generic.disabled" ).get ())
174+ .color (Color .WHITE .main ).shadow (false ))
175+ .tooltip (tooltip -> tooltip
176+ .addLine (IKey .lang ("cover.filter.allow_flow.tooltip" )))
177+ .size (72 , 18 )
178+ .value (new BooleanSyncValue (() -> allowFlow , b -> allowFlow = b )))
179+ .child (IKey .lang ("cover.filter.allow_flow.label" )
180+ .asWidget ()
181+ .height (18 )
182+ .alignX (1f )))
159183 .child (new Rectangle ().setColor (UI_TEXT_COLOR ).asWidget ()
160184 .height (1 ).widthRel (0.95f ).margin (0 , 4 ))
161185 .child (getFilter ().createWidgets (guiSyncManager ).left (0 )))
@@ -212,23 +236,31 @@ public ItemHandlerFiltered(IItemHandler delegate) {
212236 @ NotNull
213237 @ Override
214238 public ItemStack insertItem (int slot , @ NotNull ItemStack stack , boolean simulate ) {
215- if (getFilterMode () == ItemFilterMode .FILTER_EXTRACT || !itemFilterContainer .test (stack )) {
216- return stack ;
217- }
218- return super .insertItem (slot , stack , simulate );
239+ // set to extract, but insertion is allowed
240+ if (getFilterMode () == ItemFilterMode .FILTER_EXTRACT && allowFlow )
241+ return super .insertItem (slot , stack , simulate );
242+
243+ // if set to insert or both, test the stack
244+ if (getFilterMode () != ItemFilterMode .FILTER_EXTRACT && itemFilterContainer .test (stack ))
245+ return super .insertItem (slot , stack , simulate );
246+
247+ // otherwise fail
248+ return stack ;
219249 }
220250
221251 @ NotNull
222252 @ Override
223253 public ItemStack extractItem (int slot , int amount , boolean simulate ) {
224- if (getFilterMode () != ItemFilterMode .FILTER_INSERT ) {
225- ItemStack result = super .extractItem (slot , amount , true );
226- if (result .isEmpty () || !itemFilterContainer .test (result )) {
227- return ItemStack .EMPTY ;
228- }
229- return simulate ? result : super .extractItem (slot , amount , false );
230- }
231- return super .extractItem (slot , amount , simulate );
254+ // set to insert, but extraction is allowed
255+ if (getFilterMode () == ItemFilterMode .FILTER_INSERT && allowFlow )
256+ return super .extractItem (slot , amount , simulate );
257+
258+ // if set to extract or both, test stack
259+ if (getFilterMode () != ItemFilterMode .FILTER_INSERT && itemFilterContainer .test (getStackInSlot (slot )))
260+ return super .extractItem (slot , amount , simulate );
261+
262+ // otherwise fail
263+ return ItemStack .EMPTY ;
232264 }
233265 }
234266}
0 commit comments