22
33import falseresync .vivatech .client .VivatechKeybindings ;
44import falseresync .vivatech .common .data .VivatechComponents ;
5+ import falseresync .vivatech .common .item .focus .Focus ;
56import falseresync .vivatech .common .item .focus .FocusItem ;
67import net .fabricmc .api .EnvType ;
78import net .fabricmc .api .Environment ;
@@ -70,6 +71,12 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
7071 var gadgetStack = user .getStackInHand (hand );
7172 var focusStack = getEquipped (gadgetStack );
7273 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
74+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
75+ var result = behaviorExtension .focusUse (gadgetStack , focusStack , world , user , hand );
76+ if (result .getResult () != ActionResult .PASS ) {
77+ return result ;
78+ }
79+ }
7380 return focusItem .focusUse (gadgetStack , focusStack , world , user , hand );
7481 }
7582
@@ -85,6 +92,12 @@ public ActionResult useOnBlock(ItemUsageContext context) {
8592 var gadgetStack = context .getStack ();
8693 var focusStack = getEquipped (gadgetStack );
8794 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
95+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
96+ var result = behaviorExtension .focusUseOnBlock (gadgetStack , focusStack , context );
97+ if (result != ActionResult .PASS ) {
98+ return result ;
99+ }
100+ }
88101 return focusItem .focusUseOnBlock (gadgetStack , focusStack , context );
89102 }
90103
@@ -96,6 +109,12 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity
96109 var gadgetStack = user .getStackInHand (hand );
97110 var focusStack = getEquipped (gadgetStack );
98111 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
112+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
113+ var result = behaviorExtension .focusUseOnEntity (gadgetStack , focusStack , user , entity , hand );
114+ if (result != ActionResult .PASS ) {
115+ return result ;
116+ }
117+ }
99118 return focusItem .focusUseOnEntity (gadgetStack , focusStack , user , entity , hand );
100119 }
101120
@@ -106,6 +125,9 @@ public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity
106125 public void usageTick (World world , LivingEntity user , ItemStack stack , int remainingUseTicks ) {
107126 var focusStack = getEquipped (stack );
108127 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
128+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
129+ behaviorExtension .focusUsageTick (world , user , stack , focusStack , remainingUseTicks );
130+ }
109131 focusItem .focusUsageTick (world , user , stack , focusStack , remainingUseTicks );
110132 return ;
111133 }
@@ -118,6 +140,12 @@ public void usageTick(World world, LivingEntity user, ItemStack stack, int remai
118140 public ItemStack finishUsing (ItemStack stack , World world , LivingEntity user ) {
119141 var focusStack = getEquipped (stack );
120142 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
143+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
144+ var newStack = behaviorExtension .focusFinishUsing (stack , focusStack , world , user );
145+ if (!ItemStack .areEqual (newStack , stack )) {
146+ return newStack ;
147+ }
148+ }
121149 return focusItem .focusFinishUsing (stack , focusStack , world , user );
122150 }
123151
@@ -129,6 +157,9 @@ public ItemStack finishUsing(ItemStack stack, World world, LivingEntity user) {
129157 public void onStoppedUsing (ItemStack stack , World world , LivingEntity user , int remainingUseTicks ) {
130158 var focusStack = getEquipped (stack );
131159 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
160+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
161+ behaviorExtension .focusOnStoppedUsing (stack , focusStack , world , user , remainingUseTicks );
162+ }
132163 focusItem .focusOnStoppedUsing (stack , focusStack , world , user , remainingUseTicks );
133164 }
134165 }
@@ -137,6 +168,9 @@ public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int
137168 public void inventoryTick (ItemStack stack , World world , Entity entity , int slot , boolean selected ) {
138169 var focusStack = getEquipped (stack );
139170 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
171+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
172+ behaviorExtension .focusInventoryTick (stack , focusStack , world , entity , slot , selected );
173+ }
140174 focusItem .focusInventoryTick (stack , focusStack , world , entity , slot , selected );
141175 }
142176// if (entity instanceof ServerPlayerEntity player) {
@@ -151,6 +185,11 @@ public void inventoryTick(ItemStack stack, World world, Entity entity, int slot,
151185 public boolean isUsedOnRelease (ItemStack stack ) {
152186 var focusStack = getEquipped (stack );
153187 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
188+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
189+ if (behaviorExtension .focusIsUsedOnRelease (stack , focusStack )) {
190+ return true ;
191+ }
192+ }
154193 return focusItem .focusIsUsedOnRelease (stack , focusStack );
155194 }
156195
@@ -166,6 +205,12 @@ public boolean isUsedOnRelease(ItemStack stack) {
166205 public int getMaxUseTime (ItemStack stack , LivingEntity user ) {
167206 var focusStack = getEquipped (stack );
168207 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
208+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
209+ var maxUseTime = behaviorExtension .focusGetMaxUseTime (stack , focusStack , user );
210+ if (maxUseTime > 0 ) {
211+ return maxUseTime ;
212+ }
213+ }
169214 return focusItem .focusGetMaxUseTime (stack , focusStack , user );
170215 }
171216
@@ -178,6 +223,12 @@ public float getBonusAttackDamage(Entity target, float baseAttackDamage, DamageS
178223 if (weaponStack != null && weaponStack .getItem () instanceof GadgetItem ) {
179224 var focusStack = getEquipped (weaponStack );
180225 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
226+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
227+ var bonusAttackDamage = behaviorExtension .focusGetBonusAttackDamage (weaponStack , focusStack , target , baseAttackDamage , damageSource );
228+ if (bonusAttackDamage > 0 ) {
229+ return bonusAttackDamage ;
230+ }
231+ }
181232 return focusItem .focusGetBonusAttackDamage (weaponStack , focusStack , target , baseAttackDamage , damageSource );
182233 }
183234 }
@@ -191,6 +242,11 @@ public float getBonusAttackDamage(Entity target, float baseAttackDamage, DamageS
191242 public boolean isItemBarVisible (ItemStack stack ) {
192243 var focusStack = getEquipped (stack );
193244 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
245+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
246+ if (behaviorExtension .focusIsItemBarVisible (stack , focusStack )) {
247+ return true ;
248+ }
249+ }
194250 return focusItem .focusIsItemBarVisible (stack , focusStack );
195251 }
196252
@@ -201,6 +257,12 @@ public boolean isItemBarVisible(ItemStack stack) {
201257 public int getItemBarStep (ItemStack stack ) {
202258 var focusStack = getEquipped (stack );
203259 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
260+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
261+ var step = behaviorExtension .focusGetItemBarStep (stack , focusStack );
262+ if (step > 0 ) {
263+ return step ;
264+ }
265+ }
204266 return focusItem .focusGetItemBarStep (stack , focusStack );
205267 }
206268
@@ -211,6 +273,12 @@ public int getItemBarStep(ItemStack stack) {
211273 public int getItemBarColor (ItemStack stack ) {
212274 var focusStack = getEquipped (stack );
213275 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
276+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
277+ var step = behaviorExtension .focusGetItemBarStep (stack , focusStack );
278+ if (step > 0 ) {
279+ return step ;
280+ }
281+ }
214282 return focusItem .focusGetItemBarColor (stack , focusStack );
215283 }
216284
@@ -221,6 +289,11 @@ public int getItemBarColor(ItemStack stack) {
221289 public boolean hasGlint (ItemStack stack ) {
222290 var focusStack = getEquipped (stack );
223291 if (!focusStack .isEmpty () && focusStack .getItem () instanceof FocusItem focusItem ) {
292+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
293+ if (behaviorExtension .focusHasGlint (stack , focusStack )) {
294+ return true ;
295+ }
296+ }
224297 return focusItem .focusHasGlint (stack , focusStack );
225298 }
226299
@@ -236,6 +309,9 @@ public void appendTooltip(ItemStack stack, TooltipContext context, List<Text> to
236309 .translatable ("tooltip.vivatech.gadget.active_focus" , focusStack .getName ())
237310 .styled (style -> style .withColor (Formatting .GRAY )));
238311 focusItem .focusAppendTooltip (stack , focusStack , context , tooltip , type );
312+ for (Focus behaviorExtension : focusItem .getBehaviorExtensions ()) {
313+ behaviorExtension .focusAppendTooltip (stack , focusStack , context , tooltip , type );
314+ }
239315 }
240316 tooltip .add (Text
241317 .translatable ("tooltip.vivatech.gadget.change_focus" , KeyBindingHelper .getBoundKeyOf (VivatechKeybindings .TOOL_CONTROL ).getLocalizedText ())
@@ -260,11 +336,17 @@ public TypedActionResult<ItemStack> exchangeFocuses(ItemStack gadgetStack, ItemS
260336 if (oldFocusStack .getItem () instanceof FocusItem oldFocusItem ) {
261337 removeOld = true ;
262338 oldFocusItem .focusOnUnequipped (gadgetStack , oldFocusStack , user );
339+ for (Focus behaviorExtension : oldFocusItem .getBehaviorExtensions ()) {
340+ behaviorExtension .focusOnUnequipped (gadgetStack , oldFocusStack , user );
341+ }
263342 }
264343
265344 if (newFocusStack .getItem () instanceof FocusItem newFocusItem ) {
266345 insertNew = true ;
267346 newFocusItem .focusOnEquipped (gadgetStack , newFocusStack , user );
347+ for (Focus behaviorExtension : newFocusItem .getBehaviorExtensions ()) {
348+ behaviorExtension .focusOnEquipped (gadgetStack , newFocusStack , user );
349+ }
268350 }
269351
270352 // newFocus != empty, oldFocus == empty -> success oldFocus
0 commit comments