Removed redundant function from backpack API. All checks for item validity now use IBackpackDefinition.isItemValid() resulting in more consistent behaivor.

This commit is contained in:
CovertJaguar committed 2014-08-12 03:47:28 -07:00
1 parent 38ed2fec51
commit 54146d29b9
6 files changed
+19 -25

No files matched your search

+1
View File
@@ -26,3 +26,4 @@ gradle.properties
# Other
*~
.nb-gradle-properties
+1 -1
Submodule api updated: 87b3cd16ca...960034e1e6.
@@ -20,6 +20,7 @@ import forestry.core.config.Defaults;
import forestry.core.utils.StringUtil;
public class BackpackDefinition implements IBackpackDefinition {
final String name;
final int primaryColor; // - c03384
@@ -64,12 +65,10 @@ public class BackpackDefinition implements IBackpackDefinition {
@Override
public void addValidItem(ItemStack validItem) {
if (validItem.getItem() != null) {
if (validItem.getItem() != null)
this.validItems.add(validItem);
}
}
@Override
public ArrayList<ItemStack> getValidItems(EntityPlayer player) {
return validItems;
}
@@ -77,13 +76,12 @@ public class BackpackDefinition implements IBackpackDefinition {
@Override
public boolean isValidItem(EntityPlayer player, ItemStack itemstack) {
for (ItemStack stack : getValidItems(player))
if (stack != null && stack.getItem() != null ) {
if (stack != null && stack.getItem() != null)
if (stack.getItemDamage() == Defaults.WILDCARD) {
if (stack.getItem() == itemstack.getItem())
return true;
} else if (stack.isItemEqual(itemstack))
return true;
}
return false;
}
@@ -4,7 +4,7 @@
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
@@ -15,13 +15,13 @@ import net.minecraft.item.ItemStack;
import forestry.core.config.Defaults;
import forestry.core.gui.ContainerItemInventory;
import forestry.core.gui.slots.SlotCustom;
import forestry.core.gui.slots.SlotForestry;
import forestry.core.utils.ItemInventory;
import forestry.storage.items.ItemBackpack;
public class ContainerBackpack extends ContainerItemInventory {
public ContainerBackpack(EntityPlayer player, ItemInventory inventory) {
public ContainerBackpack(final EntityPlayer player, ItemInventory inventory) {
super(inventory, player);
int lines = 0;
@@ -44,7 +44,14 @@ public class ContainerBackpack extends ContainerItemInventory {
for (int j = 0; j < lines; j++)
for (int k = 0; k < columns; k++) {
int slot = k + j * columns;
addSlot(new SlotCustom(inventory, ((ItemBackpack) inventory.parent.getItem()).getValidItems(player), slot, startX + k * 18, startY + j * 18));
addSlot(new SlotForestry(inventory, slot, startX + k * 18, startY + j * 18) {
@Override
public boolean isItemValid(ItemStack stack) {
return isAcceptedItem(player, stack);
}
});
}
// Player inventory
@@ -10,7 +10,6 @@
******************************************************************************/
package forestry.storage.items;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@@ -190,7 +189,7 @@ public class ItemBackpack extends ItemInventoried {
if (targetStack == null)
continue;
if(!info.isValidItem(player, targetStack))
if (!info.isValidItem(player, targetStack))
continue;
ItemStack remaining = InvTools.moveItemStack(targetStack, backpackInventory);
@@ -215,15 +214,11 @@ public class ItemBackpack extends ItemInventoried {
return stack.getItem() == this;
}
public Collection<ItemStack> getValidItems(EntityPlayer player) {
return info.getValidItems(player);
}
public int getBackpackSize() {
return getSlotsForType(type);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void addInformation(ItemStack itemstack, EntityPlayer player, List list, boolean flag) {
ItemInventory inventory = new ItemInventory(ItemBackpack.class, getBackpackSize(), itemstack);
@@ -4,14 +4,12 @@
* are made available under the terms of the GNU Lesser Public License v3
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.txt
*
*
* Various Contributors including, but not limited to:
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
******************************************************************************/
package forestry.storage.items;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
@@ -56,9 +54,4 @@ public class ItemNaturalistBackpack extends ItemBackpack {
public void openGui(EntityPlayer player, ItemStack itemstack) {
player.openGui(ForestryAPI.instance, guiId, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
}
@Override
public ArrayList<ItemStack> getValidItems(EntityPlayer player) {
return null;
}
}