-
Notifications
You must be signed in to change notification settings - Fork 2
/
ContainerBasic.java
70 lines (53 loc) · 2.08 KB
/
ContainerBasic.java
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
package com.clowcadia.test.containers;
import com.clowcadia.test.entities.living.Test;
import com.clowcadia.test.utils.Utils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
public class ContainerBasic extends Container{
public Entity entity;
private int stomach;
public ContainerBasic(IInventory playerInv, Entity entity) {
this.entity = entity;
Utils.getLogger().info("ContainerBasic: Constructor");
IItemHandler handler = entity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); //Gets the inventory from our tile entity
this.addSlotToContainer(new SlotItemHandler(handler, 0, 8,8));
int xPos = 8;
int yPos = 84;
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 9; ++x) {
this.addSlotToContainer(new Slot(playerInv, x + y * 9 + 9, xPos + x * 18, yPos + y * 18));
}
}
for (int x = 0; x < 9; ++x) {
this.addSlotToContainer(new Slot(playerInv, x, xPos + x * 18, yPos + 58));
}
}
@Override
public boolean canInteractWith(EntityPlayer player) {
//Utils.getLogger().info("ContainerBasic: canInteractWith");
((Test) this.entity).getOwner(player);
return !player.isSpectator();
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
//Utils.getLogger().info("ContainerBasic: detectAndSendChanges");
IContainerListener icontainerlistener = this.listeners.get(0);
if(this.stomach!=((Test) this.entity).getStomach()){
icontainerlistener.sendProgressBarUpdate(this, 0, ((Test) this.entity).getStomach());
}
this.stomach = ((Test) this.entity).getStomach();
}
@Override
public void updateProgressBar(int id, int data) {
Utils.getLogger().info("ContainerBasic: updateProgressBar");
if(id==0) ((Test) this.entity).setStomach(data);
}
}