aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/GoodGenerator/util/StructureHelper.java
blob: 2c5feadab824d4e5ec2881f4f82f0af6eb77c4f3 (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
package GoodGenerator.util;

import com.github.technus.tectech.TecTech;
import com.github.technus.tectech.mechanics.structure.IStructureElement;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.metatileentity.BaseMetaPipeEntity;
import gregtech.api.metatileentity.implementations.GT_MetaPipeEntity_Frame;
import gregtech.api.util.GT_OreDictUnificator;
import net.minecraft.init.Items;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;

import java.util.Arrays;

public class StructureHelper {

    public static <T>IStructureElement<T> addFrame(Materials aMaterials) {
        return new IStructureElement<T>() {

            private IIcon[] mIcons;

            @Override
            public boolean check(T t, World world, int x, int y, int z) {
                TileEntity tBlock = world.getTileEntity(x, y, z);
                if (tBlock instanceof BaseMetaPipeEntity) {
                    BaseMetaPipeEntity tFrame = (BaseMetaPipeEntity) tBlock;
                    if (tFrame.isInvalidTileEntity()) return false;
                    if (tFrame.getMetaTileEntity() instanceof GT_MetaPipeEntity_Frame) {
                        return ((GT_MetaPipeEntity_Frame) tFrame.getMetaTileEntity()).mMaterial == aMaterials;
                    }
                }
                return false;
            }

            @Override
            public boolean spawnHint(T t, World world, int x, int y, int z, ItemStack trigger) {
                if (mIcons == null) {
                    mIcons = new IIcon[6];
                    Arrays.fill(mIcons, aMaterials.mIconSet.mTextures[OrePrefixes.frameGt.mTextureIndex].getIcon());
                }
                TecTech.proxy.hint_particle_tinted(world, x, y, z, mIcons, aMaterials.mRGBa);
                return true;
            }

            @Override
            public boolean placeBlock(T t, World world, int x, int y, int z, ItemStack trigger) {
                ItemStack tFrame = GT_OreDictUnificator.get(OrePrefixes.frameGt, aMaterials, 1);
                if (tFrame.getItem() instanceof ItemBlock) {
                    ItemBlock tFrameStackItem = (ItemBlock) tFrame.getItem();
                    return tFrameStackItem.placeBlockAt(tFrame, null, world, x, y, z, 6, 0, 0, 0, Items.feather.getDamage(tFrame));
                }
                return false;
            }
        };
    }

}