/** * MrCrayfish's Furniture Mod * Copyright (C) 2016 MrCrayfish (http://www.mrcrayfish.com/) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.mrcrayfish.furniture.items; import com.mrcrayfish.furniture.MrCrayfishFurnitureMod; import com.mrcrayfish.furniture.gui.inventory.InventoryPackage; import com.mrcrayfish.furniture.tileentity.TileEntityMailBox; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.text.TextComponentString; import net.minecraft.world.World; public class ItemPackage extends Item implements IMail { public ItemPackage() { setMaxStackSize(1); setCreativeTab(MrCrayfishFurnitureMod.tabFurniture); } @Override public boolean getShareTag() { return true; } @Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { TileEntity tile_entity = worldIn.getTileEntity(pos); if (!worldIn.isRemote) { if (tile_entity instanceof TileEntityMailBox) { if (playerIn.isSneaking() && !worldIn.isRemote) { playerIn.addChatMessage(new TextComponentString("You must sign the package before depositing it.")); } } return EnumActionResult.SUCCESS; } return EnumActionResult.PASS; } @Override public ActionResult<ItemStack> onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn, EnumHand hand) { if (!worldIn.isRemote) { playerIn.openGui(MrCrayfishFurnitureMod.instance, 7, worldIn, 0, 0, 0); } return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemStackIn); } public static IInventory getInv(EntityPlayer par1EntityPlayer) { ItemStack mail = par1EntityPlayer.inventory.getCurrentItem(); InventoryPackage invMail = null; if (mail != null && mail.getItem() instanceof ItemPackage) { invMail = new InventoryPackage(par1EntityPlayer, mail); } return invMail; } }