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;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
|
|
|
|
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
|
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;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-11-20 20:13:26 +01:00
|
|
|
import net.minecraft.util.NonNullList;
|
2016-05-14 17:50:10 +02:00
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2016-05-27 18:54:17 +02:00
|
|
|
import net.minecraft.util.text.TextComponentTranslation;
|
2016-05-14 17:50:10 +02:00
|
|
|
import net.minecraftforge.items.IItemHandler;
|
|
|
|
|
2016-11-16 16:59:00 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
|
|
|
|
|
2016-05-19 20:05:12 +02:00
|
|
|
public final IInventory filterInventory;
|
2016-11-17 14:56:26 +01:00
|
|
|
public FilterSettings leftFilter = new FilterSettings(0, 12, true, true, false, false, 0, -1000);
|
|
|
|
public FilterSettings rightFilter = new FilterSettings(12, 24, true, true, false, false, 0, -2000);
|
2016-11-20 20:13:26 +01:00
|
|
|
private NonNullList<ItemStack> slots = StackUtil.createSlots(24);
|
2016-05-14 17:50:10 +02:00
|
|
|
|
|
|
|
public TileEntityLaserRelayItemWhitelist(){
|
|
|
|
super("laserRelayItemWhitelist");
|
|
|
|
|
|
|
|
this.filterInventory = new IInventory(){
|
|
|
|
|
2016-05-27 18:54:17 +02:00
|
|
|
private TileEntityLaserRelayItemWhitelist tile;
|
2016-05-14 17:50:10 +02:00
|
|
|
|
2016-05-27 18:54:17 +02:00
|
|
|
private IInventory setTile(TileEntityLaserRelayItemWhitelist tile){
|
2016-05-14 17:50:10 +02:00
|
|
|
this.tile = tile;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
@Override
|
|
|
|
public String getName(){
|
|
|
|
return this.tile.name;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit(){
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markDirty(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean isUseableByPlayer(EntityPlayer player){
|
2016-05-14 17:50:10 +02:00
|
|
|
return this.tile.canPlayerUse(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public void openInventory(EntityPlayer player){
|
2016-05-14 17:50:10 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public void closeInventory(EntityPlayer player){
|
2016-05-14 17:50:10 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getField(int id){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setField(int id, int value){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getFieldCount(){
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear(){
|
2016-11-20 20:13:26 +01:00
|
|
|
this.tile.slots.clear();
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int i, ItemStack stack){
|
2016-11-20 20:13:26 +01:00
|
|
|
this.tile.slots.set(i, stack);
|
2016-05-14 17:50:10 +02:00
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory(){
|
2016-11-20 20:13:26 +01:00
|
|
|
return this.tile.slots.size();
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
|
2016-11-19 21:11:17 +01:00
|
|
|
@Override
|
|
|
|
public boolean func_191420_l(){
|
|
|
|
return StackUtil.isIInvEmpty(this.tile.slots);
|
|
|
|
}
|
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int i){
|
|
|
|
if(i < this.getSizeInventory()){
|
2016-11-20 20:13:26 +01:00
|
|
|
return this.tile.slots.get(i);
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
2016-11-16 16:59:00 +01:00
|
|
|
return StackUtil.getNull();
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int i, int j){
|
2016-11-20 20:13:26 +01:00
|
|
|
if(StackUtil.isValid(this.tile.slots.get(i))){
|
2016-05-14 17:50:10 +02:00
|
|
|
ItemStack stackAt;
|
2016-11-20 20:13:26 +01:00
|
|
|
if(StackUtil.getStackSize(this.tile.slots.get(i)) <= j){
|
|
|
|
stackAt = this.tile.slots.get(i);
|
|
|
|
this.tile.slots.set(i, StackUtil.getNull());
|
2016-05-14 17:50:10 +02:00
|
|
|
this.markDirty();
|
|
|
|
return stackAt;
|
|
|
|
}
|
|
|
|
else{
|
2016-11-20 20:13:26 +01:00
|
|
|
stackAt = this.tile.slots.get(i).splitStack(j);
|
|
|
|
if(StackUtil.getStackSize(this.tile.slots.get(i)) <= 0){
|
|
|
|
this.tile.slots.set(i, StackUtil.getNull());
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
this.markDirty();
|
|
|
|
return stackAt;
|
|
|
|
}
|
|
|
|
}
|
2016-11-16 16:59:00 +01:00
|
|
|
return StackUtil.getNull();
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack removeStackFromSlot(int index){
|
2016-11-20 20:13:26 +01:00
|
|
|
ItemStack stack = this.tile.slots.get(index);
|
|
|
|
this.tile.slots.set(index, StackUtil.getNull());
|
2016-05-14 17:50:10 +02:00
|
|
|
return stack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomName(){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-29 23:49:35 +02:00
|
|
|
|
2016-05-14 17:50:10 +02:00
|
|
|
@Override
|
|
|
|
public ITextComponent getDisplayName(){
|
2016-05-27 18:54:17 +02:00
|
|
|
return new TextComponentTranslation(this.getName());
|
2016-05-14 17:50:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean isItemValidForSlot(int index, ItemStack stack){
|
2016-05-14 17:50:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}.setTile(this);
|
|
|
|
}
|
|
|
|
|
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-07-23 19:20:53 +02:00
|
|
|
return output ? this.rightFilter.check(stack, this.slots) : this.leftFilter.check(stack, this.slots);
|
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);
|
|
|
|
if(type == NBTType.SAVE_TILE){
|
2016-06-17 23:50:38 +02:00
|
|
|
TileEntityInventoryBase.saveSlots(this.slots, compound);
|
|
|
|
}
|
2016-07-23 19:20:53 +02:00
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
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);
|
|
|
|
if(type == NBTType.SAVE_TILE){
|
2016-05-14 17:50:10 +02:00
|
|
|
TileEntityInventoryBase.loadSlots(this.slots, compound);
|
|
|
|
}
|
2016-07-23 19:20:53 +02:00
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
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-17 14:56:26 +01:00
|
|
|
if(!FilterSettings.check(copy, this.slots, usedSettings.startSlot, usedSettings.endSlot, true, usedSettings.respectMeta, usedSettings.respectNBT, usedSettings.respectMod, usedSettings.respectOredict)){
|
2016-07-23 19:20:53 +02:00
|
|
|
for(int k = usedSettings.startSlot; k < usedSettings.endSlot; k++){
|
2016-11-20 20:13:26 +01:00
|
|
|
if(StackUtil.isValid(this.slots.get(k))){
|
|
|
|
if(this.slots.get(k).getItem() instanceof ItemFilter){
|
|
|
|
NonNullList<ItemStack> filterSlots = StackUtil.createSlots(ContainerFilter.SLOT_AMOUNT);
|
|
|
|
ItemDrill.loadSlotsFromNBT(filterSlots, this.slots.get(k));
|
2016-06-10 17:53:11 +02:00
|
|
|
|
|
|
|
boolean did = false;
|
2016-11-20 20:13:26 +01:00
|
|
|
if(filterSlots != null && filterSlots.size() > 0){
|
|
|
|
for(int j = 0; j < filterSlots.size(); j++){
|
|
|
|
if(!StackUtil.isValid(filterSlots.get(j))){
|
|
|
|
filterSlots.set(j, copy);
|
2016-06-10 17:53:11 +02:00
|
|
|
did = true;
|
|
|
|
break;
|
|
|
|
}
|
2016-06-07 23:17:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-10 17:53:11 +02:00
|
|
|
if(did){
|
2016-11-20 20:13:26 +01:00
|
|
|
ItemDrill.writeSlotsToNBT(filterSlots, this.slots.get(k));
|
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-20 20:13:26 +01:00
|
|
|
this.slots.set(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();
|
|
|
|
|
|
|
|
if(!this.worldObj.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|