aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/detrav/items/behaviours/BehaviourDetravConfigurator.java
blob: e55d3c8c3163b0ebc52ae191070b4e54f4d0bc8f (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
package com.detrav.items.behaviours;

import com.detrav.enums.DetravItemList;
import gregtech.api.items.GT_MetaBase_Item;
import gregtech.common.items.behaviors.Behaviour_None;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;

/**
 * Created by Detrav on 29.04.2017.
 */
public class BehaviourDetravConfigurator  extends Behaviour_None {
    public ItemStack onItemRightClick(GT_MetaBase_Item aItem, ItemStack aStack, World aWorld, EntityPlayer aPlayer) {

        InventoryPlayer inv = aPlayer.inventory;
        if (inv != null) {
            for (int i = 0; i < inv.mainInventory.length; i++) {
                if (inv.mainInventory[i].getUnlocalizedName().startsWith("gt.integrated_circuit")
                        && inv.mainInventory[i].stackSize == 1) {

                    int circuit_config = inv.mainInventory[i].getItemDamage();
                    if(circuit_config > 5)
                        circuit_config = 5;
                    //circuit_config *= 2;
                    circuit_config++;
                    inv.mainInventory[i] = DetravItemList.ConfiguredCircuit.get(1);
                    ItemStack aCircuit = inv.mainInventory[i];

                    //in here if circuit is empty set data to chunk


                    NBTTagCompound aNBT = aCircuit.getTagCompound();
                    if (aNBT == null) {
                        aNBT = new NBTTagCompound();
                        NBTTagCompound detravPosition = new NBTTagCompound();
                        aNBT.setTag("DetravPosition", detravPosition);
                        aCircuit.setTagCompound(aNBT);
                    }

                    NBTTagCompound detravPosition = aNBT.getCompoundTag("DetravPosition");
                    if (detravPosition == null) {
                        detravPosition = new NBTTagCompound();
                        aNBT.setTag("DetravPosition", detravPosition);
                    }


                    int x_from = ((((int) aPlayer.posX) >> 4) - circuit_config + 1) * 16;
                    int x_to = ((((int) aPlayer.posX) >> 4) + circuit_config) * 16;
                    int x_current = x_from;
                    int z_from = ((((int) aPlayer.posZ) >> 4) - circuit_config + 1) * 16;
                    int z_to = ((((int) aPlayer.posZ) >> 4) + circuit_config) * 16;
                    int z_current = z_from;


                    int y_from = (int) aPlayer.posY + 1;
                    int y_to = (int) aPlayer.posY - 10;

                    detravPosition.setInteger("XFrom", x_from);
                    detravPosition.setInteger("XTo", x_to);
                    detravPosition.setInteger("XCurrent", x_current);
                    detravPosition.setInteger("ZFrom", z_from);
                    detravPosition.setInteger("ZTo", z_to);
                    detravPosition.setInteger("ZCurrent", z_current);
                    detravPosition.setInteger("YFrom", y_from);
                    detravPosition.setInteger("YTo", y_to);
                    return super.onItemRightClick(aItem, aStack, aWorld, aPlayer);
                }
            }

        }
        return super.onItemRightClick(aItem, aStack, aWorld, aPlayer);

    }
}