<commit_before>package net.mcft.copy.betterstorage.item;

import java.util.List;

import net.mcft.copy.betterstorage.BetterStorage;
import net.mcft.copy.betterstorage.client.model.ModelBackpack;
import net.mcft.copy.betterstorage.client.model.ModelBackpackArmor;
import net.mcft.copy.betterstorage.config.GlobalConfig;
import net.mcft.copy.betterstorage.container.ContainerBetterStorage;
import net.mcft.copy.betterstorage.container.SlotArmorBackpack;
import net.mcft.copy.betterstorage.content.BetterStorageTiles;
import net.mcft.copy.betterstorage.inventory.InventoryBackpackEquipped;
import net.mcft.copy.betterstorage.inventory.InventoryStacks;
import net.mcft.copy.betterstorage.misc.Constants;
import net.mcft.copy.betterstorage.misc.EquipmentSlot;
import net.mcft.copy.betterstorage.misc.PropertiesBackpack;
import net.mcft.copy.betterstorage.misc.Resources;
import net.mcft.copy.betterstorage.misc.handlers.KeyBindingHandler;
import net.mcft.copy.betterstorage.network.packet.PacketBackpackHasItems;
import net.mcft.copy.betterstorage.tile.TileBackpack;
import net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack;
import net.mcft.copy.betterstorage.utils.DirectionUtils;
import net.mcft.copy.betterstorage.utils.EntityUtils;
import net.mcft.copy.betterstorage.utils.LanguageUtils;
import net.mcft.copy.betterstorage.utils.PlayerUtils;
import net.mcft.copy.betterstorage.utils.RandomUtils;
import net.mcft.copy.betterstorage.utils.StackUtils;
import net.mcft.copy.betterstorage.utils.WorldUtils;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S2FPacketSetSlot;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemBackpack extends ItemArmorBetterStorage implements ISpecialArmor, IDyeableItem {
	
	public static final ArmorMaterial material = EnumHelper.addArmorMaterial(
			"backpack", 14, new int[]{ 0, 2, 0, 0 }, 15);
	static { material.customCraftingMaterial = Items.leather; }
	
	protected ItemBackpack(ArmorMaterial material) { super(material, 0, 1); }
	public ItemBackpack() { this(material); }
	
	public String getBackpackName() { return Constants.containerBackpack; }
	
	/** Returns the number of columns this backpack has. */
	public int getBackpackColumns() { return 9; }
	/** Returns the number of rows this backpack has. */
	public int getBackpackRows() { return BetterStorage.globalConfig.getInteger(GlobalConfig.backpackRows); }
	
	protected int getDefaultColor() { return 0xA06540; }
	
	protected IInventory getBackpackItemsInternal(EntityLivingBase carrier, EntityPlayer player) {
		PropertiesBackpack backpackData = getBackpackData(carrier);
		int size = (getBackpackColumns() * getBackpackRows());
		if (backpackData.contents == null)
			backpackData.contents = new ItemStack[size];
		// In case the backpack size got changed in
		// the configuration file, update it here.
		else if (backpackData.contents.length != size) {
			ItemStack[] newContents = new ItemStack[size];
			System.arraycopy(backpackData.contents, 0, newContents, 0, Math.min(size, backpackData.contents.length));
			backpackData.contents = newContents;
		}
		return new InventoryStacks(getBackpackName(), backpackData.contents);
	}
	
	public boolean containsItems(PropertiesBackpack backpackData) {
		return (backpackData.hasItems || ((backpackData.contents != null) && !StackUtils.isEmpty(backpackData.contents)));
	}
	
	// Model and texture
	
	@SideOnly(Side.CLIENT)
	private ModelBackpack model;
	@SideOnly(Side.CLIENT)
	private ModelBackpackArmor modelArmor;
	
	/** Returns the model class of the backpack. */
	@SideOnly(Side.CLIENT)
	public Class<? extends ModelBackpack> getModelClass() { return ModelBackpack.class; }
	
	@SideOnly(Side.CLIENT)
	public ModelBackpack getModel() {
		if (model == null) {
			try { model = getModelClass().getConstructor(boolean.class).newInstance(true); }
			catch (Exception e) { e.printStackTrace(); }
		}
		return model;
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack stack, int slot) {
		if (modelArmor == null) {
			try {
				ModelBackpack model = getModelClass().getConstructor(boolean.class).newInstance(false);
				modelArmor = new ModelBackpackArmor(model);
			} catch (Exception e) { e.printStackTrace(); }
		}
		return modelArmor;
	}
	
	@Override
	public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
		return ((type == "overlay") ? Resources.textureBackpackOverlay : Resources.textureBackpack).toString();
	}
	
	// Item stuff
	
	@Override
	@SideOnly(Side.CLIENT)
	public int getSpriteNumber() { return 0; }
	
	@Override
	@SideOnly(Side.CLIENT)
	public void registerIcons(IIconRegister iconRegister) {  }
	
	@Override
	public String getUnlocalizedName() { return getBlockType().getUnlocalizedName(); }
	@Override
	public String getUnlocalizedName(ItemStack stack) { return getUnlocalizedName(); }
	
	public TileBackpack getBlockType() { return BetterStorageTiles.backpack; }
	
	@Override
	public boolean isValidArmor(ItemStack stack, int armorType, Entity entity) { return false; }
	
	@Override
	public int getColor(ItemStack stack) {
		int color = getDefaultColor();
		return ((color >= 0) ? StackUtils.get(stack, color, "display", "color") : color);
	}
	@Override
	public int getRenderPasses(int metadata) { return ((getDefaultColor() >= 0) ? 2 : 1); }
	
	@Override
	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advancedTooltips) {
		boolean enableHelpTooltips = BetterStorage.globalConfig.getBoolean(GlobalConfig.enableHelpTooltips);
		if (getBackpack(player) == stack) {
			String info = LanguageUtils.translateTooltip(getAdditionalInfo(stack, player));
			// Tell players if someone's using their backpack when they hovers over it in the GUI.
			// This is because if the backpack is used by another player it can't be placed down.
			if (ItemBackpack.isBackpackOpen(player)) {
				if (info != null) list.add(info);
				LanguageUtils.translateTooltip(list, "backpack.used");
			// If the backpack can't be removed from its slot (only placed down),
			// tell the player why, like "Contains items" or "Bound backpack".
			} else if (enableHelpTooltips)
				LanguageUtils.translateTooltip(list,
						(info != null) ? "backpack.unequipHint.extended" : "backpack.unequipHint",
						(info != null) ? new String[]{ "%INFO%", info } : new String[0]);
			else if (info != null) list.add(info);
			// If the backpack can be opened by pressing a key, let the player know.
			if (BetterStorage.globalConfig.getBoolean(GlobalConfig.enableBackpackOpen)) {
				String str = GameSettings.getKeyDisplayString(KeyBindingHandler.backpackOpen.getKeyCode());
				LanguageUtils.translateTooltip(list, "backpack.openHint", "%KEY%", str);
			}
		// Tell the player to place down and break a backpack to equip it.
		} else if (enableHelpTooltips) {
			boolean chestplate = BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate);
			LanguageUtils.translateTooltip(list, (chestplate ? "backpack.equipHint"
			                                                 : "backpack.equipHint.extended"));
			// If the backpack doesn't get equipped to the chestplate slot,
			// let players know they can open it in the regular item tooltip.
			if (!chestplate) {
				String str = GameSettings.getKeyDisplayString(KeyBindingHandler.backpackOpen.getKeyCode());
				LanguageUtils.translateTooltip(list, "backpack.openHint", "%KEY%", str);
			}
		}
	}
	/** Returns additional info (a string to be translated) of the backpack. */<commit_msg>Fix backpack open hint showing with setting off<commit_after>package net.mcft.copy.betterstorage.item;

import java.util.List;

import net.mcft.copy.betterstorage.BetterStorage;
import net.mcft.copy.betterstorage.client.model.ModelBackpack;
import net.mcft.copy.betterstorage.client.model.ModelBackpackArmor;
import net.mcft.copy.betterstorage.config.GlobalConfig;
import net.mcft.copy.betterstorage.container.ContainerBetterStorage;
import net.mcft.copy.betterstorage.container.SlotArmorBackpack;
import net.mcft.copy.betterstorage.content.BetterStorageTiles;
import net.mcft.copy.betterstorage.inventory.InventoryBackpackEquipped;
import net.mcft.copy.betterstorage.inventory.InventoryStacks;
import net.mcft.copy.betterstorage.misc.Constants;
import net.mcft.copy.betterstorage.misc.EquipmentSlot;
import net.mcft.copy.betterstorage.misc.PropertiesBackpack;
import net.mcft.copy.betterstorage.misc.Resources;
import net.mcft.copy.betterstorage.misc.handlers.KeyBindingHandler;
import net.mcft.copy.betterstorage.network.packet.PacketBackpackHasItems;
import net.mcft.copy.betterstorage.tile.TileBackpack;
import net.mcft.copy.betterstorage.tile.entity.TileEntityBackpack;
import net.mcft.copy.betterstorage.utils.DirectionUtils;
import net.mcft.copy.betterstorage.utils.EntityUtils;
import net.mcft.copy.betterstorage.utils.LanguageUtils;
import net.mcft.copy.betterstorage.utils.PlayerUtils;
import net.mcft.copy.betterstorage.utils.RandomUtils;
import net.mcft.copy.betterstorage.utils.StackUtils;
import net.mcft.copy.betterstorage.utils.WorldUtils;
import net.minecraft.block.Block;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.client.settings.GameSettings;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.network.play.server.S2FPacketSetSlot;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

public class ItemBackpack extends ItemArmorBetterStorage implements ISpecialArmor, IDyeableItem {
	
	public static final ArmorMaterial material = EnumHelper.addArmorMaterial(
			"backpack", 14, new int[]{ 0, 2, 0, 0 }, 15);
	static { material.customCraftingMaterial = Items.leather; }
	
	protected ItemBackpack(ArmorMaterial material) { super(material, 0, 1); }
	public ItemBackpack() { this(material); }
	
	public String getBackpackName() { return Constants.containerBackpack; }
	
	/** Returns the number of columns this backpack has. */
	public int getBackpackColumns() { return 9; }
	/** Returns the number of rows this backpack has. */
	public int getBackpackRows() { return BetterStorage.globalConfig.getInteger(GlobalConfig.backpackRows); }
	
	protected int getDefaultColor() { return 0xA06540; }
	
	protected IInventory getBackpackItemsInternal(EntityLivingBase carrier, EntityPlayer player) {
		PropertiesBackpack backpackData = getBackpackData(carrier);
		int size = (getBackpackColumns() * getBackpackRows());
		if (backpackData.contents == null)
			backpackData.contents = new ItemStack[size];
		// In case the backpack size got changed in
		// the configuration file, update it here.
		else if (backpackData.contents.length != size) {
			ItemStack[] newContents = new ItemStack[size];
			System.arraycopy(backpackData.contents, 0, newContents, 0, Math.min(size, backpackData.contents.length));
			backpackData.contents = newContents;
		}
		return new InventoryStacks(getBackpackName(), backpackData.contents);
	}
	
	public boolean containsItems(PropertiesBackpack backpackData) {
		return (backpackData.hasItems || ((backpackData.contents != null) && !StackUtils.isEmpty(backpackData.contents)));
	}
	
	// Model and texture
	
	@SideOnly(Side.CLIENT)
	private ModelBackpack model;
	@SideOnly(Side.CLIENT)
	private ModelBackpackArmor modelArmor;
	
	/** Returns the model class of the backpack. */
	@SideOnly(Side.CLIENT)
	public Class<? extends ModelBackpack> getModelClass() { return ModelBackpack.class; }
	
	@SideOnly(Side.CLIENT)
	public ModelBackpack getModel() {
		if (model == null) {
			try { model = getModelClass().getConstructor(boolean.class).newInstance(true); }
			catch (Exception e) { e.printStackTrace(); }
		}
		return model;
	}
	
	@Override
	@SideOnly(Side.CLIENT)
	public ModelBiped getArmorModel(EntityLivingBase entity, ItemStack stack, int slot) {
		if (modelArmor == null) {
			try {
				ModelBackpack model = getModelClass().getConstructor(boolean.class).newInstance(false);
				modelArmor = new ModelBackpackArmor(model);
			} catch (Exception e) { e.printStackTrace(); }
		}
		return modelArmor;
	}
	
	@Override
	public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {
		return ((type == "overlay") ? Resources.textureBackpackOverlay : Resources.textureBackpack).toString();
	}
	
	// Item stuff
	
	@Override
	@SideOnly(Side.CLIENT)
	public int getSpriteNumber() { return 0; }
	
	@Override
	@SideOnly(Side.CLIENT)
	public void registerIcons(IIconRegister iconRegister) {  }
	
	@Override
	public String getUnlocalizedName() { return getBlockType().getUnlocalizedName(); }
	@Override
	public String getUnlocalizedName(ItemStack stack) { return getUnlocalizedName(); }
	
	public TileBackpack getBlockType() { return BetterStorageTiles.backpack; }
	
	@Override
	public boolean isValidArmor(ItemStack stack, int armorType, Entity entity) { return false; }
	
	@Override
	public int getColor(ItemStack stack) {
		int color = getDefaultColor();
		return ((color >= 0) ? StackUtils.get(stack, color, "display", "color") : color);
	}
	@Override
	public int getRenderPasses(int metadata) { return ((getDefaultColor() >= 0) ? 2 : 1); }
	
	@Override
	@SideOnly(Side.CLIENT)
	public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advancedTooltips) {
		boolean enableHelpTooltips = BetterStorage.globalConfig.getBoolean(GlobalConfig.enableHelpTooltips);
		if (getBackpack(player) == stack) {
			String info = LanguageUtils.translateTooltip(getAdditionalInfo(stack, player));
			// Tell players if someone's using their backpack when they hovers over it in the GUI.
			// This is because if the backpack is used by another player it can't be placed down.
			if (ItemBackpack.isBackpackOpen(player)) {
				if (info != null) list.add(info);
				LanguageUtils.translateTooltip(list, "backpack.used");
			// If the backpack can't be removed from its slot (only placed down),
			// tell the player why, like "Contains items" or "Bound backpack".
			} else if (enableHelpTooltips)
				LanguageUtils.translateTooltip(list,
						(info != null) ? "backpack.unequipHint.extended" : "backpack.unequipHint",
						(info != null) ? new String[]{ "%INFO%", info } : new String[0]);
			else if (info != null) list.add(info);
			// If the backpack can be opened by pressing a key, let the player know.
			if (BetterStorage.globalConfig.getBoolean(GlobalConfig.enableBackpackOpen)) {
				String str = GameSettings.getKeyDisplayString(KeyBindingHandler.backpackOpen.getKeyCode());
				LanguageUtils.translateTooltip(list, "backpack.openHint", "%KEY%", str);
			}
		// Tell the player to place down and break a backpack to equip it.
		} else if (enableHelpTooltips) {
			boolean chestplate = BetterStorage.globalConfig.getBoolean(GlobalConfig.backpackChestplate);
			LanguageUtils.translateTooltip(list, (chestplate ? "backpack.equipHint"
			                                                 : "backpack.equipHint.extended"));
			// If the backpack doesn't get equipped to the chestplate slot,
			// let players know they can open it in the regular item tooltip.
			if (!chestplate && BetterStorage.globalConfig.getBoolean(GlobalConfig.enableBackpackOpen)) {
				String str = GameSettings.getKeyDisplayString(KeyBindingHandler.backpackOpen.getKeyCode());
				LanguageUtils.translateTooltip(list, "backpack.openHint", "%KEY%", str);
			}
		}
	}
	/** Returns additional info (a string to be translated) of the backpack. */
{'fraction_non_alphanumeric': 0.10686170837739396, 'fraction_numerical': 0.003054870168017859, 'mean_word_length': 5.187931661214104, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '828340', 'n_tokens_mistral': 5407, 'n_tokens_neox': 5014, 'n_words': 1162}