aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/multitileentity/multiblock/base/StackableModularController.java
blob: 5e7a928399f7d27b60c7e8ddfeddad53722d6c61 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package gregtech.api.multitileentity.multiblock.base;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.jetbrains.annotations.NotNull;

import gregtech.api.logic.MuTEProcessingLogic;
import gregtech.api.multitileentity.interfaces.UpgradableModularMuTE;
import gregtech.api.util.GT_StructureUtilityMuTE.UpgradeCasings;

public abstract class StackableModularController<C extends StackableModularController<C, P>, P extends MuTEProcessingLogic<P>>
    extends StackableController<C, P> implements UpgradableModularMuTE {

    protected double durationMultiplier = 1;
    protected double euTickMultiplier = 1;

    private Map<UpgradeCasings, int[]> mucMap;

    protected @NotNull Map<UpgradeCasings, int[]> getMucMap() {
        if (mucMap == null) {
            mucMap = createMucMap();
        }
        return mucMap;
    }

    protected static @NotNull Map<UpgradeCasings, int[]> createMucMap() {
        Map<UpgradeCasings, int[]> mucCount = new HashMap<>();
        mucCount.put(UpgradeCasings.Heater, new int[] { 0, 0, 0, 0, 0 });
        mucCount.put(UpgradeCasings.Insulator, new int[] { 0, 0, 0, 0, 0 });
        return mucCount;
    }

    @Override
    public void increaseMucCount(UpgradeCasings casingType, int tier) {
        Map<UpgradeCasings, int[]> mucCounters = getMucMap();
        int[] casingCount = mucCounters.get(casingType);

        switch (tier) {
            case 0, 1, 2 -> casingCount[0] += 1;
            case 3, 4, 5 -> casingCount[1] += 1;
            case 6, 7, 8 -> casingCount[2] += 1;
            case 9, 10, 11 -> casingCount[3] += 1;
            default -> casingCount[4] += 1;
        }
    }

    @Override
    public void resetMucCount() {
        Map<UpgradeCasings, int[]> mucCounters = getMucMap();
        mucCounters.forEach((type, casingCount) -> Arrays.fill(casingCount, 0));
    }

    // Returns the cheapest MUC that is possible for the multi, which gets the minimum bonuses.
    protected abstract UpgradeCasings getBaseMucType();

    // Minimum parallel bonus per MUC. Higher tier MUCs multiply with this value for even more parallels.
    protected abstract int getParallelFactor();

    protected void calculateParallels() {
        int parallelCount = 0;
        int parallelFactor = getParallelFactor();
        int[] parallelCasingList = mucMap.get(getBaseMucType());

        for (int i = 0; i < 5; i++) {
            // (i * 3 + 1) -> Convert MUC tier into minimum GT tier, in groups of 3 (LV, EV, LuV, UHV, UMV)
            // If higher than multi tier, upgrade casing has no effect
            if (i * 3 + 1 <= tier) {
                parallelCount += parallelCasingList[i] * (i + 1) * parallelFactor;
            }
        }
        maxParallel = parallelCount == 0 ? 1 : parallelCount;
    }

    protected abstract boolean calculateMucMultipliers();
}