Added item filters

This commit is contained in:
Ellpeck 2016-06-07 23:17:06 +02:00
parent 0b025fe249
commit 9a9ec02eef
38 changed files with 493 additions and 106 deletions

View file

@ -168,7 +168,7 @@ public class CreativeTab extends CreativeTabs{
this.list.add(UniversalBucket.getFilledBucket(ForgeModContainer.getInstance().universalBucket, InitFluids.fluidOil));
this.add(InitItems.itemPhantomConnector);
this.add(InitItems.itemFilter);
this.add(InitItems.itemWingsOfTheBats);
this.add(InitItems.itemCoffeeSeed);

View file

@ -74,7 +74,7 @@ public class ContainerBreaker extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -76,7 +76,7 @@ public class ContainerCanolaPress extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -75,7 +75,7 @@ public class ContainerCoalGenerator extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -103,7 +103,7 @@ public class ContainerCoffeeMachine extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -74,7 +74,7 @@ public class ContainerCrafter extends Container{
return null;
}
if(savedStack.stackSize == 0){
if(savedStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -74,7 +74,7 @@ public class ContainerDirectionalBreaker extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -36,7 +36,7 @@ public class ContainerDrill extends Container{
this.inventory = inventory;
for(int i = 0; i < SLOT_AMOUNT; i++){
this.addSlotToContainer(new Slot(ContainerDrill.this.drillInventory, i, 44+i*18, 19){
this.addSlotToContainer(new Slot(this.drillInventory, i, 44+i*18, 19){
@Override
public boolean isItemValid(ItemStack stack){
return stack.getItem() instanceof ItemDrillUpgrade || stack.getItem() instanceof IEnergyContainerItem;
@ -60,10 +60,7 @@ public class ContainerDrill extends Container{
ItemStack stack = inventory.getCurrentItem();
if(stack != null && stack.getItem() instanceof ItemDrill){
ItemStack[] slots = ((ItemDrill)stack.getItem()).getSlotsFromNBT(inventory.getCurrentItem());
if(slots != null && slots.length > 0){
this.drillInventory.slots = slots;
}
ItemDrill.loadSlotsFromNBT(this.drillInventory.slots, inventory.getCurrentItem());
}
}
@ -103,7 +100,7 @@ public class ContainerDrill extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{
@ -134,7 +131,7 @@ public class ContainerDrill extends Container{
public void onContainerClosed(EntityPlayer player){
ItemStack stack = this.inventory.getCurrentItem();
if(stack != null && stack.getItem() instanceof ItemDrill){
((ItemDrill)stack.getItem()).writeSlotsToNBT(this.drillInventory.slots, this.inventory.getCurrentItem());
ItemDrill.writeSlotsToNBT(this.drillInventory.slots, this.inventory.getCurrentItem());
}
super.onContainerClosed(player);
}
@ -148,7 +145,6 @@ public class ContainerDrill extends Container{
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT];
@Override
public String getName(){
return "drill";

View file

@ -74,7 +74,7 @@ public class ContainerDropper extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -111,7 +111,7 @@ public class ContainerEnergizer extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -110,7 +110,7 @@ public class ContainerEnervator extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -69,7 +69,7 @@ public class ContainerFeeder extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -64,7 +64,7 @@ public class ContainerFermentingBarrel extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -0,0 +1,258 @@
/*
* This file ("ContainerFilter.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
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotFilter;
import de.ellpeck.actuallyadditions.mod.inventory.slot.SlotImmovable;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ClickType;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
public class ContainerFilter extends Container{
public static final int SLOT_AMOUNT = 24;
private final InventoryFilter filterInventory = new InventoryFilter();
private final InventoryPlayer inventory;
public ContainerFilter(InventoryPlayer inventory){
this.inventory = inventory;
for(int i = 0; i < 4; i++){
for(int j = 0; j < 6; j++){
this.addSlotToContainer(new SlotFilter(this.filterInventory, j+(i*6), 35+j*18, 10+i*18));
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8+j*18, 94+i*18));
}
}
for(int i = 0; i < 9; i++){
if(i == inventory.currentItem){
this.addSlotToContainer(new SlotImmovable(inventory, i, 8+i*18, 152));
}
else{
this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 152));
}
}
ItemStack stack = inventory.getCurrentItem();
if(stack != null && stack.getItem() instanceof ItemFilter){
ItemDrill.loadSlotsFromNBT(this.filterInventory.slots, inventory.getCurrentItem());
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
final int inventoryStart = SLOT_AMOUNT;
final int inventoryEnd = inventoryStart+26;
final int hotbarStart = inventoryEnd+1;
final int hotbarEnd = hotbarStart+8;
Slot theSlot = this.inventorySlots.get(slot);
if(theSlot != null && theSlot.getHasStack()){
ItemStack newStack = theSlot.getStack();
ItemStack currentStack = newStack.copy();
//Other Slots in Inventory excluded
if(slot >= inventoryStart){
//Shift from Inventory
//
if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
}
if(newStack.stackSize == 0){
theSlot.putStack(null);
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
}
@Override
public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player){
if(slotId >= 0 && slotId < this.inventorySlots.size() && this.getSlot(slotId) instanceof SlotFilter){
//Calls the Filter's SlotClick function
return ((SlotFilter)this.getSlot(slotId)).slotClick(player);
}
else if(clickTypeIn == ClickType.SWAP && dragType == this.inventory.currentItem){
return null;
}
else{
return super.slotClick(slotId, dragType, clickTypeIn, player);
}
}
@Override
public void onContainerClosed(EntityPlayer player){
ItemStack stack = this.inventory.getCurrentItem();
if(stack != null && stack.getItem() instanceof ItemFilter){
ItemDrill.writeSlotsToNBT(this.filterInventory.slots, this.inventory.getCurrentItem());
}
super.onContainerClosed(player);
}
@Override
public boolean canInteractWith(EntityPlayer player){
return this.filterInventory.isUseableByPlayer(player);
}
public static class InventoryFilter implements IInventory{
public ItemStack[] slots = new ItemStack[SLOT_AMOUNT];
@Override
public String getName(){
return "filter";
}
@Override
public int getInventoryStackLimit(){
return 64;
}
@Override
public void markDirty(){
}
@Override
public boolean isUseableByPlayer(EntityPlayer player){
return true;
}
@Override
public void openInventory(EntityPlayer player){
}
@Override
public void closeInventory(EntityPlayer player){
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack){
return true;
}
@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(){
int length = this.slots.length;
this.slots = new ItemStack[length];
}
@Override
public void setInventorySlotContents(int i, ItemStack stack){
this.slots[i] = stack;
this.markDirty();
}
@Override
public int getSizeInventory(){
return this.slots.length;
}
@Override
public ItemStack getStackInSlot(int i){
if(i < this.getSizeInventory()){
return this.slots[i];
}
return null;
}
@Override
public ItemStack decrStackSize(int i, int j){
if(this.slots[i] != null){
ItemStack stackAt;
if(this.slots[i].stackSize <= j){
stackAt = this.slots[i];
this.slots[i] = null;
this.markDirty();
return stackAt;
}
else{
stackAt = this.slots[i].splitStack(j);
if(this.slots[i].stackSize <= 0){
this.slots[i] = null;
}
this.markDirty();
return stackAt;
}
}
return null;
}
@Override
public ItemStack removeStackFromSlot(int index){
ItemStack stack = this.slots[index];
this.slots[index] = null;
return stack;
}
@Override
public boolean hasCustomName(){
return false;
}
@Override
public ITextComponent getDisplayName(){
return new TextComponentTranslation(this.getName());
}
}
}

View file

@ -71,7 +71,7 @@ public class ContainerFluidCollector extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -88,7 +88,7 @@ public class ContainerFurnaceDouble extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -75,7 +75,7 @@ public class ContainerGiantChest extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -99,7 +99,7 @@ public class ContainerGrinder extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -86,7 +86,7 @@ public class ContainerInputter extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -74,7 +74,7 @@ public class ContainerLaserRelayItemWhitelist extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -74,7 +74,7 @@ public class ContainerMiner extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -63,7 +63,7 @@ public class ContainerOilGenerator extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -74,7 +74,7 @@ public class ContainerPhantomPlacer extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -81,7 +81,7 @@ public class ContainerRangedCollector extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -76,7 +76,7 @@ public class ContainerRepairer extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -67,7 +67,7 @@ public class ContainerXPSolidifier extends Container{
return null;
}
if(newStack.stackSize == 0){
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{

View file

@ -74,6 +74,8 @@ public class GuiHandler implements IGuiHandler{
return new ContainerCoffeeMachine(entityPlayer.inventory, tile);
case DRILL:
return new ContainerDrill(entityPlayer.inventory);
case FILTER:
return new ContainerFilter(entityPlayer.inventory);
case ENERGIZER:
return new ContainerEnergizer(entityPlayer, tile);
case ENERVATOR:
@ -140,6 +142,8 @@ public class GuiHandler implements IGuiHandler{
return new GuiCoffeeMachine(entityPlayer.inventory, tile, x, y, z, world);
case DRILL:
return new GuiDrill(entityPlayer.inventory);
case FILTER:
return new GuiFilter(entityPlayer.inventory);
case ENERGIZER:
return new GuiEnergizer(entityPlayer, tile);
case ENERVATOR:
@ -194,7 +198,8 @@ public class GuiHandler implements IGuiHandler{
RANGED_COLLECTOR,
MINER,
BOOK_STAND,
LASER_RELAY_ITEM_WHITELIST;
LASER_RELAY_ITEM_WHITELIST,
FILTER(false);
public final boolean checkTileEntity;

View file

@ -0,0 +1,49 @@
/*
* This file ("GuiFilter.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
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiFilter extends GuiContainer{
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiFilter");
public GuiFilter(InventoryPlayer inventory){
super(new ContainerFilter(inventory));
this.xSize = 176;
this.ySize = 90+86;
}
@Override
public void drawGuiContainerForegroundLayer(int x, int y){
AssetUtil.displayNameString(this.fontRendererObj, this.xSize, -10, "container."+ModUtil.MOD_ID+".filter");
}
@Override
public void drawGuiContainerBackgroundLayer(float f, int x, int y){
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
this.drawTexturedModalRect(this.guiLeft, this.guiTop+90, 0, 0, 176, 86);
this.mc.getTextureManager().bindTexture(RES_LOC);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 90);
}
}

View file

@ -208,12 +208,14 @@ public class InitItems{
public static Item itemPaxelCrystalWhite;
public static Item itemWaterBowl;
public static Item itemFilter;
public static Item itemRarmorModuleReconstructor;
public static void init(){
ModUtil.LOGGER.info("Initializing Items...");
itemFilter = new ItemFilter("itemFilter");
itemWaterBowl = new ItemWaterBowl("itemWaterBowl");
itemSpawnerChanger = new ItemSpawnerChanger("itemSpawnerChanger");
itemMisc = new ItemMisc("itemMisc");

View file

@ -126,7 +126,8 @@ public class ItemDrill extends ItemEnergy{
return null;
}
ItemStack[] slots = this.getSlotsFromNBT(stack);
ItemStack[] slots = new ItemStack[ContainerDrill.SLOT_AMOUNT];
loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){
for(ItemStack slotStack : slots){
if(slotStack != null && slotStack.getItem() instanceof ItemDrillUpgrade){
@ -143,18 +144,12 @@ public class ItemDrill extends ItemEnergy{
* Gets all of the Slots from NBT
*
* @param stack The Drill
* @return All of the Slots
*/
public ItemStack[] getSlotsFromNBT(ItemStack stack){
public static void loadSlotsFromNBT(ItemStack[] slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound();
if(compound == null){
return null;
if(compound != null){
TileEntityInventoryBase.loadSlots(slots, compound);
}
ItemStack[] slots = new ItemStack[ContainerDrill.SLOT_AMOUNT];
TileEntityInventoryBase.loadSlots(slots, compound);
return slots;
}
@ -183,7 +178,8 @@ public class ItemDrill extends ItemEnergy{
//Checks for Energy Containers in the Upgrade Slots and charges the Drill from them
@Override
public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5){
ItemStack[] slots = this.getSlotsFromNBT(stack);
ItemStack[] slots = new ItemStack[ContainerDrill.SLOT_AMOUNT];
loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){
for(ItemStack slotStack : slots){
if(slotStack != null && slotStack.getItem() instanceof IEnergyContainerItem){
@ -395,7 +391,7 @@ public class ItemDrill extends ItemEnergy{
* @param slots The Slots
* @param stack The Drill
*/
public void writeSlotsToNBT(ItemStack[] slots, ItemStack stack){
public static void writeSlotsToNBT(ItemStack[] slots, ItemStack stack){
NBTTagCompound compound = stack.getTagCompound();
if(compound == null){
compound = new NBTTagCompound();

View file

@ -0,0 +1,60 @@
/*
* This file ("ItemFilter.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
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerDrill;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import java.util.List;
public class ItemFilter extends ItemBase{
public ItemFilter(String name){
super(name);
this.setMaxStackSize(1);
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.UNCOMMON;
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){
if(!world.isRemote){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FILTER.ordinal(), world, (int)player.posX, (int)player.posY, (int)player.posZ);
}
return new ActionResult<ItemStack>(EnumActionResult.PASS, stack);
}
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced){
ItemStack[] slots = new ItemStack[ContainerFilter.SLOT_AMOUNT];
ItemDrill.loadSlotsFromNBT(slots, stack);
if(slots != null && slots.length > 0){
for(ItemStack slot : slots){
if(slot != null && slot.getItem() != null){
tooltip.add(slot.getItem().getItemStackDisplayName(slot));
}
}
}
}
}

View file

@ -11,6 +11,7 @@
package de.ellpeck.actuallyadditions.mod.tile;
import com.sun.org.apache.bcel.internal.generic.PUTFIELD;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.network.gui.INumberReactor;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
@ -265,31 +266,8 @@ public class TileEntityInputter extends TileEntityInventoryBase implements IButt
* @return If the Item is filtered correctly
*/
private boolean checkBothFilters(ItemStack stack, boolean output){
return this.checkFilter(stack, !output, output ? this.isPutWhitelist : this.isPullWhitelist);
}
/**
* 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?
*/
private boolean checkFilter(ItemStack stack, boolean isPull, boolean isWhitelist){
if(!this.isAdvanced){
return true;
}
int slotStart = isPull ? PULL_FILTER_START : PUT_FILTER_START;
int slotStop = slotStart+12;
for(int i = slotStart; i < slotStop; i++){
if(this.slots[i] != null && this.slots[i].isItemEqual(stack)){
return isWhitelist;
}
}
return !isWhitelist;
int slotStart = output ? PUT_FILTER_START : PULL_FILTER_START;
return TileEntityLaserRelayItemWhitelist.checkFilter(stack, output ? this.isPutWhitelist : this.isPullWhitelist, this.slots, slotStart, slotStart+12);
}
/**

View file

@ -10,8 +10,10 @@
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFilter;
import de.ellpeck.actuallyadditions.mod.items.ItemDrill;
import de.ellpeck.actuallyadditions.mod.items.ItemFilter;
import de.ellpeck.actuallyadditions.mod.network.gui.IButtonReactor;
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@ -20,7 +22,6 @@ import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraftforge.items.IItemHandler;
import java.util.Arrays;
import java.util.List;
public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem implements IButtonReactor{
@ -164,19 +165,8 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
@Override
public boolean isWhitelisted(ItemStack stack, boolean output){
return this.checkFilter(stack, !output, output ? this.isRightWhitelist : this.isLeftWhitelist);
}
private boolean checkFilter(ItemStack stack, boolean left, boolean isWhitelist){
int slotStart = left ? 0 : 12;
int slotStop = slotStart+12;
for(int i = slotStart; i < slotStop; i++){
if(this.slots[i] != null && this.slots[i].isItemEqual(stack)){
return isWhitelist;
}
}
return !isWhitelist;
int slotStart = output ? 12 : 0;
return checkFilter(stack, output ? this.isRightWhitelist : this.isLeftWhitelist, this.slots, slotStart, slotStart+12);
}
@Override
@ -189,6 +179,30 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
compound.setBoolean("RightWhitelist", this.isRightWhitelist);
}
public static boolean checkFilter(ItemStack stack, boolean isWhitelist, ItemStack[] slots, int start, int end){
if(stack != null){
for(int i = start; i < end; i++){
if(slots[i] != null){
if(slots[i].isItemEqual(stack)){
return isWhitelist;
}
else if(slots[i].getItem() instanceof ItemFilter){
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT];
ItemDrill.loadSlotsFromNBT(filterSlots, slots[i]);
if(filterSlots != null && filterSlots.length > 0){
for(ItemStack filterSlot : filterSlots){
if(filterSlot != null && filterSlot.isItemEqual(stack)){
return isWhitelist;
}
}
}
}
}
}
}
return !isWhitelist;
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean isForSync){
super.readSyncableNBT(compound, isForSync);
@ -219,20 +233,52 @@ public class TileEntityLaserRelayItemWhitelist extends TileEntityLaserRelayItem
int slotStart = output ? 12 : 0;
int slotStop = slotStart+12;
for(int i = 0; i < this.slots.length; i++){
if(this.slots[i] != null){
if(this.slots[i].getItem() instanceof ItemFilter){
ItemDrill.writeSlotsToNBT(new ItemStack[ContainerFilter.SLOT_AMOUNT], this.slots[i]);
}
else{
this.slots[i] = null;
}
}
}
List<IItemHandler> handlers = this.getAllHandlersAround();
for(IItemHandler handler : handlers){
for(int i = 0; i < handler.getSlots(); i++){
ItemStack stack = handler.getStackInSlot(i);
if(stack != null){
if(!ItemUtil.contains(Arrays.copyOfRange(this.slots, slotStart, slotStop), stack, false)){
for(int j = slotStart; j < slotStop; j++){
if(this.slots[j] == null || this.slots[j].stackSize <= 0){
ItemStack whitelistStack = stack.copy();
whitelistStack.stackSize = 1;
this.slots[j] = whitelistStack;
break;
ItemStack copy = stack.copy();
copy.stackSize = 1;
for(int k = slotStart; k < slotStop; k++){
if(this.slots[k] != null){
if(this.slots[k].getItem() instanceof ItemFilter){
ItemStack[] filterSlots = new ItemStack[ContainerFilter.SLOT_AMOUNT];
ItemDrill.loadSlotsFromNBT(filterSlots, this.slots[k]);
boolean did = false;
if(filterSlots != null && filterSlots.length > 0){
for(int j = 0; j < filterSlots.length; j++){
if(filterSlots[j] == null || filterSlots[j].stackSize <= 0){
filterSlots[j] = copy;
did = true;
break;
}
}
}
if(did){
ItemDrill.writeSlotsToNBT(filterSlots, this.slots[k]);
break;
}
}
}
else{
this.slots[k] = copy;
break;
}
}
}
}

View file

@ -55,7 +55,7 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
for(EntityItem item : items){
if(!item.isDead && item.getEntityItem() != null){
ItemStack toAdd = item.getEntityItem().copy();
if(this.checkFilter(toAdd)){
if(TileEntityLaserRelayItemWhitelist.checkFilter(toAdd, this.isWhitelist, this.slots, WHITELIST_START, WHITELIST_START+12)){
ArrayList<ItemStack> checkList = new ArrayList<ItemStack>();
checkList.add(toAdd);
if(WorldUtil.addToInventory(this, 0, WHITELIST_START, checkList, EnumFacing.UP, false, true)){
@ -74,17 +74,6 @@ public class TileEntityRangedCollector extends TileEntityInventoryBase implement
}
}
private boolean checkFilter(ItemStack stack){
int slotStop = WHITELIST_START+12;
for(int i = WHITELIST_START; i < slotStop; i++){
if(this.slots[i] != null && this.slots[i].isItemEqual(stack)){
return this.isWhitelist;
}
}
return !this.isWhitelist;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return false;

View file

@ -490,6 +490,7 @@ item.actuallyadditions.itemSpawnerChanger.name=Spawner Changer
item.actuallyadditions.itemMiscSpawnerShard.name=Spawner Shards
item.actuallyadditions.itemMinecartFireworkBox.name=Firework Box Cart
item.actuallyadditions.itemWaterBowl.name=Bowl of Water
item.actuallyadditions.itemFilter.name=Item Filter
#Tooltips
tooltip.actuallyadditions.onSuffix.desc=On
@ -542,10 +543,10 @@ info.actuallyadditions.gui.coffee=Coffee
info.actuallyadditions.gui.ok=Ok
info.actuallyadditions.gui.the=the
info.actuallyadditions.gui.smart=Smart Whitelist
info.actuallyadditions.gui.smartInfo=When pressing this, all items from inventories adjacent to this relay will be added to this part of the white- or blacklist.
info.actuallyadditions.gui.smartInfo=When pressing this, all items from inventories adjacent to this relay will be added to this part of the white- or blacklist. Adding Item Filters to the list before will cause them to also be filled. Caution: Non-Item Filters previously added to the list will be removed and Item Filters will be cleared!
info.actuallyadditions.inputter.info.1=This is the first Slot in the connected Inventory to <p> at.
info.actuallyadditions.inputter.info.2=This is the slot after the last Slot in the connected Inventory to <p> at. What that means: If you, for example, write 2 in the field to the left and 5 in this one, it will <p> at Slot 2, 3, and 4.
info.actuallyadditions.inputter.whitelistInfo=When pressing this, this side's whitelist mode will be changed. To let all items through, an empty blacklist can be used, to let no items through, an empty whitelist can be used. To configure certain items, place them in the slots.
info.actuallyadditions.inputter.whitelistInfo=When pressing this, this side's whitelist mode will be changed. To let all items through, an empty blacklist can be used, to let no items through, an empty whitelist can be used. To configure certain items, place them or configured Item Filters in the slots.
info.actuallyadditions.noLens=No Lens
info.actuallyadditions.booklet.manualName.1=Actually Additions
info.actuallyadditions.booklet.manualName.2=Manual
@ -586,6 +587,7 @@ container.actuallyadditions.directionalBreaker.name=Long-Range Breaker
container.actuallyadditions.rangedCollector.name=Ranged Collector
container.actuallyadditions.miner.name=Vertical Digger
container.actuallyadditions.laserRelayItemWhitelist.name=Laser Relay
container.actuallyadditions.filter.name=Item Filter
#Update Information
info.actuallyadditions.update.generic=[{"text":"There is an Update for "},{"text":"Actually Additions ","color":"dark_green"},{"text":"available!","color":"none"}]

View file

@ -0,0 +1,6 @@
{
"parent": "actuallyadditions:item/standardItem",
"textures": {
"layer0": "actuallyadditions:items/itemFilter"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B