Skip to content

Commit d042f6e

Browse files
committed
SecUseCooldownComponent - fix bug with 0 seconds
- Ref #776
1 parent 0f2a7c5 commit d042f6e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/main/java/com/shanebeestudios/skbee/elements/itemcomponent/sections/SecUseCooldownComponent.java

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public boolean init(Expression<?>[] exprs, int matchedPattern, Kleenean isDelaye
7676
Timespan timespan = this.seconds.getSingle(event);
7777
if (timespan != null) seconds = (float) timespan.getAs(Timespan.TimePeriod.MILLISECOND) / 1000;
7878
}
79+
// Minecraft requires > 0, so lowest we'll go is 1 tick
80+
seconds = Math.clamp(seconds, 0.05f, Float.MAX_VALUE);
7981

8082
UseCooldown.Builder builder = UseCooldown.useCooldown(seconds);
8183

src/test/scripts/general/item-component.sk

+6
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,12 @@ test "SkBee - Item Component test" when running minecraft "1.21.3":
283283
group: "blah:special_apple"
284284
assert {_i} has item component minecraft:use_cooldown with "The apple should have a use cooldown component"
285285

286+
set {_i} to 1 of stick
287+
apply use cooldown to {_i}:
288+
seconds: 0 seconds # Testing a previous bug
289+
group: "sovde_found_this_bug_so_he_gets_a_custom_group"
290+
assert {_i} has item component minecraft:use_cooldown with "The apple should have a use cooldown component"
291+
286292
# Use Remainder
287293
set {_i} to 1 of honey bottle
288294
assert use remainder component of {_i} is glass bottle with "Default use remainder of a honey bottle should be a glass bottle"

0 commit comments

Comments
 (0)