aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/objects/blockupdate/RandomCooldown.java
blob: 8c46e5a1eca077697c145bdadc931adc325b7c6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package gregtech.api.objects.blockupdate;

import static gregtech.api.objects.XSTR.XSTR_INSTANCE;

public class RandomCooldown extends Cooldown {

    public RandomCooldown(int aMinLengthInTicks, int aMaxLengthInTicks) {

        super(aMinLengthInTicks);

        if (aMinLengthInTicks <= 0)
            throw new IllegalArgumentException("min length should be a positive non-zero number");
        if (aMaxLengthInTicks <= 0)
            throw new IllegalArgumentException("max length should be a positive non-zero number");
        if (aMinLengthInTicks > aMaxLengthInTicks)
            throw new IllegalArgumentException("min length should be less or equal to max length");

        this.minLengthInTicks = aMinLengthInTicks;
        this.maxLengthInTicks = aMaxLengthInTicks;
    }

    @Override
    public void set(long currTickTime) {

        super.set(currTickTime);
        lengthInTicks = minLengthInTicks + XSTR_INSTANCE.nextInt(maxLengthInTicks - minLengthInTicks + 1);
    }

    private final int minLengthInTicks;
    private final int maxLengthInTicks;
}