mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Container base class to make life easier
This commit is contained in:
parent
9f567135d2
commit
eb8155b11b
67
src/main/java/com/hbm/inventory/container/ContainerBase.java
Normal file
67
src/main/java/com/hbm/inventory/container/ContainerBase.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
package com.hbm.inventory.container;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.IInventory;
|
||||||
|
import net.minecraft.inventory.Slot;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
|
/**For now, only used for stuff with filters and crates as a reference implementation,
|
||||||
|
* because I really needed to get the te from a container
|
||||||
|
* But you should very much use this to kill the giant amount of boilerplate in container classes
|
||||||
|
* @author 70k **/
|
||||||
|
public class ContainerBase extends Container {
|
||||||
|
|
||||||
|
protected IInventory te;
|
||||||
|
|
||||||
|
public ContainerBase (InventoryPlayer invPlayer, IInventory tedf){
|
||||||
|
te = tedf;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
|
return te.isUseableByPlayer(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2) {
|
||||||
|
ItemStack var3 = null;
|
||||||
|
Slot var4 = (Slot) this.inventorySlots.get(par2);
|
||||||
|
|
||||||
|
if(var4 != null && var4.getHasStack()) {
|
||||||
|
ItemStack var5 = var4.getStack();
|
||||||
|
var3 = var5.copy();
|
||||||
|
|
||||||
|
if(par2 <= te.getSizeInventory() - 1) {
|
||||||
|
if(!this.mergeItemStack(var5, te.getSizeInventory(), this.inventorySlots.size(), true)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} else if(!this.mergeItemStack(var5, 0, te.getSizeInventory(), false)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(var5.stackSize == 0) {
|
||||||
|
var4.putStack(null);
|
||||||
|
} else {
|
||||||
|
var4.onSlotChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
var4.onPickupFromSlot(p_82846_1_, var5);
|
||||||
|
}
|
||||||
|
|
||||||
|
return var3;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void playerInv(InventoryPlayer invPlayer, int playerInvX, int playerInvY, int playerHotbarY){
|
||||||
|
for(int i = 0; i < 3; i++) {
|
||||||
|
for(int j = 0; j < 9; j++) {
|
||||||
|
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, playerInvX + j * 18, playerInvY + i * 18));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < 9; i++) {
|
||||||
|
this.addSlotToContainer(new Slot(invPlayer, i, playerInvX + i * 18, playerHotbarY));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,57 +1,25 @@
|
|||||||
package com.hbm.inventory.container;
|
package com.hbm.inventory.container;
|
||||||
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.IInventory;
|
import net.minecraft.inventory.IInventory;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class ContainerCrateBase extends Container {
|
public class ContainerCrateBase extends ContainerBase {
|
||||||
|
|
||||||
protected IInventory crate;
|
|
||||||
|
|
||||||
public ContainerCrateBase(IInventory tedf) {
|
//just there so prev stuff doesnt break
|
||||||
crate = tedf;
|
protected IInventory crate = te;
|
||||||
crate.openInventory();
|
|
||||||
|
public ContainerCrateBase(InventoryPlayer invPlayer, IInventory tedf) {
|
||||||
|
super(invPlayer, tedf);
|
||||||
|
te.openInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack transferStackInSlot(EntityPlayer p_82846_1_, int par2) {
|
|
||||||
ItemStack var3 = null;
|
|
||||||
Slot var4 = (Slot) this.inventorySlots.get(par2);
|
|
||||||
|
|
||||||
if(var4 != null && var4.getHasStack()) {
|
|
||||||
ItemStack var5 = var4.getStack();
|
|
||||||
var3 = var5.copy();
|
|
||||||
|
|
||||||
if(par2 <= crate.getSizeInventory() - 1) {
|
|
||||||
if(!this.mergeItemStack(var5, crate.getSizeInventory(), this.inventorySlots.size(), true)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
} else if(!this.mergeItemStack(var5, 0, crate.getSizeInventory(), false)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(var5.stackSize == 0) {
|
|
||||||
var4.putStack((ItemStack) null);
|
|
||||||
} else {
|
|
||||||
var4.onSlotChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
var4.onPickupFromSlot(p_82846_1_, var5);
|
|
||||||
}
|
|
||||||
|
|
||||||
return var3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canInteractWith(EntityPlayer player) {
|
|
||||||
return crate.isUseableByPlayer(player);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onContainerClosed(EntityPlayer p_75134_1_) {
|
public void onContainerClosed(EntityPlayer p_75134_1_) {
|
||||||
super.onContainerClosed(p_75134_1_);
|
super.onContainerClosed(p_75134_1_);
|
||||||
this.crate.closeInventory();
|
te.closeInventory();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import net.minecraft.inventory.Slot;
|
|||||||
public class ContainerCrateDesh extends ContainerCrateBase {
|
public class ContainerCrateDesh extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerCrateDesh(InventoryPlayer invPlayer, IInventory tedf) {
|
public ContainerCrateDesh(InventoryPlayer invPlayer, IInventory tedf) {
|
||||||
super(tedf);
|
super(invPlayer,tedf);
|
||||||
|
|
||||||
for(int i = 0; i < 8; i++) {
|
for(int i = 0; i < 8; i++) {
|
||||||
for(int j = 0; j < 13; j++) {
|
for(int j = 0; j < 13; j++) {
|
||||||
@ -15,14 +15,7 @@ public class ContainerCrateDesh extends ContainerCrateBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
this.playerInv(invPlayer,44, 174, 232);
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 44 + j * 18, 174 + i * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 44 + i * 18, 232));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,22 +9,13 @@ import net.minecraft.inventory.Slot;
|
|||||||
public class ContainerCrateIron extends ContainerCrateBase {
|
public class ContainerCrateIron extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerCrateIron(InventoryPlayer invPlayer, TileEntityCrateIron tedf) {
|
public ContainerCrateIron(InventoryPlayer invPlayer, TileEntityCrateIron tedf) {
|
||||||
super(tedf);
|
super(invPlayer,tedf);
|
||||||
|
|
||||||
for(int i = 0; i < 4; i++) {
|
for(int i = 0; i < 4; i++) {
|
||||||
for(int j = 0; j < 9; j++) {
|
for(int j = 0; j < 9; j++) {
|
||||||
this.addSlotToContainer(new Slot(tedf, j + i * 9, 8 + j * 18, 18 + i * 18));
|
this.addSlotToContainer(new Slot(tedf, j + i * 9, 8 + j * 18, 18 + i * 18));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.playerInv(invPlayer, 8, 84 + 20, 142 + 20);
|
||||||
for(int i = 0; i < 3; i++) {
|
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + 20));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142 + 20));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import net.minecraft.inventory.Slot;
|
|||||||
public class ContainerCrateSteel extends ContainerCrateBase {
|
public class ContainerCrateSteel extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerCrateSteel(InventoryPlayer invPlayer, IInventory tedf) {
|
public ContainerCrateSteel(InventoryPlayer invPlayer, IInventory tedf) {
|
||||||
super(tedf);
|
super(invPlayer,tedf);
|
||||||
|
|
||||||
for(int i = 0; i < 6; i++) {
|
for(int i = 0; i < 6; i++) {
|
||||||
for(int j = 0; j < 9; j++) {
|
for(int j = 0; j < 9; j++) {
|
||||||
@ -16,14 +16,6 @@ public class ContainerCrateSteel extends ContainerCrateBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
this.playerInv(invPlayer,8, 84 + (18 * 3) + 2, 142 + (18 * 3) + 2);
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + (18 * 3) + 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 142 + (18 * 3) + 2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import net.minecraft.inventory.Slot;
|
|||||||
public class ContainerCrateTemplate extends ContainerCrateBase {
|
public class ContainerCrateTemplate extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerCrateTemplate(InventoryPlayer invPlayer, TileEntityCrateTemplate tedf) {
|
public ContainerCrateTemplate(InventoryPlayer invPlayer, TileEntityCrateTemplate tedf) {
|
||||||
super(tedf);
|
super(invPlayer,tedf);
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
for(int j = 0; j < 9; j++) {
|
for(int j = 0; j < 9; j++) {
|
||||||
@ -16,14 +16,6 @@ public class ContainerCrateTemplate extends ContainerCrateBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
this.playerInv(invPlayer,8, 86, 144);
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 86 + i * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 144));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -9,7 +9,7 @@ import net.minecraft.inventory.Slot;
|
|||||||
public class ContainerCrateTungsten extends ContainerCrateBase {
|
public class ContainerCrateTungsten extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerCrateTungsten(InventoryPlayer invPlayer, TileEntityCrateTungsten te) {
|
public ContainerCrateTungsten(InventoryPlayer invPlayer, TileEntityCrateTungsten te) {
|
||||||
super(te);
|
super(invPlayer,te);
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
for(int j = 0; j < 9; j++) {
|
for(int j = 0; j < 9; j++) {
|
||||||
@ -17,14 +17,6 @@ public class ContainerCrateTungsten extends ContainerCrateBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
this.playerInv(invPlayer,8, 32 + 18 * 3, 90 + (18 * 3));
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 32 + i * 18 + (18 * 3)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 90 + (18 * 3)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import net.minecraft.inventory.Slot;
|
|||||||
public class ContainerDroneDock extends ContainerCrateBase {
|
public class ContainerDroneDock extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerDroneDock(InventoryPlayer invPlayer, TileEntityDroneDock tedf) {
|
public ContainerDroneDock(InventoryPlayer invPlayer, TileEntityDroneDock tedf) {
|
||||||
super(tedf);
|
super(invPlayer,tedf);
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
for(int j = 0; j < 3; j++) {
|
for(int j = 0; j < 3; j++) {
|
||||||
@ -16,14 +16,6 @@ public class ContainerDroneDock extends ContainerCrateBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
this.playerInv(invPlayer, 8, 103, 161);
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import net.minecraft.inventory.Slot;
|
|||||||
public class ContainerDroneProvider extends ContainerCrateBase {
|
public class ContainerDroneProvider extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerDroneProvider(InventoryPlayer invPlayer, TileEntityDroneProvider tedf) {
|
public ContainerDroneProvider(InventoryPlayer invPlayer, TileEntityDroneProvider tedf) {
|
||||||
super(tedf);
|
super(invPlayer,tedf);
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
for(int j = 0; j < 3; j++) {
|
for(int j = 0; j < 3; j++) {
|
||||||
@ -16,14 +16,6 @@ public class ContainerDroneProvider extends ContainerCrateBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
this.playerInv(invPlayer, 8, 103, 161);
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,10 @@ import net.minecraft.inventory.Slot;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
|
||||||
public class ContainerDroneRequester extends ContainerCrateBase {
|
public class ContainerDroneRequester extends ContainerCrateBase {
|
||||||
|
|
||||||
public ContainerDroneRequester(InventoryPlayer invPlayer, TileEntityDroneRequester tedf) {
|
public ContainerDroneRequester(InventoryPlayer invPlayer, TileEntityDroneRequester tedf) {
|
||||||
super(tedf);
|
super(invPlayer,tedf);
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
for(int i = 0; i < 3; i++) {
|
||||||
for(int j = 0; j < 3; j++) {
|
for(int j = 0; j < 3; j++) {
|
||||||
this.addSlotToContainer(new SlotPattern(tedf, j + i * 3, 98 + j * 18, 17 + i * 18));
|
this.addSlotToContainer(new SlotPattern(tedf, j + i * 3, 98 + j * 18, 17 + i * 18));
|
||||||
@ -25,15 +25,7 @@ public class ContainerDroneRequester extends ContainerCrateBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < 3; i++) {
|
this.playerInv(invPlayer, 8, 103, 161);
|
||||||
for(int j = 0; j < 9; j++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 103 + i * 18));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i = 0; i < 9; i++) {
|
|
||||||
this.addSlotToContainer(new Slot(invPlayer, i, 8 + i * 18, 161));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -44,7 +36,7 @@ public class ContainerDroneRequester extends ContainerCrateBase {
|
|||||||
if(var4 != null && var4.getHasStack()) {
|
if(var4 != null && var4.getHasStack()) {
|
||||||
ItemStack var5 = var4.getStack();
|
ItemStack var5 = var4.getStack();
|
||||||
var3 = var5.copy();
|
var3 = var5.copy();
|
||||||
|
|
||||||
if(par2 < 9) return null; //ignore filters
|
if(par2 < 9) return null; //ignore filters
|
||||||
|
|
||||||
if(par2 <= crate.getSizeInventory() - 1) {
|
if(par2 <= crate.getSizeInventory() - 1) {
|
||||||
@ -69,18 +61,18 @@ public class ContainerDroneRequester extends ContainerCrateBase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {
|
public ItemStack slotClick(int index, int button, int mode, EntityPlayer player) {
|
||||||
|
|
||||||
//L/R: 0
|
//L/R: 0
|
||||||
//M3: 3
|
//M3: 3
|
||||||
//SHIFT: 1
|
//SHIFT: 1
|
||||||
//DRAG: 5
|
//DRAG: 5
|
||||||
|
|
||||||
if(index < 0 || index > 8) {
|
if(index < 0 || index > 8) {
|
||||||
return super.slotClick(index, button, mode, player);
|
return super.slotClick(index, button, mode, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
Slot slot = this.getSlot(index);
|
Slot slot = this.getSlot(index);
|
||||||
|
|
||||||
ItemStack ret = null;
|
ItemStack ret = null;
|
||||||
ItemStack held = player.inventory.getItemStack();
|
ItemStack held = player.inventory.getItemStack();
|
||||||
TileEntityDroneRequester requester = (TileEntityDroneRequester) crate;
|
TileEntityDroneRequester requester = (TileEntityDroneRequester) crate;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user