use of forestry.storage.items.ItemBackpack in project ForestryMC by ForestryMC.
the class BackpackInterface method createNaturalistBackpack.
@Override
public Item createNaturalistBackpack(String backpackUid, ISpeciesRoot speciesRoot) {
Preconditions.checkNotNull(backpackUid, "backpackUid must not be null");
Preconditions.checkNotNull(speciesRoot, "speciesRoot must not be null");
IBackpackDefinition definition = definitions.get(backpackUid);
if (definition == null) {
throw new IllegalArgumentException("No backpack definition was registered for UID: " + backpackUid);
}
ItemBackpack backpack = new ItemBackpackNaturalist(speciesRoot, definition);
Proxies.common.registerItem(backpack);
return backpack;
}
use of forestry.storage.items.ItemBackpack in project ForestryMC by ForestryMC.
the class BackpackInterface method createBackpack.
@Override
public Item createBackpack(String backpackUid, EnumBackpackType type) {
Preconditions.checkNotNull(backpackUid, "backpackUid must not be null");
Preconditions.checkNotNull(type, "type must not be null");
Preconditions.checkArgument(type != EnumBackpackType.NATURALIST, "type must not be NATURALIST. Use createNaturalistBackpack instead.");
IBackpackDefinition definition = definitions.get(backpackUid);
if (definition == null) {
throw new IllegalArgumentException("No backpack definition was registered for UID: " + backpackUid);
}
ItemBackpack backpack = new ItemBackpack(definition, type);
Proxies.common.registerItem(backpack);
return backpack;
}
use of forestry.storage.items.ItemBackpack in project ForestryMC by ForestryMC.
the class PickupHandlerStorage method onItemPickup.
@Override
public boolean onItemPickup(EntityPlayer player, EntityItem entityitem) {
ItemStack itemstack = entityitem.getItem();
if (itemstack.isEmpty()) {
return false;
}
// Do not pick up if a backpack is open
if (player.openContainer instanceof ContainerBackpack || player.openContainer instanceof ContainerNaturalistBackpack) {
return false;
}
// Make sure to top off manually placed itemstacks in player inventory first
topOffPlayerInventory(player, itemstack);
for (ItemStack pack : player.inventory.mainInventory) {
if (itemstack.isEmpty()) {
break;
}
if (pack.isEmpty() || !(pack.getItem() instanceof ItemBackpack)) {
continue;
}
ItemBackpack backpack = (ItemBackpack) pack.getItem();
IBackpackDefinition backpackDefinition = backpack.getDefinition();
if (backpackDefinition.getFilter().test(itemstack)) {
ItemBackpack.tryStowing(player, pack, itemstack);
}
}
return itemstack.isEmpty();
}
use of forestry.storage.items.ItemBackpack in project ForestryMC by ForestryMC.
the class ResupplyHandler method resupply.
@Override
public void resupply(EntityPlayer player) {
// Do not attempt resupplying if this backpack is already opened.
if (!(player.openContainer instanceof ContainerPlayer)) {
return;
}
for (ItemStack backpack : getBackpacks(player.inventory)) {
if (ItemBackpack.getMode(backpack) == BackpackMode.RESUPPLY) {
// Load their inventory
ItemBackpack backpackItem = (ItemBackpack) backpack.getItem();
ItemInventory backpackInventory = new ItemInventoryBackpack(player, backpackItem.getBackpackSize(), backpack);
Event event = new BackpackResupplyEvent(player, backpackItem.getDefinition(), backpackInventory);
if (!MinecraftForge.EVENT_BUS.post(event)) {
for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
ItemStack itemStack = backpackInventory.getStackInSlot(i);
if (topOffPlayerInventory(player, itemStack)) {
backpackInventory.setInventorySlotContents(i, itemStack);
break;
}
}
}
}
}
}
Aggregations