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

import java.security.InvalidParameterException;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.mcft.copy.betterstorage.Config;
import net.mcft.copy.betterstorage.api.ILock;
import net.mcft.copy.betterstorage.api.ILockable;
import net.mcft.copy.betterstorage.utils.WorldUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;

public class TileEntityReinforcedChest extends TileEntityConnectable implements IInventory, ILockable {
	
	private ItemStack lock;
	private boolean powered;
	
	private static ForgeDirection[] neighbors = { ForgeDirection.EAST, ForgeDirection.NORTH,
	                                              ForgeDirection.WEST, ForgeDirection.SOUTH };
	
	@Override
	@SideOnly(Side.CLIENT)
	public AxisAlignedBB getRenderBoundingBox() {
		return WorldUtils.getAABB(this, 0, 0, 0, 1, 1, 1);
	}
	
	@Override
	public ForgeDirection[] getPossibleNeighbors() { return neighbors; }
	@Override
	protected String getConnectableName() { return "container.reinforcedChest"; }
	
	@Override
	public boolean canConnect(TileEntityConnectable connectable) {
		if (!(connectable instanceof TileEntityReinforcedChest)) return false;
		TileEntityReinforcedChest chest = (TileEntityReinforcedChest)connectable;
		return (super.canConnect(connectable) &&
		        (((xCoord != chest.xCoord) && ((orientation == ForgeDirection.SOUTH) ||
		                                       (orientation == ForgeDirection.NORTH))) ||
		         ((zCoord != chest.zCoord) && ((orientation == ForgeDirection.EAST) ||
		                                       (orientation == ForgeDirection.WEST)))) &&
		        (getLock() == null) && (chest.getLock() == null));
	}
	
	@Override
	public void dropContents() {
		super.dropContents();
		WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, lock);
	}
	
	// TileEntityContainer stuff

	@Override
	public int getColumns() { return Config.reinforcedChestColumns; }
	
	// ILockable implementation
	
	@Override
	public ItemStack getLock() { return ((TileEntityReinforcedChest)getMain()).lock; }
	
	@Override
	public boolean isLockValid(ItemStack lock) { return (lock.getItem() instanceof ILock); }
	
	@Override
	public void setLock(ItemStack lock) {
		if ((lock != null) && !isLockValid(lock))
			throw new InvalidParameterException("Can't set lock to " + lock + ".");
		if (isMain()) {
			this.lock = lock;
			// Mark the block for an update, sends description packet to players.
			worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
		} else ((TileEntityReinforcedChest)getMain()).setLock(lock);
	}
	
	@Override
	public boolean canUse(EntityPlayer player) { return (getPlayersUsing() > 0); }
	
	@Override
	public void applyTrigger() { setPowered(true); }
	
	// Trigger enchantment related
	
	/** Returns if the chest is emitting redstone. */
	public boolean isPowered() {<commit_msg>Fix #39, locked chests accessible with pipes etc.<commit_after>package net.mcft.copy.betterstorage.block;

import java.security.InvalidParameterException;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.mcft.copy.betterstorage.Config;
import net.mcft.copy.betterstorage.api.ILock;
import net.mcft.copy.betterstorage.api.ILockable;
import net.mcft.copy.betterstorage.utils.WorldUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;

public class TileEntityReinforcedChest extends TileEntityConnectable implements IInventory, ILockable {
	
	private ItemStack lock;
	private boolean powered;
	
	private static ForgeDirection[] neighbors = { ForgeDirection.EAST, ForgeDirection.NORTH,
	                                              ForgeDirection.WEST, ForgeDirection.SOUTH };
	
	@Override
	@SideOnly(Side.CLIENT)
	public AxisAlignedBB getRenderBoundingBox() {
		return WorldUtils.getAABB(this, 0, 0, 0, 1, 1, 1);
	}
	
	@Override
	public ForgeDirection[] getPossibleNeighbors() { return neighbors; }
	@Override
	protected String getConnectableName() { return "container.reinforcedChest"; }
	
	@Override
	public boolean canConnect(TileEntityConnectable connectable) {
		if (!(connectable instanceof TileEntityReinforcedChest)) return false;
		TileEntityReinforcedChest chest = (TileEntityReinforcedChest)connectable;
		return (super.canConnect(connectable) &&
		        (((xCoord != chest.xCoord) && ((orientation == ForgeDirection.SOUTH) ||
		                                       (orientation == ForgeDirection.NORTH))) ||
		         ((zCoord != chest.zCoord) && ((orientation == ForgeDirection.EAST) ||
		                                       (orientation == ForgeDirection.WEST)))) &&
		        (getLock() == null) && (chest.getLock() == null));
	}
	
	@Override
	public void dropContents() {
		super.dropContents();
		WorldUtils.dropStackFromBlock(worldObj, xCoord, yCoord, zCoord, lock);
	}
	
	// TileEntityContainer stuff

	@Override
	public int getColumns() { return Config.reinforcedChestColumns; }
	
	// TileEntityConnactable stuff
	
	@Override
	protected boolean isAccessible() { return (getLock() == null); }
	
	// ILockable implementation
	
	@Override
	public ItemStack getLock() { return ((TileEntityReinforcedChest)getMain()).lock; }
	
	@Override
	public boolean isLockValid(ItemStack lock) { return (lock.getItem() instanceof ILock); }
	
	@Override
	public void setLock(ItemStack lock) {
		if ((lock != null) && !isLockValid(lock))
			throw new InvalidParameterException("Can't set lock to " + lock + ".");
		if (isMain()) {
			this.lock = lock;
			// Mark the block for an update, sends description packet to players.
			worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
		} else ((TileEntityReinforcedChest)getMain()).setLock(lock);
	}
	
	@Override
	public boolean canUse(EntityPlayer player) { return (getPlayersUsing() > 0); }
	
	@Override
	public void applyTrigger() { setPowered(true); }
	
	// Trigger enchantment related
	
	/** Returns if the chest is emitting redstone. */
	public boolean isPowered() {
{'fraction_non_alphanumeric': 0.11097869804856249, 'fraction_numerical': 0.0032772232980783555, 'mean_word_length': 4.224902723735409, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6541930', 'n_tokens_mistral': 2135, 'n_tokens_neox': 1966, 'n_words': 436}