Jump to content

[1.10.2]How to tell if a player right clicked the Ender Dragon[RESOLVED]


RealTheUnderTaker11

Recommended Posts

I am using the EntityInteract event to try and tell when a player right clicks entities, and it has worked on everything I've tested so far besides the end dragon. For some reason it's like it has no idea when I right click it.

 

This is what I'm using on the event.getTarget() to check if its something alive.

if(target instanceof EntityLivingBase&&!(target instanceof EntityPlayer))

 

And just in case the all the code for the event is in the spoiler below.

 

/**
 * I use this to scrape entities, with basic or advanced scraper.
 * Also at the bottom it is used to handle the wooly and milky genes
 */
@SubscribeEvent
public void rightClickEntity(EntityInteract event)
{
	EntityPlayer player = event.getEntityPlayer();
	Entity target = event.getTarget();
	World world = event.getWorld();
	if(event.getHand()==EnumHand.MAIN_HAND&&!world.isRemote&&player.getHeldItemMainhand()!=null)
	{
		if(target instanceof EntityLivingBase&&!(target instanceof EntityPlayer))
		{
			EntityLivingBase livingtarget = (EntityLivingBase)target;
			player.getHeldItemMainhand().damageItem(1, player);
			ItemStack organicmatter = new ItemStack(GRItems.OrganicMatter, 1);
			String name = livingtarget.getName();
			//Start special snowflakes.
			if(livingtarget instanceof EntitySkeleton)
			{
				EntitySkeleton skeleton = (EntitySkeleton)livingtarget;
				if(skeleton.func_189771_df()==SkeletonType.WITHER)
				{
					name = "Wither Skeleton";
				}
			}
			if(livingtarget instanceof EntityPigZombie)
			{
				name="Zombie Pigman";
			}
			//End special snowflakes.
			if(player.getHeldItemMainhand().getItem()==GRItems.MetalScraper)
			{
				livingtarget.attackEntityFrom(DamageSource.causePlayerDamage(player), 0.25F);
				ModUtils.getTagCompound(organicmatter).setString("entityName", name);
			}
			//Gives more info than other one for use in cloning, but makes items not stack.
			if(player.getHeldItemMainhand().getItem()==GRItems.AdvancedScraper)
			{
				livingtarget.attackEntityFrom(DamageSource.causePlayerDamage(player), 1.0F);

				NBTTagCompound entitytag = livingtarget.getEntityData();
				NBTTagCompound itemtag = ModUtils.getTagCompound(organicmatter);
				livingtarget.writeToNBT(entitytag);

				itemtag.setTag("mobTag", entitytag);
				itemtag.setString("type", livingtarget.getClass().getCanonicalName());
				itemtag.setString("entityName", name);
			}
			EntityItem entity = new EntityItem(event.getWorld(), livingtarget.getPosition().getX(), livingtarget.getPosition().getY(), livingtarget.getPosition().getZ(), organicmatter);
			event.getWorld().spawnEntityInWorld(entity);
		}

		//START WOOLY/MILK GENES
		if(target instanceof EntityPlayer)
		{
			EntityPlayer targetplayer = (EntityPlayer)target;
			if(ModUtils.getIGenes(targetplayer)!=null)
			{
				IGenes targetplayergenes = ModUtils.getIGenes(targetplayer);

				if(player.getHeldItemMainhand().getItem() instanceof ItemShears&&targetplayergenes.hasGene(EnumGenes.WOOLY))
				{
					ItemStack wool = new ItemStack(Blocks.WOOL, 1);
					EntityItem entitywool = new EntityItem(event.getWorld(), targetplayer.getPosition().getX(), targetplayer.getPosition().getY(), targetplayer.getPosition().getZ(), wool);
					world.spawnEntityInWorld(entitywool);
				}

				if(player.getHeldItemMainhand().getItem()==Items.BUCKET&&targetplayergenes.hasGene(EnumGenes.MILKY))
				{
					if((player.getHeldItemMainhand().stackSize-1)<=0) player.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(Items.MILK_BUCKET));
					else if(!player.inventory.addItemStackToInventory(new ItemStack(Items.MILK_BUCKET))) player.dropItem(Items.MILK_BUCKET, 1);
				}
			}
		}
	}
}

 

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Link to comment
Share on other sites

The end dragon has sub-parts which I believe are an entirely different class.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.