/
DrawbridgeContainer.java
50 lines (38 loc) · 1.82 KB
/
DrawbridgeContainer.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
package slimeknights.tmechworks.common.inventory;
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.network.PacketBuffer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import slimeknights.mantle.inventory.BaseContainer;
import slimeknights.tmechworks.common.MechworksContent;
import slimeknights.tmechworks.common.blocks.tileentity.DrawbridgeTileEntity;
import slimeknights.tmechworks.common.inventory.slots.ValidatingSlot;
public class DrawbridgeContainer extends BaseContainer<DrawbridgeTileEntity> {
public final PlayerInventory playerInventory;
public DrawbridgeContainer(int id, PlayerInventory playerInventory, DrawbridgeTileEntity te) {
super(MechworksContent.Containers.drawbridge, id, te);
this.playerInventory = playerInventory;
te.openInventory(playerInventory.player);
addDrawbridgeSlots();
for(int x = 0; x < 2; x++){
for(int y = 0; y < 2; y++){
addSlot(new ValidatingSlot(tile.upgrades, x * 2 + y, -36 + x * 18, 119 + y * 18));
}
}
addPlayerInventory(playerInventory, 8, 84);
}
protected void addDrawbridgeSlots(){
addSlot(new ValidatingSlot(tile.slots, 0, 80, 36));
}
@OnlyIn(Dist.CLIENT)
public static DrawbridgeContainer factory(int id, PlayerInventory playerInventory, PacketBuffer extraData) {
BlockPos pos = extraData.readBlockPos();
TileEntity te = playerInventory.player.world.getTileEntity(pos);
DrawbridgeTileEntity drawbridge = null;
if(te instanceof DrawbridgeTileEntity)
drawbridge = (DrawbridgeTileEntity) te;
return new DrawbridgeContainer(id, playerInventory, drawbridge);
}
}