package xyz.brassgoggledcoders.boilerplate.items;

import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World;
import xyz.brassgoggledcoders.boilerplate.api.IDebuggable;

import javax.annotation.Nonnull;
import java.util.LinkedHashMap;

/**
 * @author SkySom
 */
public class ItemDebuggerStick extends ItemBase
{
	public ItemDebuggerStick()
	{
		super("debugger_stick");
		this.setCreativeTab(CreativeTabs.MISC);
	}

	@Override
	@Nonnull
	public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack itemStack, World world, EntityPlayer player, EnumHand hand)
	{
		RayTraceResult rayTrace = rayTrace(world, player, true);

		LinkedHashMap<String, String> debugStrings = new LinkedHashMap<String, String>();
		if(rayTrace.typeOfHit != null)
		{
			if (rayTrace.typeOfHit == RayTraceResult.Type.BLOCK)
			{
				TileEntity tileEntity = world.getTileEntity(rayTrace.getBlockPos());
				{
					if (tileEntity instanceof IDebuggable)
					{
						debugStrings.putAll(((IDebuggable) tileEntity).getDebugStrings());
					} else {
						debugStrings.put("name", world.getBlockState(rayTrace.getBlockPos()).toString());
					}
				}
			}
			else if (rayTrace.typeOfHit == RayTraceResult.Type.ENTITY)
			{
				Entity entity = rayTrace.entityHit;
				if (entity instanceof IDebuggable)
				{
					debugStrings.putAll(((IDebuggable) entity).getDebugStrings());
				} else {
					debugStrings.put("name", entity.getName());
				}
			}
		}

		if(!debugStrings.isEmpty())
		{
			for(String debugString : debugStrings.values())
			{
				getMod().getLogger().info(debugString);
			}
			return ActionResult.newResult(EnumActionResult.SUCCESS, itemStack);
		}

		return ActionResult.newResult(EnumActionResult.PASS, itemStack);
	}

	@Override
	public String[] getResourceLocations()
	{
		return new String[] {"debugger_stick"};
	}
}

@@ -975,17 +975,16 @@
  true);%0A
-%0A
 %09%09Linked
@@ -1059,16 +1059,17 @@
 ing%3E();%0A
+%0A
 %09%09if(ray
@@ -1065,32 +1065,52 @@
 ;%0A%0A%09%09if(rayTrace
+ != null && rayTrace
 .typeOfHit != nu

Fix Debugger stick NPE