summaryrefslogtreecommitdiff
path: root/src/main/java/ihl/flexible_cable/IronWorkbenchContainer.java
blob: ede21949cd162cb3e12b20ee5add0f6d987e712d (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package ihl.flexible_cable;

import ic2.core.ContainerBase;
import ihl.processing.invslots.SlotInvSlotIronWorkbench;
import ihl.processing.invslots.SlotInvSlotOutputInProgress;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;

public class IronWorkbenchContainer extends ContainerBase<IronWorkbenchTileEntity> {

    protected IronWorkbenchTileEntity tileEntity;
    private int lastProgress1 = -1;
    private int conrolSum = -1;
    private int currentSlot1 = -1;
    private short workspaceReadyStatus1 = -1;
    private static final short slotUpdateOffset=4;
    public final static int height=202;//166
    
    public IronWorkbenchContainer(EntityPlayer entityPlayer, IronWorkbenchTileEntity tileEntity1){
        super(tileEntity1);
        this.tileEntity = tileEntity1;
        int col, row;

        for (col = 0; col < 3; ++col)
        {
            for (int col1 = 0; col1 < 9; ++col1)
            {
                this.addSlotToContainer(new Slot(entityPlayer.inventory, col1 + col * 9 + 9, 8 + col1 * 18, height + -82 + col * 18));
            }
        }
        for (col = 0; col < 9; ++col)
        {
            this.addSlotToContainer(new Slot(entityPlayer.inventory, col, 8 + col * 18, height + -24));
        }
        for(row=0;row<6;row++)
        {
            for(col=0;col<=1;col++)
            {
            	this.addSlotToContainer(new SlotInvSlotIronWorkbench(tileEntity1.tools, row+col*6, 26+col*18, 8+row*18));
            }
        }
       for(row=0;row<6;row++)
       {
           for(col=0;col<=1;col++)
           {
        	   this.addSlotToContainer(new SlotInvSlotIronWorkbench(tileEntity1.inputMaterial, row+col*6, 65+col*18, 8+row*18));
           }
       }
       for (row = 0; row<6; ++row)
       {
    	   this.addSlotToContainer(new SlotInvSlotOutputInProgress(tileEntity1.workspaceElements, row, 8, 8+row*18));
       }
	   for(row=0;row<6;row++)
  		{
		   for (col = 0; col<3; ++col)
		   	{
    		   this.addSlotToContainer(new SlotInvSlotOutputInProgress(tileEntity1.output, col+row*3, 116+col*18, 8+row*18));
       		}
       }

    }

    @Override
	public void detectAndSendChanges()
    {
        super.detectAndSendChanges();
        for (int i = 0; i < this.crafters.size(); ++i)
        {
            ICrafting icrafting = (ICrafting)this.crafters.get(i);

            if (this.tileEntity.progress != this.lastProgress1)
            {
            	icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.progress);

            }
            if (this.tileEntity.currentSlot != this.currentSlot1)
            {
            	icrafting.sendProgressBarUpdate(this, 1, this.tileEntity.currentSlot);

            }
            if(this.tileEntity.workspaceElements.encodeReadyStatus()!=this.workspaceReadyStatus1)
            {
               	icrafting.sendProgressBarUpdate(this, 2, this.tileEntity.workspaceElements.encodeReadyStatus());
            }
            if(this.tileEntity.output.getCheckSum()!=this.conrolSum)
            {
            	for(int i1 = 0; i1<this.tileEntity.output.size();i1++)
            	{
                	icrafting.sendProgressBarUpdate(this, i1+slotUpdateOffset, this.tileEntity.output.slotRecipe[i1]);
            	}
            }

        }
        this.currentSlot1=this.tileEntity.currentSlot;
        this.conrolSum=this.tileEntity.output.getCheckSum();
        this.lastProgress1 = this.tileEntity.progress;
        this.workspaceReadyStatus1=this.tileEntity.workspaceElements.encodeReadyStatus();
    }
    
    @Override
	public void updateProgressBar(int index, int value)
    {
        super.updateProgressBar(index, value);
        if(index>=slotUpdateOffset)
        {
            this.tileEntity.output.slotRecipe[index-slotUpdateOffset]=(short) value;
        }
        switch (index)
        {
        case 0:
            this.tileEntity.progress=value;
            break;
        case 1:
        	this.tileEntity.currentSlot=value;
            break;
        case 2:
        	this.tileEntity.workspaceElements.decodeReadyStatus((short) value);
            break;
        }
    }
    
	@Override
	public boolean canInteractWith(EntityPlayer var1) {
		return tileEntity.isUseableByPlayer(var1);
	}
	
    /**
     * Called when a player shift-clicks on a slot. You must override this or you will crash when someone does that.
     */
}