aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/elisis/gtnhlanth/util/Util.java
blob: 1a42396de0ebf06f10516c1e67ee860d56a9f3fb (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
package com.elisis.gtnhlanth.util;

import java.util.ArrayList;
import java.util.List;

import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;

import com.gtnewhorizons.modularui.api.math.Pos2d;

public class Util {

    public static void depleteDurabilityOfStack(ItemStack stack, int damage) {

        if (stack == null) return;

        if (stack.stackSize == 0) // Might happen, who knows
            return;

        if (damage + stack.getItemDamage() > stack.getMaxDamage()) {
            stack.stackSize--;
        } else {

            stack.setItemDamage(stack.getItemDamage() + damage);

        }

    }

    public static List<Pos2d> getGridPositions(int totalCount, int xOrigin, int yOrigin, int xDirMaxCount,
        int yDirMaxCount, int distanceBetweenSlots) {
        // 18 pixels to get to a new grid for placing an item tile since they are 16x16 and have 1 pixel buffers
        // around them.

        int distance = 18 + distanceBetweenSlots;

        List<Pos2d> results = new ArrayList<>();
        int count = 0;
        loop: for (int j = 0; j < yDirMaxCount; j++) {
            for (int i = 0; i < xDirMaxCount; i++) {
                if (count >= totalCount) break loop;
                results.add(new Pos2d(xOrigin + i * distance, yOrigin + j * distance));
                count++;
            }
        }
        return results;
    }

    public static boolean coolantFluidCheck(FluidStack inStack, int fluidToConsume) {
        return (inStack.amount < fluidToConsume
            || (!inStack.isFluidEqual(FluidRegistry.getFluidStack("ic2coolant", 1)) && inStack.getFluid()
                .getTemperature() > 200));
    }
}