2016-05-16 22:52:27 +02:00
|
|
|
/*
|
|
|
|
* This file ("TileEntityLaserRelayItemWhitelist.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://ellpeck.de/actaddlicense
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2016-05-16 22:52:27 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
|
|
|
|
2016-06-07 23:17:06 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
|
2016-12-03 10:52:03 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
|
2016-06-07 23:17:06 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
|
2016-05-14 17:50:10 +02:00
|
|
|
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
|
2016-11-16 16:59:00 +01:00
|
|
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
2016-05-14 17:50:10 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
2016-11-27 11:37:55 +01:00
|
|
|
import net.minecraft.inventory.InventoryBasic;
|
2016-05-14 17:50:10 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
|
|
|
|
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
|
|
|
|
|
2016-11-27 11:37:55 +01:00
|
|
|
public FilterSettings leftFilter = new FilterSettings(12, true, true, false, false, 0, -1000);
|
|
|
|
public FilterSettings rightFilter = new FilterSettings(12, true, true, false, false, 0, -2000);
|
2016-05-14 17:50:10 +02:00
|
|
|
|
|
|
|
public TileEntityLaserRelayItemWhitelist(){
|
|
|
|
super("laserRelayItemWhitelist");
|
|
|
|
}
|
|
|
|
|
2016-11-16 18:51:23 +01:00
|
|
|
@Override
|
|
|
|
public int getPriority(){
|
|
|
|
return super.getPriority()+10;
|
|
|
|
}
|
|
|
|
|
2016-06-17 23:50:38 +02:00
|
|
|
@Override
|
|
|
|
public boolean isWhitelisted(ItemStack stack, boolean output){
|
2016-11-27 11:37:55 +01:00
|
|
|
return output ? this.rightFilter.check(stack) : this.leftFilter.check(stack);
|
2016-06-17 23:50:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
2016-12-03 10:52:03 +01:00
|
|
|
|
|
|
|
this.leftFilter.writeToNBT(compound, "LeftFilter");
|
|
|
|
this.rightFilter.writeToNBT(compound, "RightFilter");
|
2016-06-17 23:50:38 +02:00
|
|
|
}
|
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
2016-12-03 10:52:03 +01:00
|
|
|
|
|
|
|
this.leftFilter.readFromNBT(compound, "LeftFilter");
|
|
|
|
this.rightFilter.readFromNBT(compound, "RightFilter");
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onButtonPressed(int buttonID, EntityPlayer player){
|
2016-07-23 19:20:53 +02:00
|
|
|
this.leftFilter.onButtonPressed(buttonID);
|
|
|
|
this.rightFilter.onButtonPressed(buttonID);
|
|
|
|
if(buttonID == 2){
|
2016-06-06 17:59:01 +02:00
|
|
|
this.addWhitelistSmart(false);
|
|
|
|
}
|
|
|
|
else if(buttonID == 3){
|
|
|
|
this.addWhitelistSmart(true);
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 17:59:01 +02:00
|
|
|
private void addWhitelistSmart(boolean output){
|
2016-07-23 19:20:53 +02:00
|
|
|
FilterSettings usedSettings = output ? this.rightFilter : this.leftFilter;
|
2016-08-06 02:17:11 +02:00
|
|
|
for(IItemHandler handler : this.handlersAround.values()){
|
2016-05-14 17:50:10 +02:00
|
|
|
for(int i = 0; i < handler.getSlots(); i++){
|
|
|
|
ItemStack stack = handler.getStackInSlot(i);
|
2016-11-16 16:59:00 +01:00
|
|
|
if(StackUtil.isValid(stack)){
|
2016-06-07 23:17:06 +02:00
|
|
|
ItemStack copy = stack.copy();
|
2016-11-16 16:59:00 +01:00
|
|
|
copy = StackUtil.setStackSize(copy, 1);
|
2016-06-07 23:17:06 +02:00
|
|
|
|
2016-11-27 11:37:55 +01:00
|
|
|
if(!FilterSettings.check(copy, usedSettings.filterInventory, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){
|
|
|
|
for(int k = 0; k < usedSettings.filterInventory.getSizeInventory(); k++){
|
|
|
|
ItemStack slot = usedSettings.filterInventory.getStackInSlot(k);
|
|
|
|
if(StackUtil.isValid(slot)){
|
2016-12-03 10:52:03 +01:00
|
|
|
if(SlotFilter.isFilter(slot)){
|
2016-11-27 11:37:55 +01:00
|
|
|
IInventory inv = new InventoryBasic("Filter", false, ContainerFilter.SLOT_AMOUNT);
|
|
|
|
ItemDrill.loadSlotsFromNBT(inv, slot);
|
2016-06-10 17:53:11 +02:00
|
|
|
|
|
|
|
boolean did = false;
|
2016-11-27 11:37:55 +01:00
|
|
|
for(int j = 0; j < inv.getSizeInventory(); j++){
|
|
|
|
if(!StackUtil.isValid(inv.getStackInSlot(j))){
|
|
|
|
inv.setInventorySlotContents(j, copy);
|
|
|
|
did = true;
|
|
|
|
break;
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 17:53:11 +02:00
|
|
|
if(did){
|
2016-11-27 11:37:55 +01:00
|
|
|
ItemDrill.writeSlotsToNBT(inv, slot);
|
2016-06-10 17:53:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
2016-06-10 17:53:11 +02:00
|
|
|
else{
|
2016-11-27 11:37:55 +01:00
|
|
|
usedSettings.filterInventory.setInventorySlotContents(k, copy);
|
2016-06-10 17:53:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity(){
|
|
|
|
super.updateEntity();
|
|
|
|
|
2016-11-26 21:32:27 +01:00
|
|
|
if(!this.world.isRemote){
|
2016-07-23 19:20:53 +02:00
|
|
|
if((this.leftFilter.needsUpdateSend() || this.rightFilter.needsUpdateSend()) && this.sendUpdateWithInterval()){
|
|
|
|
this.leftFilter.updateLasts();
|
|
|
|
this.rightFilter.updateLasts();
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|