2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file ("TileEntityInputter.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
|
import ellpeck.actuallyadditions.network.gui.IButtonReactor;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
import ellpeck.actuallyadditions.network.gui.INumberReactor;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
import ellpeck.actuallyadditions.network.sync.IPacketSyncerToClient;
|
|
|
|
|
import ellpeck.actuallyadditions.network.sync.PacketSyncerToClient;
|
2015-04-19 01:50:02 +02:00
|
|
|
|
import ellpeck.actuallyadditions.util.WorldUtil;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
import net.minecraft.inventory.IInventory;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
|
|
2015-07-02 04:21:21 +02:00
|
|
|
|
public class TileEntityInputter extends TileEntityInventoryBase implements IButtonReactor, INumberReactor, IPacketSyncerToClient{
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onNumberReceived(int text, int textID, EntityPlayer player){
|
|
|
|
|
if(text != -1){
|
2015-07-09 15:55:26 +02:00
|
|
|
|
if(this.placeToPut instanceof IInventory){
|
|
|
|
|
if(textID == 0) this.slotToPutStart = Math.max(Math.min(text, ((IInventory)this.placeToPut).getSizeInventory()-1), 0);
|
|
|
|
|
if(textID == 1) this.slotToPutEnd = Math.max(Math.min(text, ((IInventory)this.placeToPut).getSizeInventory()), 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.placeToPull instanceof IInventory){
|
|
|
|
|
if(textID == 2) this.slotToPullStart = Math.max(Math.min(text, ((IInventory)this.placeToPull).getSizeInventory()-1), 0);
|
|
|
|
|
if(textID == 3) this.slotToPullEnd = Math.max(Math.min(text, ((IInventory)this.placeToPull).getSizeInventory()), 0);
|
|
|
|
|
}
|
2015-06-28 03:12:32 +02:00
|
|
|
|
}
|
|
|
|
|
this.markDirty();
|
|
|
|
|
}
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
2015-07-02 04:21:21 +02:00
|
|
|
|
@Override
|
|
|
|
|
public int[] getValues(){
|
|
|
|
|
return new int[]{sideToPut, sideToPull, slotToPutStart, slotToPutEnd, slotToPullStart, slotToPullEnd, this.isPutWhitelist ? 1 : 0, this.isPullWhitelist ? 1 : 0};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setValues(int[] values){
|
|
|
|
|
this.sideToPut = values[0];
|
|
|
|
|
this.sideToPull = values[1];
|
|
|
|
|
this.slotToPutStart = values[2];
|
|
|
|
|
this.slotToPutEnd = values[3];
|
|
|
|
|
this.slotToPullStart = values[4];
|
|
|
|
|
this.slotToPullEnd = values[5];
|
|
|
|
|
this.isPutWhitelist = values[6] == 1;
|
|
|
|
|
this.isPullWhitelist = values[7] == 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void sendUpdate(){
|
|
|
|
|
PacketSyncerToClient.sendPacket(this);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
|
public static class TileEntityInputterAdvanced extends TileEntityInputter{
|
|
|
|
|
|
|
|
|
|
public TileEntityInputterAdvanced(){
|
2015-06-12 19:12:06 +02:00
|
|
|
|
super(25, "inputterAdvanced");
|
2015-05-04 17:26:50 +02:00
|
|
|
|
this.isAdvanced = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
|
public static final int PUT_FILTER_START = 13;
|
|
|
|
|
public static final int PULL_FILTER_START = 1;
|
|
|
|
|
|
|
|
|
|
public static final int WHITELIST_PULL_BUTTON_ID = 87;
|
|
|
|
|
public static final int WHITELIST_PUT_BUTTON_ID = 88;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
public static final int OKAY_BUTTON_ID = 133;
|
2015-04-04 05:20:19 +02:00
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
|
public int sideToPut = -1;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastPutSide;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
|
|
|
|
public int slotToPutStart;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastPutStart;
|
2015-07-02 10:45:15 +02:00
|
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
|
public int slotToPutEnd;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastPutEnd;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
|
public TileEntity placeToPut;
|
|
|
|
|
|
|
|
|
|
public int sideToPull = -1;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastPullSide;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
|
|
|
|
public int slotToPullStart;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastPullStart;
|
2015-07-02 10:45:15 +02:00
|
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
|
public int slotToPullEnd;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private int lastPullEnd;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
|
public TileEntity placeToPull;
|
|
|
|
|
|
2015-04-04 05:20:19 +02:00
|
|
|
|
public boolean isAdvanced;
|
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
|
public boolean isPullWhitelist = true;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private boolean lastPullWhite;
|
2015-07-02 10:45:15 +02:00
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
|
public boolean isPutWhitelist = true;
|
2015-07-02 04:21:21 +02:00
|
|
|
|
private boolean lastPutWhite;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
|
public TileEntityInputter(int slots, String name){
|
|
|
|
|
super(slots, name);
|
2015-04-04 05:20:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-04 17:26:50 +02:00
|
|
|
|
public TileEntityInputter(){
|
|
|
|
|
super(1, "inputter");
|
|
|
|
|
this.isAdvanced = false;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updateEntity(){
|
|
|
|
|
if(!worldObj.isRemote){
|
|
|
|
|
this.initVars();
|
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Is Block not powered by Redstone?
|
2015-04-04 05:20:19 +02:00
|
|
|
|
if(!worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)){
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(!(this.sideToPull == this.sideToPut && this.slotToPullStart == this.slotToPutStart && this.slotToPullEnd == this.slotToPutEnd)){
|
|
|
|
|
if(sideToPull != -1 && this.placeToPull instanceof IInventory) this.pull();
|
|
|
|
|
if(sideToPut != -1 && this.placeToPut instanceof IInventory) this.put();
|
2015-04-04 05:20:19 +02:00
|
|
|
|
}
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
2015-07-02 04:21:21 +02:00
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Update the Client
|
2015-07-02 04:21:21 +02:00
|
|
|
|
if(this.sideToPut != this.lastPutSide || this.sideToPull != this.lastPullSide || this.slotToPullStart != this.lastPullStart || this.slotToPullEnd != this.lastPullEnd || this.slotToPutStart != this.lastPutStart || this.slotToPutEnd != this.lastPutEnd || this.isPullWhitelist != lastPullWhite || this.isPutWhitelist != this.lastPutWhite){
|
|
|
|
|
this.lastPutSide = this.sideToPut;
|
|
|
|
|
this.lastPullSide = this.sideToPull;
|
|
|
|
|
this.lastPullStart = this.slotToPullStart;
|
|
|
|
|
this.lastPullEnd = this.slotToPullEnd;
|
|
|
|
|
this.lastPutStart = this.slotToPutStart;
|
|
|
|
|
this.lastPutEnd = this.slotToPutEnd;
|
|
|
|
|
this.lastPullWhite = this.isPullWhitelist;
|
|
|
|
|
this.lastPutWhite = this.isPutWhitelist;
|
|
|
|
|
this.sendUpdate();
|
|
|
|
|
}
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* Pulls Items from the specified Slots on the specified Side
|
|
|
|
|
*/
|
2015-03-19 21:27:56 +01:00
|
|
|
|
public void pull(){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//The Inventory to pull from
|
2015-06-28 03:12:32 +02:00
|
|
|
|
IInventory theInventory = (IInventory)placeToPull;
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Does the Inventory even have Slots!?
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(theInventory.getSizeInventory() > 0){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//The slot currently pulling from (for later)
|
2015-06-28 03:12:32 +02:00
|
|
|
|
int theSlotToPull = this.slotToPullStart;
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//The amount of Items that can fit into one slot of the inventory
|
2015-03-29 15:29:05 +02:00
|
|
|
|
int maxSize = theInventory.getInventoryStackLimit();
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If the Inventory is ISided, deal with that
|
2015-03-29 15:29:05 +02:00
|
|
|
|
ISidedInventory theSided = null;
|
|
|
|
|
if(theInventory instanceof ISidedInventory) theSided = (ISidedInventory)theInventory;
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If can be pulled (for later)
|
2015-06-28 03:12:32 +02:00
|
|
|
|
boolean can = false;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//The Stack that is pulled (for later)
|
2015-03-19 21:27:56 +01:00
|
|
|
|
ItemStack theStack = null;
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Go through all of the specified Slots
|
2015-07-03 01:22:09 +02:00
|
|
|
|
for(int i = Math.max(theSlotToPull, 0); i < Math.min(this.slotToPullEnd, theInventory.getSizeInventory()); i++){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Temporary Stack for storage
|
2015-03-29 15:29:05 +02:00
|
|
|
|
ItemStack tempStack = theInventory.getStackInSlot(i);
|
|
|
|
|
if(tempStack != null){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Set maxSize to the max Size of the temporary stack if it's smaller than the Inventory's Max Size
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(tempStack.getMaxStackSize() < this.getInventoryStackLimit()) maxSize = tempStack.getMaxStackSize();
|
|
|
|
|
else maxSize = this.getInventoryStackLimit();
|
|
|
|
|
}
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If ESD has enough Space & Item in question is on whitelist
|
2015-08-04 10:14:23 +02:00
|
|
|
|
if(tempStack != null && (this.slots[0] == null || (tempStack.isItemEqual(this.slots[0]) && this.slots[0].stackSize < maxSize)) && this.checkBothFilters(tempStack)){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Deal with ISided
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(theSided != null){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Check if Item can be inserted from any Side (Because Sidedness gets ignored!)
|
2015-08-09 22:04:28 +02:00
|
|
|
|
for(int j = 0; j <= 5; j++){
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(theSided.canExtractItem(i, tempStack, j)){
|
|
|
|
|
theStack = tempStack;
|
|
|
|
|
theSlotToPull = i;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
can = true;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Deal with IInventory
|
2015-03-29 15:29:05 +02:00
|
|
|
|
else{
|
2015-03-19 21:27:56 +01:00
|
|
|
|
theStack = tempStack;
|
|
|
|
|
theSlotToPull = i;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
can = true;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Stop if it can already pull
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(can) break;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If pull can be done
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(can){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If ESD already has Items
|
2015-03-19 21:27:56 +01:00
|
|
|
|
if(this.slots[0] != null){
|
|
|
|
|
if(theStack.isItemEqual(this.slots[0])){
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If the StackSize is smaller than the space the ESD has left
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(theStack.stackSize <= maxSize - this.slots[0].stackSize){
|
2015-03-19 21:27:56 +01:00
|
|
|
|
this.slots[0].stackSize += theStack.stackSize;
|
|
|
|
|
theInventory.setInventorySlotContents(theSlotToPull, null);
|
|
|
|
|
}
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If the StackSize is bigger than what fits into the Inventory
|
2015-03-29 15:29:05 +02:00
|
|
|
|
else if(theStack.stackSize > maxSize - this.slots[0].stackSize){
|
|
|
|
|
theInventory.decrStackSize(theSlotToPull, maxSize - this.slots[0].stackSize);
|
|
|
|
|
this.slots[0].stackSize = maxSize;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//If ESD is empty
|
2015-03-19 21:27:56 +01:00
|
|
|
|
else{
|
2015-03-20 18:58:31 +01:00
|
|
|
|
ItemStack toBePut = theStack.copy();
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(maxSize < toBePut.stackSize) toBePut.stackSize = maxSize;
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Actually puts the Item
|
2015-03-20 18:58:31 +01:00
|
|
|
|
this.setInventorySlotContents(0, toBePut);
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Removes the Item from the inventory getting pulled from
|
2015-03-20 18:58:31 +01:00
|
|
|
|
if(theStack.stackSize == toBePut.stackSize) theInventory.setInventorySlotContents(theSlotToPull, null);
|
2015-03-29 15:29:05 +02:00
|
|
|
|
else theInventory.decrStackSize(theSlotToPull, toBePut.stackSize);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* Puts Items into the specified Slots at the specified Side
|
|
|
|
|
* (Check pull() for Description, similar to this)
|
|
|
|
|
*/
|
2015-03-19 21:27:56 +01:00
|
|
|
|
public void put(){
|
2015-06-28 03:12:32 +02:00
|
|
|
|
IInventory theInventory = (IInventory)placeToPut;
|
|
|
|
|
if(theInventory.getSizeInventory() > 0){
|
|
|
|
|
int theSlotToPut = this.slotToPutStart;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
int maxSize = theInventory.getInventoryStackLimit();
|
|
|
|
|
ISidedInventory theSided = null;
|
|
|
|
|
if(theInventory instanceof ISidedInventory) theSided = (ISidedInventory)theInventory;
|
|
|
|
|
boolean can = false;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
|
|
|
|
if(this.slots[0] != null){
|
|
|
|
|
ItemStack theStack = null;
|
2015-07-03 01:22:09 +02:00
|
|
|
|
for(int i = Math.max(theSlotToPut, 0); i < Math.min(this.slotToPutEnd, theInventory.getSizeInventory()); i++){
|
2015-03-29 15:29:05 +02:00
|
|
|
|
ItemStack tempStack = theInventory.getStackInSlot(i);
|
|
|
|
|
if(tempStack != null){
|
|
|
|
|
if(tempStack.getMaxStackSize() < theInventory.getInventoryStackLimit()) maxSize = tempStack.getMaxStackSize();
|
|
|
|
|
else maxSize = theInventory.getInventoryStackLimit();
|
|
|
|
|
}
|
2015-08-04 10:14:23 +02:00
|
|
|
|
if(theInventory.isItemValidForSlot(i, this.slots[0]) && (tempStack == null || (tempStack.isItemEqual(this.slots[0]) && tempStack.stackSize < maxSize)) && this.checkBothFilters(this.slots[0])){
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(theSided != null){
|
2015-08-09 22:04:28 +02:00
|
|
|
|
for(int j = 0; j <= 5; j++){
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(theSided.canInsertItem(i, this.slots[0], j)){
|
|
|
|
|
theStack = tempStack;
|
|
|
|
|
theSlotToPut = i;
|
|
|
|
|
can = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
2015-03-19 21:27:56 +01:00
|
|
|
|
theStack = tempStack;
|
|
|
|
|
theSlotToPut = i;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
can = true;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(can) break;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(can){
|
2015-03-19 21:27:56 +01:00
|
|
|
|
if(theStack != null){
|
2015-08-10 12:51:13 +02:00
|
|
|
|
ItemStack copiedStack = theStack.copy();
|
|
|
|
|
if(copiedStack.isItemEqual(this.slots[0])){
|
|
|
|
|
if(this.slots[0].stackSize <= maxSize - copiedStack.stackSize){
|
|
|
|
|
copiedStack.stackSize += this.slots[0].stackSize;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
this.slots[0] = null;
|
2015-08-10 12:51:13 +02:00
|
|
|
|
theInventory.setInventorySlotContents(theSlotToPut, copiedStack);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
2015-08-10 12:51:13 +02:00
|
|
|
|
else if(this.slots[0].stackSize > maxSize - copiedStack.stackSize){
|
|
|
|
|
this.decrStackSize(0, maxSize - copiedStack.stackSize);
|
|
|
|
|
copiedStack.stackSize = maxSize;
|
|
|
|
|
theInventory.setInventorySlotContents(theSlotToPut, copiedStack);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
2015-03-20 18:58:31 +01:00
|
|
|
|
ItemStack toBePut = this.slots[0].copy();
|
2015-03-29 15:29:05 +02:00
|
|
|
|
if(maxSize < toBePut.stackSize) toBePut.stackSize = maxSize;
|
2015-03-20 18:58:31 +01:00
|
|
|
|
theInventory.setInventorySlotContents(theSlotToPut, toBePut);
|
|
|
|
|
if(this.slots[0].stackSize == toBePut.stackSize) this.slots[0] = null;
|
2015-03-29 15:29:05 +02:00
|
|
|
|
else this.decrStackSize(0, toBePut.stackSize);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-04 10:14:23 +02:00
|
|
|
|
/**
|
|
|
|
|
* Checks if one of the filters contains the ItemStack
|
|
|
|
|
* (Whitelist or empty Blacklist in one of them always lets the Item through!)
|
|
|
|
|
* @param stack The ItemStack
|
|
|
|
|
* @return If the Item is filtered correctly
|
|
|
|
|
*/
|
|
|
|
|
private boolean checkBothFilters(ItemStack stack){
|
|
|
|
|
return this.checkFilter(stack, true, isPullWhitelist) || this.checkFilter(stack, false, isPutWhitelist);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* Checks the Whitelist/Blacklist to see if Item fits
|
|
|
|
|
* @param stack The Stack to check for
|
|
|
|
|
* @param isPull If we're pulling or putting
|
|
|
|
|
* @param isWhitelist If it's set to white- or Blacklist
|
|
|
|
|
* @return Is Item on White-/Blacklist?
|
|
|
|
|
*/
|
2015-08-04 10:14:23 +02:00
|
|
|
|
private boolean checkFilter(ItemStack stack, boolean isPull, boolean isWhitelist){
|
2015-04-04 05:20:19 +02:00
|
|
|
|
if(!this.isAdvanced) return true;
|
|
|
|
|
|
|
|
|
|
int slotStart = isPull ? PULL_FILTER_START : PUT_FILTER_START;
|
2015-06-12 19:12:06 +02:00
|
|
|
|
int slotStop = slotStart+12;
|
2015-04-04 05:20:19 +02:00
|
|
|
|
|
|
|
|
|
for(int i = slotStart; i < slotStop; i++){
|
2015-06-12 19:12:06 +02:00
|
|
|
|
if(this.slots[i] != null && this.slots[i].isItemEqual(stack)) return isWhitelist;
|
2015-04-04 05:20:19 +02:00
|
|
|
|
}
|
2015-06-12 19:12:06 +02:00
|
|
|
|
return !isWhitelist;
|
2015-04-04 05:20:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* Sets all of the relevant variables
|
|
|
|
|
*/
|
2015-03-19 21:27:56 +01:00
|
|
|
|
public void initVars(){
|
2015-05-04 17:26:50 +02:00
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Gets the Place to put and Pull
|
2015-07-27 08:40:24 +02:00
|
|
|
|
this.placeToPull = WorldUtil.getTileEntityFromSide(WorldUtil.getDirectionBySidesInOrder(this.sideToPull), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
|
|
|
|
this.placeToPut = WorldUtil.getTileEntityFromSide(WorldUtil.getDirectionBySidesInOrder(this.sideToPut), this.worldObj, this.xCoord, this.yCoord, this.zCoord);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Resets the Variables
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(this.placeToPull instanceof IInventory){
|
|
|
|
|
if(this.slotToPullEnd <= 0) this.slotToPullEnd = ((IInventory)this.placeToPull).getSizeInventory();
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(this.placeToPut instanceof IInventory){
|
|
|
|
|
if(this.slotToPutEnd <= 0) this.slotToPutEnd = ((IInventory)this.placeToPut).getSizeInventory();
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-12 19:12:06 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void onButtonPressed(int buttonID, EntityPlayer player){
|
|
|
|
|
if(buttonID == WHITELIST_PULL_BUTTON_ID){
|
|
|
|
|
this.isPullWhitelist = !this.isPullWhitelist;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(buttonID == WHITELIST_PUT_BUTTON_ID){
|
|
|
|
|
this.isPutWhitelist = !this.isPutWhitelist;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 18:24:43 +02:00
|
|
|
|
//Reset the Slots
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(buttonID == 0 || buttonID == 1){
|
|
|
|
|
this.slotToPutStart = 0;
|
|
|
|
|
this.slotToPutEnd = 0;
|
|
|
|
|
}
|
|
|
|
|
if(buttonID == 2 || buttonID == 3){
|
|
|
|
|
this.slotToPullStart = 0;
|
|
|
|
|
this.slotToPullEnd = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
|
if(buttonID == 0) this.sideToPut++;
|
|
|
|
|
if(buttonID == 1) this.sideToPut--;
|
|
|
|
|
|
2015-06-28 03:12:32 +02:00
|
|
|
|
if(buttonID == 2) this.sideToPull++;
|
|
|
|
|
if(buttonID == 3) this.sideToPull--;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
|
|
|
|
|
if(this.sideToPut >= 6) this.sideToPut = -1;
|
|
|
|
|
else if(this.sideToPut < -1) this.sideToPut = 5;
|
|
|
|
|
else if(this.sideToPull >= 6) this.sideToPull = -1;
|
|
|
|
|
else if(this.sideToPull < -1) this.sideToPull = 5;
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
|
|
|
|
this.markDirty();
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void writeToNBT(NBTTagCompound compound){
|
|
|
|
|
super.writeToNBT(compound);
|
|
|
|
|
compound.setInteger("SideToPut", this.sideToPut);
|
2015-06-28 03:12:32 +02:00
|
|
|
|
compound.setInteger("SlotToPut", this.slotToPutStart);
|
|
|
|
|
compound.setInteger("SlotToPutEnd", this.slotToPutEnd);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
compound.setInteger("SideToPull", this.sideToPull);
|
2015-06-28 03:12:32 +02:00
|
|
|
|
compound.setInteger("SlotToPull", this.slotToPullStart);
|
|
|
|
|
compound.setInteger("SlotToPullEnd", this.slotToPullEnd);
|
2015-06-12 19:12:06 +02:00
|
|
|
|
compound.setBoolean("PullWhitelist", this.isPullWhitelist);
|
|
|
|
|
compound.setBoolean("PutWhitelist", this.isPutWhitelist);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
|
this.sideToPut = compound.getInteger("SideToPut");
|
2015-06-28 03:12:32 +02:00
|
|
|
|
this.slotToPutStart = compound.getInteger("SlotToPut");
|
|
|
|
|
this.slotToPutEnd = compound.getInteger("SlotToPutEnd");
|
2015-03-19 21:27:56 +01:00
|
|
|
|
this.sideToPull = compound.getInteger("SideToPull");
|
2015-06-28 03:12:32 +02:00
|
|
|
|
this.slotToPullStart = compound.getInteger("SlotToPull");
|
|
|
|
|
this.slotToPullEnd = compound.getInteger("SlotToPullEnd");
|
2015-06-12 19:12:06 +02:00
|
|
|
|
this.isPullWhitelist = compound.getBoolean("PullWhitelist");
|
|
|
|
|
this.isPutWhitelist = compound.getBoolean("PutWhitelist");
|
2015-04-04 05:20:19 +02:00
|
|
|
|
super.readFromNBT(compound);
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
2015-06-28 03:12:32 +02:00
|
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
|
@Override
|
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2015-04-04 05:20:19 +02:00
|
|
|
|
return i == 0;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
|
|
|
|
return this.isItemValidForSlot(slot, stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
2015-04-04 05:20:19 +02:00
|
|
|
|
return slot == 0;
|
2015-03-19 21:27:56 +01:00
|
|
|
|
}
|
2015-06-28 03:12:32 +02:00
|
|
|
|
}
|