aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GTPPMTEFluid.java
blob: 550e5e409c5a9146079710d8d00102a251ad04a3 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations;

import net.minecraftforge.common.util.ForgeDirection;

import gregtech.api.enums.Dyes;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.enums.SubTag;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.MTEFluid;
import gregtech.api.render.TextureFactory;
import gtPlusPlus.xmod.gregtech.api.enums.GregtechOrePrefixes.GT_Materials;

public class GTPPMTEFluid extends MTEFluid {

    public final GT_Materials mMaterial;

    public GTPPMTEFluid(int aID, String aName, String aNameRegional, float aThickNess, GT_Materials aMaterial,
        int aCapacity, int aHeatResistance, boolean aGasProof) {
        this(aID, aName, aNameRegional, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1);
    }

    public GTPPMTEFluid(final String aName, final float aThickNess, final GT_Materials aMaterial, final int aCapacity,
        final int aHeatResistance, final boolean aGasProof) {
        this(aName, aThickNess, aMaterial, aCapacity, aHeatResistance, aGasProof, 1);
    }

    public GTPPMTEFluid(int aID, String aName, String aNameRegional, float aThickNess, GT_Materials aMaterial,
        int aCapacity, int aHeatResistance, boolean aGasProof, int aFluidTypes) {
        super(aID, aName, aNameRegional, aThickNess, null, aCapacity, aHeatResistance, aGasProof, aFluidTypes);
        this.mLastReceivedFrom = 0;
        this.oLastReceivedFrom = 0;
        this.mMaterial = aMaterial;
    }

    public GTPPMTEFluid(String aName, float aThickNess, GT_Materials aMaterial, int aCapacity, int aHeatResistance,
        boolean aGasProof, int aFluidTypes) {
        super(aName, aThickNess, null, aCapacity, aHeatResistance, aGasProof, aFluidTypes);
        this.mLastReceivedFrom = 0;
        this.oLastReceivedFrom = 0;
        this.mMaterial = aMaterial;
    }

    @Override
    public byte getTileEntityBaseType() {
        return this.mMaterial == null ? 4
            : (byte) ((this.mMaterial.contains(SubTag.WOOD) ? 12 : 4)
                + Math.max(0, Math.min(3, this.mMaterial.mToolQuality)));
    }

    @Override
    public IMetaTileEntity newMetaEntity(final IGregTechTileEntity aTileEntity) {
        return new GTPPMTEFluid(
            this.mName,
            this.mThickNess,
            this.mMaterial,
            this.mCapacity,
            this.mHeatResistance,
            this.mGasProof);
    }

    @Override
    public ITexture[] getTexture(IGregTechTileEntity aBaseMetaTileEntity, ForgeDirection side, int aConnections,
        int aColorIndex, boolean aConnected, boolean aRedstone) {
        float tThickNess = getThickNess();
        if (mDisableInput == 0)
            return new ITexture[] { aConnected ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex)
                : TextureFactory.of(
                    mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex],
                    Dyes.getModulation(aColorIndex, mMaterial.mRGBa)) };
        int tMask = 0;
        int[][] sRestrictionArray = { { 2, 3, 5, 4 }, { 2, 3, 5, 4 }, { 1, 0, 5, 4 }, { 1, 0, 4, 5 }, { 1, 0, 2, 3 },
            { 1, 0, 2, 3 } };
        if (side != ForgeDirection.UNKNOWN) {
            for (int i = 0; i < 4; i++)
                if (isInputDisabledAtSide(ForgeDirection.getOrientation(sRestrictionArray[side.ordinal()][i])))
                    tMask |= 1 << i;
            // Full block size renderer flips side 5 and 2 textures, flip restrictor textures to compensate
            if (side == ForgeDirection.EAST || side == ForgeDirection.UP)
                if (tMask > 3 && tMask < 12) tMask = (tMask ^ 12);
        }
        return new ITexture[] { aConnected ? getBaseTexture(tThickNess, mPipeAmount, mMaterial, aColorIndex)
            : TextureFactory.of(
                mMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex],
                Dyes.getModulation(aColorIndex, mMaterial.mRGBa)),
            getRestrictorTexture(tMask) };
    }

    protected static ITexture getBaseTexture(float aThickNess, int aPipeAmount, GT_Materials aMaterial,
        int aColorIndex) {
        if (aPipeAmount >= 9) return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipeNonuple.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
        if (aPipeAmount >= 4) return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipeQuadruple.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
        if (aThickNess < 0.124F) return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipe.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
        if (aThickNess < 0.374F) return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipeTiny.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
        if (aThickNess < 0.499F) return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipeSmall.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
        if (aThickNess < 0.749F) return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipeMedium.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
        if (aThickNess < 0.874F) return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipeLarge.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
        return TextureFactory.of(
            aMaterial.mIconSet.mTextures[OrePrefixes.pipeHuge.mTextureIndex],
            Dyes.getModulation(aColorIndex, aMaterial.mRGBa));
    }
}