Update for 1.11. Missing assets, unstable.

This commit is contained in:
mezz committed 2016-12-22 16:47:56 -08:00
1 parent 30d7365518
commit 9611ae08ae
1145 files changed
+15561 -18107

No files matched your search

@@ -10,8 +10,7 @@
******************************************************************************/
package forestry.storage;
import javax.annotation.Nonnull;
import java.awt.*;
import java.awt.Color;
import java.util.function.Predicate;
import forestry.api.storage.BackpackManager;
@@ -24,26 +23,23 @@ import net.minecraft.nbt.NBTTagCompound;
public class BackpackDefinition implements IBackpackDefinition {
private final int primaryColor;
private final int secondaryColor;
@Nonnull
private final Predicate<ItemStack> filter;
public BackpackDefinition(@Nonnull Color primaryColor, @Nonnull Color secondaryColor) {
public BackpackDefinition(Color primaryColor, Color secondaryColor) {
this(primaryColor, secondaryColor, BackpackManager.backpackInterface.createBackpackFilter());
}
public BackpackDefinition(@Nonnull Color primaryColor, @Nonnull Color secondaryColor, @Nonnull Predicate<ItemStack> filter) {
public BackpackDefinition(Color primaryColor, Color secondaryColor, Predicate<ItemStack> filter) {
this.primaryColor = primaryColor.getRGB();
this.secondaryColor = secondaryColor.getRGB();
this.filter = filter;
}
@Override
@Nonnull
public Predicate<ItemStack> getFilter() {
return filter;
}
@Nonnull
@Override
public String getName(ItemStack backpack) {
Item item = backpack.getItem();
@@ -55,15 +55,11 @@ public class BackpackFilter implements IBackpackFilterConfigurable {
@Override
public boolean test(ItemStack itemStack) {
if (itemStack == null) {
if (itemStack.isEmpty()) {
return false;
}
Item item = itemStack.getItem();
if (item == null) {
return false;
}
String itemStackStringWild = ItemStackUtil.getItemNameFromRegistryAsString(item);
if (rejectedItemStacks.contains(itemStackStringWild)) {
return false;
@@ -1,6 +1,5 @@
package forestry.storage;
import javax.annotation.Nonnull;
import java.util.function.Predicate;
import forestry.api.genetics.AlleleManager;
@@ -8,16 +7,15 @@ import forestry.api.genetics.ISpeciesRoot;
import net.minecraft.item.ItemStack;
public class BackpackFilterNaturalist implements Predicate<ItemStack> {
@Nonnull
private final String speciesRootUid;
public BackpackFilterNaturalist(@Nonnull String speciesRootUid) {
public BackpackFilterNaturalist(String speciesRootUid) {
this.speciesRootUid = speciesRootUid;
}
@Override
public boolean test(ItemStack itemStack) {
ISpeciesRoot speciesRoot = AlleleManager.alleleRegistry.getSpeciesRoot(speciesRootUid);
return speciesRoot.isMember(itemStack);
return speciesRoot != null && speciesRoot.isMember(itemStack);
}
}
@@ -10,12 +10,12 @@
******************************************************************************/
package forestry.storage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Predicate;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import forestry.api.genetics.ISpeciesRoot;
@@ -39,53 +39,36 @@ public class BackpackInterface implements IBackpackInterface {
}
@Override
public void addItemToForestryBackpack(@Nullable String backpackUid, @Nullable ItemStack itemStack) {
if (backpackUid == null) {
throw new NullPointerException("backpackUid must not be null");
}
if (itemStack == null) {
throw new NullPointerException("itemStack must not be null");
}
if (itemStack.getItem() == null) {
throw new NullPointerException("itemStack.getItem() must not be null");
}
public void addItemToForestryBackpack(String backpackUid, ItemStack itemStack) {
Preconditions.checkNotNull(backpackUid, "backpackUid must not be null");
Preconditions.checkNotNull(itemStack, "itemStack must not be null");
Preconditions.checkArgument(!itemStack.isEmpty(), "itemStack must not be empty");
String stringForItemStack = ItemStackUtil.getStringForItemStack(itemStack);
backpackAcceptedItems.put(backpackUid, stringForItemStack);
}
@Override
public void registerBackpackDefinition(@Nullable String backpackUid, @Nullable IBackpackDefinition definition) {
if (backpackUid == null) {
throw new NullPointerException("backpackUid must not be null");
}
if (definition == null) {
throw new NullPointerException("definition must not be null");
}
public void registerBackpackDefinition(String backpackUid, IBackpackDefinition definition) {
Preconditions.checkNotNull(backpackUid, "backpackUid must not be null");
Preconditions.checkNotNull(definition, "definition must not be null");
definitions.put(backpackUid, definition);
}
@Nullable
@Override
public IBackpackDefinition getBackpackDefinition(@Nullable String backpackUid) {
if (backpackUid == null) {
throw new NullPointerException("backpackUid must not be null");
}
public IBackpackDefinition getBackpackDefinition(String backpackUid) {
Preconditions.checkNotNull(backpackUid, "backpackUid must not be null");
return definitions.get(backpackUid);
}
@Nonnull
@Override
public Item createBackpack(@Nullable String backpackUid, @Nullable EnumBackpackType type) {
if (backpackUid == null) {
throw new NullPointerException("backpackUid must not be null");
}
if (type == null) {
throw new NullPointerException("type must not be null");
}
if (type == EnumBackpackType.NATURALIST) {
throw new IllegalArgumentException("type must not be NATURALIST. Use createNaturalistBackpack instead.");
}
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) {
@@ -95,13 +78,9 @@ public class BackpackInterface implements IBackpackInterface {
}
@Override
public Item createNaturalistBackpack(@Nullable String backpackUid, @Nullable ISpeciesRoot speciesRoot) {
if (backpackUid == null) {
throw new NullPointerException("backpackUid must not be null");
}
if (speciesRoot == null) {
throw new NullPointerException("speciesRoot must not be null");
}
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) {
@@ -10,26 +10,23 @@
******************************************************************************/
package forestry.storage;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;
import forestry.api.storage.ICrateRegistry;
import forestry.core.items.ItemCrated;
import forestry.core.proxy.Proxies;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.Log;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.OreDictionary;
public class CrateRegistry implements ICrateRegistry {
private static void registerCrate(@Nonnull ItemStack stack, @Nullable String oreDictName) {
if (stack == null || stack.getItem() == null) {
private static void registerCrate(ItemStack stack, @Nullable String oreDictName) {
if (stack.isEmpty()) {
Log.warning("Tried to make a crate without an item");
return;
}
@@ -52,7 +49,7 @@ public class CrateRegistry implements ICrateRegistry {
}
@Override
public void registerCrate(@Nonnull String oreDictName) {
public void registerCrate(String oreDictName) {
if (OreDictionary.doesOreNameExist(oreDictName)) {
for (ItemStack stack : OreDictionary.getOres(oreDictName)) {
if (stack != null) {
@@ -64,17 +61,17 @@ public class CrateRegistry implements ICrateRegistry {
}
@Override
public void registerCrate(@Nonnull Block block) {
public void registerCrate(Block block) {
registerCrate(new ItemStack(block), null);
}
@Override
public void registerCrate(@Nonnull Item item) {
public void registerCrate(Item item) {
registerCrate(new ItemStack(item), null);
}
@Override
public void registerCrate(@Nonnull ItemStack stack) {
public void registerCrate(ItemStack stack) {
registerCrate(stack, null);
}
}
@@ -25,7 +25,7 @@ public class PickupHandlerStorage implements IPickupHandler {
public boolean onItemPickup(EntityPlayer player, EntityItem entityitem) {
ItemStack itemstack = entityitem.getEntityItem();
if (itemstack == null || itemstack.stackSize <= 0) {
if (itemstack.isEmpty()) {
return false;
}
@@ -38,12 +38,7 @@ public class PickupHandlerStorage implements IPickupHandler {
topOffPlayerInventory(player, itemstack);
for (ItemStack pack : player.inventory.mainInventory) {
if (pack == null || pack.stackSize <= 0) {
continue;
}
if (itemstack.stackSize <= 0) {
if (pack.isEmpty() || itemstack.isEmpty()) {
break;
}
@@ -58,7 +53,7 @@ public class PickupHandlerStorage implements IPickupHandler {
}
}
return itemstack.stackSize == 0;
return itemstack.isEmpty();
}
/**
@@ -72,27 +67,26 @@ public class PickupHandlerStorage implements IPickupHandler {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack inventoryStack = player.inventory.getStackInSlot(i);
// We only add to existing stacks.
if (inventoryStack == null) {
if (inventoryStack.isEmpty()) {
continue;
}
// Already full
if (inventoryStack.stackSize >= inventoryStack.getMaxStackSize()) {
if (inventoryStack.getCount() >= inventoryStack.getMaxStackSize()) {
continue;
}
if (inventoryStack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(inventoryStack, itemstack)) {
int space = inventoryStack.getMaxStackSize() - inventoryStack.stackSize;
int space = inventoryStack.getMaxStackSize() - inventoryStack.getCount();
// Enough space to add all
if (space > itemstack.stackSize) {
inventoryStack.stackSize += itemstack.stackSize;
itemstack.stackSize = 0;
break;
// Only part can be added
if (space > itemstack.getCount()) {
// Enough space to add all
inventoryStack.grow(itemstack.getCount());
itemstack.setCount(0);
} else {
inventoryStack.stackSize = inventoryStack.getMaxStackSize();
itemstack.stackSize -= space;
// Only part can be added
inventoryStack.setCount(inventoryStack.getMaxStackSize());
itemstack.shrink(space);
}
}
}
@@ -10,8 +10,8 @@
******************************************************************************/
package forestry.storage;
import javax.annotation.Nonnull;
import java.awt.*;
import javax.annotation.Nullable;
import java.awt.Color;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Set;
import java.util.function.Predicate;
import com.google.common.base.Preconditions;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import forestry.Forestry;
@@ -38,6 +39,7 @@ import forestry.core.PluginCore;
import forestry.core.config.Constants;
import forestry.core.config.LocalizedConfiguration;
import forestry.core.items.ItemCrated;
import forestry.core.items.ItemRegistryCore;
import forestry.core.models.ModelCrate;
import forestry.core.recipes.RecipeUtil;
import forestry.core.utils.IMCUtil;
@@ -72,12 +74,14 @@ import net.minecraftforge.oredict.OreDictionary;
@ForestryPlugin(pluginID = ForestryPluginUids.STORAGE, name = "Storage", author = "SirSengir", url = Constants.URL, unlocalizedDescription = "for.plugin.storage.description")
public class PluginStorage extends BlankForestryPlugin {
@SuppressWarnings("NullableProblems")
@SidedProxy(clientSide = "forestry.storage.proxy.ProxyStorageClient", serverSide = "forestry.storage.proxy.ProxyStorage")
public static ProxyStorage proxy;
private static final List<ItemCrated> crates = new ArrayList<>();
private static final String CONFIG_CATEGORY = "backpacks";
@Nullable
public static ItemRegistryStorage items;
private final Multimap<String, String> backpackAcceptedOreDictRegexpDefaults = HashMultimap.create();
@@ -133,7 +137,7 @@ public class PluginStorage extends BlankForestryPlugin {
definition = new BackpackDefinition(new Color(0xdd3a3a), Color.WHITE);
BackpackManager.backpackInterface.registerBackpackDefinition(BackpackManager.BUILDER_UID, definition);
proxy.registerCrateModel();
}
@@ -141,7 +145,7 @@ public class PluginStorage extends BlankForestryPlugin {
public void registerItemsAndBlocks() {
items = new ItemRegistryStorage();
}
@Override
public void preInit() {
registerFenceAndFenceGatesToOreDict();
@@ -163,7 +167,7 @@ public class PluginStorage extends BlankForestryPlugin {
setDefaultsForConfig();
for (String backpackUid : forestryBackpackUids) {
for (String backpackUid : forestryBackpackUids) {
handleBackpackConfig(config, backpackUid);
}
@@ -171,6 +175,9 @@ public class PluginStorage extends BlankForestryPlugin {
}
private void setDefaultsForConfig() {
ItemRegistryCore coreItems = PluginCore.items;
Preconditions.checkState(coreItems != null);
backpackAcceptedOreDictRegexpDefaults.get(BackpackManager.MINER_UID).addAll(Arrays.asList(
"obsidian",
"ore[A-Z].*",
@@ -245,9 +252,9 @@ public class PluginStorage extends BlankForestryPlugin {
backpackAcceptedItemDefaults.get(BackpackManager.MINER_UID).addAll(getItemStrings(Arrays.asList(
new ItemStack(Blocks.COAL_ORE),
new ItemStack(Items.COAL),
PluginCore.items.bronzePickaxe.getItemStack(),
PluginCore.items.kitPickaxe.getItemStack(),
PluginCore.items.brokenBronzePickaxe.getItemStack()
coreItems.bronzePickaxe.getItemStack(),
coreItems.kitPickaxe.getItemStack(),
coreItems.brokenBronzePickaxe.getItemStack()
)));
backpackAcceptedItemDefaults.get(BackpackManager.DIGGER_UID).addAll(getItemStrings(Arrays.asList(
@@ -257,9 +264,9 @@ public class PluginStorage extends BlankForestryPlugin {
new ItemStack(Items.CLAY_BALL),
new ItemStack(Items.SNOWBALL),
new ItemStack(Blocks.SOUL_SAND),
PluginCore.items.bronzeShovel.getItemStack(),
PluginCore.items.kitShovel.getItemStack(),
PluginCore.items.brokenBronzeShovel.getItemStack()
coreItems.bronzeShovel.getItemStack(),
coreItems.kitShovel.getItemStack(),
coreItems.brokenBronzeShovel.getItemStack()
)));
backpackAcceptedItemDefaults.get(BackpackManager.FORESTER_UID).addAll(getItemStrings(Arrays.asList(
@@ -404,7 +411,6 @@ public class PluginStorage extends BlankForestryPlugin {
OreDictionary.registerOre(OreDictUtil.FENCE_GATE_WOOD, Blocks.ACACIA_FENCE_GATE);
}
@Nonnull
private static Set<String> getItemStrings(List<ItemStack> itemStacks) {
Set<String> itemStrings = new HashSet<>(itemStacks.size());
for (ItemStack itemStack : itemStacks) {
@@ -511,7 +517,7 @@ public class PluginStorage extends BlankForestryPlugin {
for (ItemCrated crate : crates) {
ItemStack crateStack = new ItemStack(crate);
ItemStack uncrated = crate.getContained();
if (uncrated != null) {
if (!uncrated.isEmpty()) {
if (crate.getOreDictName() != null) {
addCrating(crateStack, crate.getOreDictName());
} else {
@@ -522,15 +528,17 @@ public class PluginStorage extends BlankForestryPlugin {
}
}
private static void addCrating(@Nonnull ItemStack crateStack, @Nonnull Object uncrated) {
private static void addCrating(ItemStack crateStack, Object uncrated) {
Preconditions.checkState(items != null);
FluidStack water = new FluidStack(FluidRegistry.WATER, Constants.CARPENTER_CRATING_LIQUID_QUANTITY);
ItemStack box = items.crate.getItemStack();
RecipeManagers.carpenterManager.addRecipe(Constants.CARPENTER_CRATING_CYCLES, water, box, crateStack, "###", "###", "###", '#', uncrated);
}
private static void addUncrating(@Nonnull ItemStack crateStack, @Nonnull ItemStack uncrated) {
private static void addUncrating(ItemStack crateStack, ItemStack uncrated) {
ItemStack product = new ItemStack(uncrated.getItem(), 9, uncrated.getItemDamage());
RecipeManagers.carpenterManager.addRecipe(Constants.CARPENTER_UNCRATING_CYCLES, null, product, "#", '#', crateStack);
RecipeManagers.carpenterManager.addRecipe(Constants.CARPENTER_UNCRATING_CYCLES, ItemStack.EMPTY, product, "#", '#', crateStack);
}
@Override
@@ -574,6 +582,8 @@ public class PluginStorage extends BlankForestryPlugin {
@Override
public void registerRecipes() {
Preconditions.checkState(items != null);
BlockRegistryApiculture beeBlocks = PluginApiculture.blocks;
if (items.apiaristBackpack != null && beeBlocks != null) {
addBackpackRecipe(items.apiaristBackpack, "stickWood", beeBlocks.beeChest);
@@ -595,7 +605,7 @@ public class PluginStorage extends BlankForestryPlugin {
// / CARPENTER
if (ForestryAPI.enabledPlugins.contains(ForestryPluginUids.FACTORY)) {
// / CRATES
RecipeManagers.carpenterManager.addRecipe(20, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME), null, items.crate.getItemStack(24),
RecipeManagers.carpenterManager.addRecipe(20, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME), ItemStack.EMPTY, items.crate.getItemStack(24),
" # ", "# #", " # ", '#', "logWood");
// / BACKPACKS WOVEN
@@ -624,8 +634,11 @@ public class PluginStorage extends BlankForestryPlugin {
}
private static void addT2BackpackRecipe(Item backpackT1, Item backpackT2) {
ItemStack wovenSilk = PluginCore.items.craftingMaterial.getWovenSilk();
RecipeManagers.carpenterManager.addRecipe(200, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME), null, new ItemStack(backpackT2),
ItemRegistryCore coreItems = PluginCore.items;
Preconditions.checkState(coreItems != null);
ItemStack wovenSilk = coreItems.craftingMaterial.getWovenSilk();
RecipeManagers.carpenterManager.addRecipe(200, new FluidStack(FluidRegistry.WATER, Fluid.BUCKET_VOLUME), ItemStack.EMPTY, new ItemStack(backpackT2),
"WXW",
"WTW",
"WWW",
@@ -633,7 +646,7 @@ public class PluginStorage extends BlankForestryPlugin {
'W', wovenSilk,
'T', backpackT1);
}
@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onBakeModel(ModelBakeEvent event) {
@@ -32,7 +32,7 @@ public class ResupplyHandler implements IResupplyHandler {
private static List<ItemStack> backpacks(InventoryPlayer playerInventory) {
List<ItemStack> backpacks = new ArrayList<>();
for (ItemStack itemStack : playerInventory.mainInventory) {
if (itemStack != null && itemStack.stackSize > 0 && itemStack.getItem() instanceof ItemBackpack) {
if (itemStack.getItem() instanceof ItemBackpack) {
backpacks.add(itemStack);
}
}
@@ -74,7 +74,7 @@ public class ResupplyHandler implements IResupplyHandler {
for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
ItemStack itemStack = backpackInventory.getStackInSlot(i);
if (itemStack == null || itemStack.stackSize <= 0) {
if (itemStack.isEmpty()) {
continue;
}
@@ -98,18 +98,18 @@ public class ResupplyHandler implements IResupplyHandler {
for (int i = 0; i < player.inventory.getSizeInventory(); i++) {
ItemStack inventoryStack = player.inventory.getStackInSlot(i);
// We only add to existing stacks.
if (inventoryStack == null) {
if (inventoryStack.isEmpty()) {
continue;
}
// Already full
if (inventoryStack.stackSize >= inventoryStack.getMaxStackSize()) {
if (inventoryStack.getCount() >= inventoryStack.getMaxStackSize()) {
continue;
}
if (inventoryStack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(inventoryStack, itemstack)) {
inventoryStack.stackSize++;
itemstack.stackSize--;
inventoryStack.grow(1);
itemstack.shrink(1);
return true;
}
}
@@ -1,7 +1,5 @@
package forestry.storage.compat;
import javax.annotation.Nonnull;
import forestry.core.utils.JeiUtil;
import forestry.storage.PluginStorage;
import forestry.storage.items.ItemRegistryStorage;
@@ -12,7 +10,7 @@ import mezz.jei.api.JEIPlugin;
@JEIPlugin
public class StorageJeiPlugin extends BlankModPlugin {
@Override
public void register(@Nonnull IModRegistry registry) {
public void register(IModRegistry registry) {
ItemRegistryStorage items = PluginStorage.items;
JeiUtil.addDescription(registry, "minerBag",
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.storage.compat;
import javax.annotation.ParametersAreNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
@@ -10,14 +10,12 @@
******************************************************************************/
package forestry.storage.gui;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import forestry.core.gui.ContainerItemInventory;
import forestry.core.gui.ContainerNaturalistInventory;
import forestry.core.gui.IGuiSelectable;
import forestry.core.network.packets.PacketGuiSelectRequest;
import forestry.storage.inventory.ItemInventoryBackpackPaged;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
public class ContainerNaturalistBackpack extends ContainerItemInventory<ItemInventoryBackpackPaged> implements IGuiSelectable {
@@ -28,7 +26,7 @@ public class ContainerNaturalistBackpack extends ContainerItemInventory<ItemInve
}
@Override
public void handleSelectionRequest(EntityPlayerMP player, PacketGuiSelectRequest packet) {
inventory.flipPage(player, (short) packet.getPrimaryIndex());
public void handleSelectionRequest(EntityPlayerMP player, int primary, int secondary) {
inventory.flipPage(player, (short) primary);
}
}
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.storage.gui;
import javax.annotation.ParametersAreNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
@@ -1,5 +1,6 @@
package forestry.storage.inventory;
import com.google.common.base.Preconditions;
import forestry.api.storage.IBackpackDefinition;
import forestry.core.inventory.ItemInventory;
import forestry.storage.items.ItemBackpack;
@@ -14,14 +15,8 @@ public class ItemInventoryBackpack extends ItemInventory {
public ItemInventoryBackpack(EntityPlayer player, int size, ItemStack parent) {
super(player, size, parent);
if (parent == null) {
throw new IllegalArgumentException("Parent cannot be null.");
}
Item item = parent.getItem();
if (!(item instanceof ItemBackpack)) {
throw new IllegalArgumentException("Parent must be a backpack.");
}
Preconditions.checkArgument(item instanceof ItemBackpack, "Parent must be a backpack.");
this.backpackDefinition = ((ItemBackpack) item).getDefinition();
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.storage.inventory;
import javax.annotation.ParametersAreNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
@@ -14,6 +14,7 @@ import javax.annotation.Nullable;
import java.util.List;
import java.util.Locale;
import com.google.common.base.Preconditions;
import forestry.api.core.IModelManager;
import forestry.api.storage.BackpackStowEvent;
import forestry.api.storage.EnumBackpackType;
@@ -21,9 +22,9 @@ import forestry.api.storage.IBackpackDefinition;
import forestry.core.config.Config;
import forestry.core.config.Constants;
import forestry.core.gui.GuiHandler;
import forestry.core.inventory.ItemHandlerInventoryManipulator;
import forestry.core.inventory.ItemInventory;
import forestry.core.inventory.filters.StandardStackFilters;
import forestry.core.inventory.manipulators.ItemHandlerInventoryManipulator;
import forestry.core.inventory.StandardStackFilters;
import forestry.core.items.IColoredItem;
import forestry.core.items.ItemWithGui;
import forestry.core.tiles.TileUtil;
@@ -76,17 +77,18 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) {
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
if (!playerIn.isSneaking()) {
return super.onItemRightClick(itemStackIn, worldIn, playerIn, hand);
return super.onItemRightClick(worldIn, playerIn, handIn);
} else {
switchMode(itemStackIn);
return ActionResult.newResult(EnumActionResult.SUCCESS, itemStackIn);
ItemStack heldItem = playerIn.getHeldItem(handIn);
switchMode(heldItem);
return ActionResult.newResult(EnumActionResult.SUCCESS, heldItem);
}
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
if (getInventoryHit(worldIn, pos, facing) != null) {
return EnumActionResult.SUCCESS;
}
@@ -94,12 +96,13 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
}
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
public EnumActionResult onItemUseFirst(EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
// We only do this when shift is clicked
if (player.isSneaking()) {
return evaluateTileHit(stack, player, world, pos, side) ? EnumActionResult.PASS : EnumActionResult.FAIL;
ItemStack heldItem = player.getHeldItem(hand);
return evaluateTileHit(heldItem, player, world, pos, side) ? EnumActionResult.PASS : EnumActionResult.FAIL;
}
return super.onItemUseFirst(stack, player, world, pos, side, hitX, hitY, hitZ, hand);
return super.onItemUseFirst(player, world, pos, side, hitX, hitY, hitZ, hand);
}
public static void tryStowing(EntityPlayer player, ItemStack backpackStack, ItemStack stack) {
@@ -113,7 +116,7 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
if (MinecraftForge.EVENT_BUS.post(new BackpackStowEvent(player, backpack.getDefinition(), inventory, stack))) {
return;
}
if (stack.stackSize <= 0) {
if (stack.isEmpty()) {
return;
}
@@ -121,7 +124,7 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
ItemHandlerInventoryManipulator manipulator = new ItemHandlerInventoryManipulator(itemHandler);
ItemStack remainder = manipulator.addStack(stack);
stack.stackSize = remainder == null ? 0 : remainder.stackSize;
stack.setCount(remainder == null ? 0 : remainder.getCount());
}
private static void switchMode(ItemStack itemstack) {
@@ -134,9 +137,10 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
itemstack.setItemDamage(nextMode);
}
@Nullable
private static IItemHandler getInventoryHit(World world, BlockPos pos, EnumFacing side) {
TileEntity targeted = world.getTileEntity(pos);
return TileUtil.getInventoryFromTile(targeted, null);
return TileUtil.getInventoryFromTile(targeted, side);
}
private boolean evaluateTileHit(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side) {
@@ -263,11 +267,8 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
}
}
@Nullable
public static BackpackMode getMode(ItemStack backpack) {
if (!(backpack.getItem() instanceof ItemBackpack)) {
return null;
}
Preconditions.checkArgument(backpack.getItem() instanceof ItemBackpack, "Item must be a backpack");
int meta = backpack.getItemDamage();
@@ -291,6 +292,7 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
@SuppressWarnings("incomplete-switch")
@Override
@Nullable
public Object getGui(EntityPlayer player, ItemStack heldItem, int data) {
if (data > EnumBackpackType.values().length) {
return null;
@@ -307,6 +309,7 @@ public class ItemBackpack extends ItemWithGui implements IColoredItem {
@SuppressWarnings("incomplete-switch")
@Override
@Nullable
public Object getContainer(EntityPlayer player, ItemStack heldItem, int data) {
if (data > EnumBackpackType.values().length) {
return null;
@@ -10,8 +10,6 @@
******************************************************************************/
package forestry.storage.items;
import javax.annotation.Nonnull;
import forestry.api.genetics.ISpeciesRoot;
import forestry.api.storage.EnumBackpackType;
import forestry.api.storage.IBackpackDefinition;
@@ -24,10 +22,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class ItemBackpackNaturalist extends ItemBackpack {
@Nonnull
private final ISpeciesRoot speciesRoot;
public ItemBackpackNaturalist(@Nonnull ISpeciesRoot speciesRoot, IBackpackDefinition definition) {
public ItemBackpackNaturalist(ISpeciesRoot speciesRoot, IBackpackDefinition definition) {
super(definition, EnumBackpackType.NATURALIST);
this.speciesRoot = speciesRoot;
}
@@ -10,6 +10,8 @@
******************************************************************************/
package forestry.storage.items;
import javax.annotation.Nullable;
import forestry.api.apiculture.BeeManager;
import forestry.api.core.ForestryAPI;
import forestry.api.core.Tabs;
@@ -21,11 +23,15 @@ import forestry.core.items.ItemCrated;
import forestry.core.items.ItemRegistry;
import forestry.plugins.ForestryPluginUids;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ItemRegistryStorage extends ItemRegistry {
public final ItemCrated crate;
@Nullable
public final Item apiaristBackpack;
@Nullable
public final Item lepidopteristBackpack;
public final Item minerBackpack;
public final Item minerBackpackT2;
public final Item diggerBackpack;
@@ -41,7 +47,7 @@ public class ItemRegistryStorage extends ItemRegistry {
public ItemRegistryStorage() {
// CRATE
crate = registerItem(new ItemCrated(null, null), "crate");
crate = registerItem(new ItemCrated(ItemStack.EMPTY, null), "crate");
// BACKPACKS
IBackpackInterface backpackInterface = BackpackManager.backpackInterface;
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.storage.items;
import javax.annotation.ParametersAreNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.storage;
import javax.annotation.ParametersAreNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;
@@ -5,6 +5,7 @@ import forestry.core.models.ModelEntry;
import forestry.core.proxy.Proxies;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
@SuppressWarnings("unused")
public class ProxyStorageClient extends ProxyStorage {
@Override
@@ -0,0 +1,9 @@
@ParametersAreNonnullByDefault
@FieldsAreNonnullByDefault
@MethodsReturnNonnullByDefault
package forestry.storage.proxy;
import javax.annotation.ParametersAreNonnullByDefault;
import forestry.core.utils.FieldsAreNonnullByDefault;
import mcp.MethodsReturnNonnullByDefault;