1717final class AnimationImpl implements Animation {
1818
1919 private final int tickDelay ;
20- private final BiPredicate <Gui , Slot > slotFilter ;
21- private final Function <Animation , Set <Slot >> slotSelector ;
22- private BiConsumer <Animation , Set <Slot >> showHandler ;
23- private Consumer <Animation > finishHandler ;
20+ private final BiPredicate <? super Gui , ? super Slot > slotFilter ;
21+ private final Function <? super Animation , ? extends Set <? extends Slot >> slotSelector ;
22+ private final Function <? super Slot , ? extends @ Nullable SlotElement > intermediaryGenerator ;
23+ private BiConsumer <? super Animation , Set <? extends Slot >> showHandler ;
24+ private Consumer <? super Animation > finishHandler ;
2425
2526 private final Set <Slot > remainingSlots = new HashSet <>();
2627 private @ Nullable Gui gui ;
@@ -30,14 +31,16 @@ final class AnimationImpl implements Animation {
3031
3132 public AnimationImpl (
3233 int tickDelay ,
33- BiPredicate <Gui , Slot > slotFilter ,
34- Function <Animation , Set <Slot >> slotSelector ,
35- BiConsumer <Animation , Set <Slot >> showHandler ,
36- Consumer <Animation > finishHandler
34+ BiPredicate <? super Gui , ? super Slot > slotFilter ,
35+ Function <? super Animation , ? extends Set <? extends Slot >> slotSelector ,
36+ Function <? super Slot , ? extends @ Nullable SlotElement > intermediaryGenerator ,
37+ BiConsumer <? super Animation , Set <? extends Slot >> showHandler ,
38+ Consumer <? super Animation > finishHandler
3739 ) {
3840 this .tickDelay = tickDelay ;
3941 this .slotFilter = slotFilter ;
4042 this .slotSelector = slotSelector ;
43+ this .intermediaryGenerator = intermediaryGenerator ;
4144 this .showHandler = showHandler ;
4245 this .finishHandler = finishHandler ;
4346 }
@@ -65,14 +68,18 @@ public boolean isFinished() {
6568 return remainingSlots .isEmpty ();
6669 }
6770
68- public void addShowHandler (Consumer <Set <Slot >> showHandler ) {
71+ public void addShowHandler (Consumer <? super Set <? extends Slot >> showHandler ) {
6972 this .showHandler = this .showHandler .andThen ((animation , slot ) -> showHandler .accept (slot ));
7073 }
7174
7275 public void addFinishHandler (Runnable finishHandler ) {
7376 this .finishHandler = this .finishHandler .andThen (animation -> finishHandler .run ());
7477 }
7578
79+ public @ Nullable SlotElement getIntermediarySlotElement (Slot slot ) {
80+ return intermediaryGenerator .apply (slot );
81+ }
82+
7683 /**
7784 * Binds the animation to a gui and populates the remaining slots.
7885 *
@@ -135,9 +142,10 @@ static final class BuilderImpl implements Animation.Builder {
135142
136143 private int tickDelay = 1 ;
137144 private BiPredicate <Gui , Slot > slotFilter = (gui , slot ) -> true ;
138- private BiConsumer <Animation , Set <Slot >> showHandler = (animation , slot ) -> {};
145+ private @ Nullable Function <? super Animation , ? extends Set <? extends Slot >> slotSelector ;
146+ private Function <? super Slot , ? extends @ Nullable SlotElement > intermediaryGenerator = slot -> null ;
147+ private BiConsumer <Animation , Set <? extends Slot >> showHandler = (animation , slot ) -> {};
139148 private Consumer <Animation > finishHandler = gui -> {};
140- private @ Nullable Function <Animation , Set <Slot >> slotSelector ;
141149
142150 @ Override
143151 public Animation .Builder setTickDelay (int tickDelay ) {
@@ -146,25 +154,31 @@ public Animation.Builder setTickDelay(int tickDelay) {
146154 }
147155
148156 @ Override
149- public Animation .Builder setSlotSelector (Function <Animation , Set <Slot >> selector ) {
157+ public Animation .Builder setSlotSelector (Function <? super Animation , ? extends Set <? extends Slot >> selector ) {
150158 this .slotSelector = selector ;
151159 return this ;
152160 }
153161
154162 @ Override
155- public Animation .Builder addShowHandler (BiConsumer <Animation , Set <Slot >> showHandler ) {
163+ public Builder setIntermediaryElementGenerator (Function <? super Slot , ? extends @ Nullable SlotElement > intermediaryGenerator ) {
164+ this .intermediaryGenerator = intermediaryGenerator ;
165+ return this ;
166+ }
167+
168+ @ Override
169+ public Animation .Builder addShowHandler (BiConsumer <? super Animation , ? super Set <? extends Slot >> showHandler ) {
156170 this .showHandler = this .showHandler .andThen (showHandler );
157171 return this ;
158172 }
159173
160174 @ Override
161- public Animation .Builder addFinishHandler (Consumer <Animation > finishHandler ) {
175+ public Animation .Builder addFinishHandler (Consumer <? super Animation > finishHandler ) {
162176 this .finishHandler = this .finishHandler .andThen (finishHandler );
163177 return this ;
164178 }
165179
166180 @ Override
167- public Animation .Builder addSlotFilter (BiPredicate <Gui , Slot > filter ) {
181+ public Animation .Builder addSlotFilter (BiPredicate <? super Gui , ? super Slot > filter ) {
168182 this .slotFilter = this .slotFilter .and (filter );
169183 return this ;
170184 }
@@ -174,7 +188,7 @@ public Animation build() {
174188 if (slotSelector == null )
175189 throw new IllegalStateException ("SlotSelector needs to be set" );
176190
177- return new AnimationImpl (tickDelay , slotFilter , slotSelector , showHandler , finishHandler );
191+ return new AnimationImpl (tickDelay , slotFilter , slotSelector , intermediaryGenerator , showHandler , finishHandler );
178192 }
179193
180194 }
0 commit comments