summaryrefslogtreecommitdiff
path: root/src/main/java/ihl/processing/chemistry/DosingPumpContainer.java
blob: 5a4cb21ebf50cc18839668f982b073039ccdcb4b (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
package ihl.processing.chemistry;

import java.util.List;

import ic2.core.ContainerBase;
import ic2.core.IC2;
import ic2.core.slot.SlotInvSlot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraftforge.fluids.FluidStack;

public class DosingPumpContainer extends ContainerBase<DosingPumpTileEntity> {

	protected DosingPumpTileEntity tileEntity;
	public int lastFluidAmount = -1;
	public int lastNumberOfFluids = -1;
	public short lastProgress = -1;
	public int lastFluidAmountSetpoint = -1;
	public short lastEnergy = -1;
	private final static int height = 166;
	public List<FluidStack> fluidTankFluidList;

	public DosingPumpContainer(EntityPlayer entityPlayer, DosingPumpTileEntity tileEntity1) {
		super(tileEntity1);
		this.tileEntity = tileEntity1;
		fluidTankFluidList = tileEntity.getFluidTank().getFluidList();
		int col;
		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));
		}
		this.addSlotToContainer(new SlotInvSlot(tileEntity1.fillInputSlot, 0, 44, 50));
		this.addSlotToContainer(new SlotInvSlot(tileEntity1.drainInputSlot, 0, 44, 14));
		this.addSlotToContainer(new SlotInvSlot(tileEntity1.emptyFluidItemsSlot, 0, 44, 32));
		this.addSlotToContainer(new SlotInvSlot(tileEntity1.dischargeSlot, 0, 8, 32));
	}

	@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.getTankAmount() != this.lastFluidAmount
					|| this.tileEntity.getNumberOfFluidsInTank() != this.lastNumberOfFluids) {
				IC2.network.get().sendContainerField(this, "fluidTankFluidList");
			}

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

			if (this.tileEntity.fluidAmountSetpoint != this.lastFluidAmountSetpoint) {
				icrafting.sendProgressBarUpdate(this, 1, this.tileEntity.fluidAmountSetpoint);
			}

			if ((short) this.tileEntity.energy != this.lastEnergy) {
				icrafting.sendProgressBarUpdate(this, 2, (short) this.tileEntity.energy);
			}
		}

		this.lastNumberOfFluids = this.tileEntity.getNumberOfFluidsInTank();
		this.lastFluidAmount = this.tileEntity.getTankAmount();
		this.lastProgress = this.tileEntity.progress;
		this.lastFluidAmountSetpoint = this.tileEntity.fluidAmountSetpoint;
		this.lastEnergy = (short) this.tileEntity.energy;
	}

	@Override
	public void updateProgressBar(int index, int value) {
		super.updateProgressBar(index, value);
		switch (index) {
		case 0:
			this.tileEntity.progress = (short) value;
			break;
		case 1:
			this.tileEntity.fluidAmountSetpoint = (short) value;
			break;
		case 2:
			this.tileEntity.energy = value;
			break;
		}
	}

	@Override
	public boolean canInteractWith(EntityPlayer var1) {
		return tileEntity.isUseableByPlayer(var1);
	}
}