forked from mitchej123/FindIt
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for Forestry backpacks (#19)
- Loading branch information
Showing
5 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/com/gtnh/findit/util/mods/ForestryUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.gtnh.findit.util.mods; | ||
|
||
import java.util.Optional; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.inventory.IInventory; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
|
||
import forestry.storage.inventory.ItemInventoryBackpack; | ||
import forestry.storage.items.ItemBackpack; | ||
|
||
public class ForestryUtils { | ||
|
||
private ForestryUtils() {} | ||
|
||
public static Optional<IInventory> getInventoryOfPotentialStorageItem(ItemStack potentialBackpackItemStack) { | ||
// Checks for Forestry backpacks. | ||
Item item = potentialBackpackItemStack.getItem(); | ||
if (item instanceof ItemBackpack) { | ||
ItemBackpack backpack = (ItemBackpack) item; | ||
|
||
// We're running the GUI code client-side only, thus the only player interacting with the GUI is the | ||
// player that the backpack's inventory is checked against. | ||
EntityPlayer player = Minecraft.getMinecraft().thePlayer; | ||
|
||
ItemInventoryBackpack inventory = new ItemInventoryBackpack( | ||
player, | ||
backpack.getBackpackSize(), | ||
potentialBackpackItemStack); | ||
return Optional.of(inventory); | ||
} | ||
|
||
return Optional.empty(); | ||
} | ||
} |