<commit_before>package StevenDimDoors.mod_pocketDim.items;

import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;

public abstract class BaseItemDoor extends ItemDoor
{
	// maps non-dimensional door items to their corresponding dimensional door
	// item
	private static HashMap<ItemDoor, BaseItemDoor> vanillaDoorMapping = new HashMap<ItemDoor, BaseItemDoor>();
	private static DDProperties properties = null;

	public BaseItemDoor(int itemID, Material material)
	{
		super(itemID, material);
		this.setMaxStackSize(64);
		this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
		if (properties == null)
			properties = DDProperties.instance();

		vanillaDoorMapping.put((ItemDoor) mod_pocketDim.itemGoldenDoor, (BaseItemDoor) mod_pocketDim.itemGoldenDimensionalDoor);
		vanillaDoorMapping.put((ItemDoor) Item.doorIron, (BaseItemDoor) mod_pocketDim.itemDimensionalDoor);
		vanillaDoorMapping.put((ItemDoor) Item.doorWood, (BaseItemDoor) mod_pocketDim.itemWarpDoor);
	}

	@Override
	public void registerIcons(IconRegister par1IconRegister)
	{
		this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", ""));
	}

	@SuppressWarnings({ "rawtypes" })
	@Override
	public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);

	/**
	 * Overriden in subclasses to specify which door block that door item will
	 * place
	 * 
	 * @return
	 */
	protected abstract BaseDimDoor getDoortoItemMapping();

	/**
	 * Overriden here to remove vanilla block placement functionality from
	 * dimensional doors, we handle this in the EventHookContainer
	 */
	@Override
	public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
	{
		// TODO Auto-generated method stub
		return false;
	}

	public static BaseDimDoor getDoorToPlace(Item item)
	{
		if (!(item instanceof BaseItemDoor))
		{
			item = BaseItemDoor.vanillaDoorMapping.get(item);
		}
		return ((BaseItemDoor) item).getDoortoItemMapping();
	}

	/**
	 * Tries to place a door block, called in EventHookContainer
	 * 
	 * @param doorBlock
	 * @param stack
	 * @param player
	 * @param world
	 * @param x
	 * @param y
	 * @param z
	 * @param side
	 * @param requireLink
	 * @param reduceStack
	 * @return
	 */
	public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side)
	{
		if (world.isRemote)
		{
			return false;
		}
		if (!(stack.getItem() instanceof ItemDoor))
		{
			throw new IllegalArgumentException("The itemstack must correspond to some type of door");
		}
		if (BaseItemDoor.placeDoorOnBlock(getDoorToPlace(stack.getItem()), stack, player, world, x, y, z, side))
		{
			return true;
		}
		return BaseItemDoor.placeDoorOnRift(getDoorToPlace(stack.getItem()), world, player, stack);
	}

	/**
	 * try to place a door block on a block
	 * @param doorBlock
	 * @param stack
	 * @param player
	 * @param world
	 * @param x
	 * @param y
	 * @param z
	 * @param side
	 * @return
	 */
	public static boolean placeDoorOnBlock(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side)
	{
		if (world.isRemote)
		{
			return false;
		}
		// Only place doors on top of blocks - check if we're targeting the top
		// side
		if (side == 1 && !world.isRemote)
		{
			int blockID = world.getBlockId(x, y, z);
			if (blockID != 0)
			{
				if (!Block.blocksList[blockID].isBlockReplaceable(world, x, y, z))
				{
					y++;
				}
			}

			if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) && player.canPlayerEdit(x, y, z, side, stack)
					&& player.canPlayerEdit(x, y + 1, z, side, stack) && stack.stackSize > 0)
			{
				int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
				placeDoorBlock(world, x, y, z, orientation, doorBlock);

				if (!player.capabilities.isCreativeMode)
				{
					stack.stackSize--;
				}
				return true;
			}
		}
		return false;
	}

	/**
	 * uses a raytrace to try and place a door on a rift
	 * 
	 * @param doorBlock<commit_msg>Fixed all doors being placed as dim doors<commit_after>package StevenDimDoors.mod_pocketDim.items;

import java.util.HashMap;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemDoor;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
import StevenDimDoors.mod_pocketDim.mod_pocketDim;
import StevenDimDoors.mod_pocketDim.blocks.BaseDimDoor;
import StevenDimDoors.mod_pocketDim.config.DDProperties;
import StevenDimDoors.mod_pocketDim.core.DimLink;
import StevenDimDoors.mod_pocketDim.core.PocketManager;
import StevenDimDoors.mod_pocketDim.tileentities.TileEntityDimDoor;

public abstract class BaseItemDoor extends ItemDoor
{
	// maps non-dimensional door items to their corresponding dimensional door
	// item
	private static HashMap<ItemDoor, BaseItemDoor> vanillaDoorMapping = new HashMap<ItemDoor, BaseItemDoor>();
	private static DDProperties properties = null;

	public BaseItemDoor(int itemID, Material material)
	{
		super(itemID, material);
		this.setMaxStackSize(64);
		this.setCreativeTab(mod_pocketDim.dimDoorsCreativeTab);
		if (properties == null)
			properties = DDProperties.instance();

		vanillaDoorMapping.put((ItemDoor) mod_pocketDim.itemGoldenDoor, (BaseItemDoor) mod_pocketDim.itemGoldenDimensionalDoor);
		vanillaDoorMapping.put((ItemDoor) Item.doorIron, (BaseItemDoor) mod_pocketDim.itemDimensionalDoor);
		vanillaDoorMapping.put((ItemDoor) Item.doorWood, (BaseItemDoor) mod_pocketDim.itemWarpDoor);
	}

	@Override
	public void registerIcons(IconRegister par1IconRegister)
	{
		this.itemIcon = par1IconRegister.registerIcon(mod_pocketDim.modid + ":" + this.getUnlocalizedName().replace("item.", ""));
	}

	@SuppressWarnings({ "rawtypes" })
	@Override
	public abstract void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4);

	/**
	 * Overriden in subclasses to specify which door block that door item will
	 * place
	 * 
	 * @return
	 */
	protected abstract BaseDimDoor getDoortoItemMapping();

	/**
	 * Overriden here to remove vanilla block placement functionality from
	 * dimensional doors, we handle this in the EventHookContainer
	 */
	@Override
	public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ)
	{
		// TODO Auto-generated method stub
		return false;
	}

	public static BaseDimDoor getDoorToPlace(Item item)
	{
		if (!(item instanceof BaseItemDoor))
		{
			item = BaseItemDoor.vanillaDoorMapping.get(item);
		}
		return ((BaseItemDoor) item).getDoortoItemMapping();
	}

	/**
	 * Tries to place a door block, called in EventHookContainer
	 * 
	 * @param doorBlock
	 * @param stack
	 * @param player
	 * @param world
	 * @param x
	 * @param y
	 * @param z
	 * @param side
	 * @param requireLink
	 * @param reduceStack
	 * @return
	 */
	public static boolean tryToPlaceDoor(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side)
	{
		if (world.isRemote)
		{
			return false;
		}
		if (!(stack.getItem() instanceof ItemDoor))
		{
			throw new IllegalArgumentException("The itemstack must correspond to some type of door");
		}
		if (BaseItemDoor.placeDoorOnBlock(getDoorToPlace(stack.getItem()), stack, player, world, x, y, z, side))
		{
			return true;
		}
		return BaseItemDoor.placeDoorOnRift(getDoorToPlace(stack.getItem()), world, player, stack);
	}

	/**
	 * try to place a door block on a block
	 * @param doorBlock
	 * @param stack
	 * @param player
	 * @param world
	 * @param x
	 * @param y
	 * @param z
	 * @param side
	 * @return
	 */
	public static boolean placeDoorOnBlock(Block doorBlock, ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side)
	{
		if (world.isRemote)
		{
			return false;
		}
		// Only place doors on top of blocks - check if we're targeting the top
		// side
		if (side == 1 && !world.isRemote)
		{
			int blockID = world.getBlockId(x, y, z);
			if (blockID != 0)
			{
				if (!Block.blocksList[blockID].isBlockReplaceable(world, x, y, z))
				{
					y++;
				}
			}

			if (canPlace(world, x, y, z) && canPlace(world, x, y + 1, z) && player.canPlayerEdit(x, y, z, side, stack)
					&& (player.canPlayerEdit(x, y + 1, z, side, stack) && stack.stackSize > 0)
					&&((stack.getItem() instanceof BaseItemDoor) || PocketManager.getLink(x, y + 1, z, world) != null))
			{
				int orientation = MathHelper.floor_double((player.rotationYaw + 180.0F) * 4.0F / 360.0F - 0.5D) & 3;
				placeDoorBlock(world, x, y, z, orientation, doorBlock);

				if (!player.capabilities.isCreativeMode)
				{
					stack.stackSize--;
				}
				return true;
			}
		}
		return false;
	}

	/**
	 * uses a raytrace to try and place a door on a rift
	 * 
	 * @param doorBlock
{'fraction_non_alphanumeric': 0.10873440285204991, 'fraction_numerical': 0.0054466230936819175, 'mean_word_length': 4.306883867577509, 'pattern_counts': {'":': 2, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4555578', 'n_tokens_mistral': 3601, 'n_tokens_neox': 3262, 'n_words': 851}