use of forestry.api.storage.IBackpackDefinition 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.api.storage.IBackpackDefinition 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.api.storage.IBackpackDefinition in project ForestryMC by ForestryMC.
the class ModuleBackpacks method processIMCMessage.
@Override
public boolean processIMCMessage(IMCMessage message) {
if (message.key.equals("add-backpack-items")) {
String[] tokens = message.getStringValue().split("@");
if (tokens.length != 2) {
IMCUtil.logInvalidIMCMessage(message);
return true;
}
String backpackUid = tokens[0];
String itemStackStrings = tokens[1];
IBackpackDefinition backpackDefinition = BackpackManager.backpackInterface.getBackpackDefinition(backpackUid);
if (backpackDefinition == null) {
String errorMessage = IMCUtil.getInvalidIMCMessageText(message);
Log.error("{} For non-existent backpack {}.", errorMessage, backpackUid);
return true;
}
List<ItemStack> itemStacks = ItemStackUtil.parseItemStackStrings(itemStackStrings, 0);
for (ItemStack itemStack : itemStacks) {
BackpackManager.backpackInterface.addItemToForestryBackpack(backpackUid, itemStack);
}
return true;
}
return false;
}
use of forestry.api.storage.IBackpackDefinition 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();
}
Aggregations