Jump to content

How to make my gun aim?


Ubalube

Recommended Posts

Hello, I have a gun and I am trying to figure out how to get it to aim. I looked at the bow code but.. I don't understand it. I have 2 jsons, A version of my gun that IS aiming and a version of my gun that IS NOT aiming. How do I switch between them?

 

public class M16A4 extends Item implements IHasModel
{
	
	int Firerate = 8;
	int clipsize = 25;
	int kick = 5;
	int ReloadTime = 30;
	
	
	public M16A4(String name, CreativeTabs tab) 
	{
		setUnlocalizedName(name);
		setRegistryName(name);
		setCreativeTab(tab);
		setMaxStackSize(1);
		setMaxDamage(clipsize + 1);
		
		ModItems.ITEMS.add(this);
	}
	
	@Override
	public void addInformation(ItemStack stack, World worldIn, List<String> tooltip, ITooltipFlag flagIn) 
	{
		tooltip.add(TextFormatting.YELLOW + "Impact: " + TextFormatting.GREEN + "::::" + TextFormatting.RED + "::::::");
		tooltip.add(TextFormatting.YELLOW + "Range:  " + TextFormatting.GREEN + ":::::" + TextFormatting.RED + ":::::");
		tooltip.add(TextFormatting.YELLOW + "Clipsize: " + TextFormatting.GREEN + "25");
		super.addInformation(stack, worldIn, tooltip, flagIn);
	}
	
	@Override
	public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) 
	{
		
		ItemStack itemstack = playerIn.getHeldItem(handIn);
		
		if (!playerIn.capabilities.isCreativeMode)
		{
			if(itemstack.isItemDamaged())
			{
				if(itemstack.getItemDamage() >= clipsize)
				{
					if(playerIn.inventory.hasItemStack(new ItemStack(ModItems.M16AMMO)))
					{
						EntityBullet entity = new EntityBullet(worldIn, playerIn, 2.0F, 50);
						itemstack.setItemDamage(-clipsize - 1);
						playerIn.inventory.clearMatchingItems(ModItems.M16AMMO, 0, 1, null);
						playerIn.getCooldownTracker().setCooldown(this, ReloadTime);
						worldIn.playSound(playerIn,	playerIn.posX, playerIn.posY, playerIn.posZ, SoundHandler.RELOAD_RIFLERELOAD, SoundCategory.MASTER, 1, 1);
					}
				}
				else
				{
					playerIn.getCooldownTracker().setCooldown(this, Firerate);
					if (!worldIn.isRemote)
					{
						EntityBullet entity = new EntityBullet(worldIn, playerIn, 3.5F, 200);
						entity.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 0.0F);
						worldIn.spawnEntity(entity);
						itemstack.damageItem(1, playerIn);
						
					}
					worldIn.playSound(playerIn,	playerIn.posX, playerIn.posY, playerIn.posZ, SoundHandler.GUN_RIFLE_SHOOT, SoundCategory.MASTER, 1, 1);
				}
				
			}
			else
			{
				//First Bullet
				playerIn.getCooldownTracker().setCooldown(this, Firerate);
				if(!worldIn.isRemote)
				{
					EntityBullet entity = new EntityBullet(worldIn, playerIn, 3.5F, 200);
					entity.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 0.0F);
					worldIn.spawnEntity(entity);
					itemstack.damageItem(1, playerIn);
					
				}
				worldIn.playSound(playerIn,	playerIn.posX, playerIn.posY, playerIn.posZ, SoundHandler.GUN_RIFLE_SHOOT, SoundCategory.MASTER, 1, 1);
				
			}
		}
		else
		{
			//Creative Move
			playerIn.getCooldownTracker().setCooldown(this, Firerate);
			if(!worldIn.isRemote)
			{
				EntityBullet entity = new EntityBullet(worldIn, playerIn, 3.5F, 200);
				entity.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 0.0F);
				worldIn.spawnEntity(entity);
				itemstack.damageItem(1, playerIn);
				
			}
			worldIn.playSound(playerIn,	playerIn.posX, playerIn.posY, playerIn.posZ, SoundHandler.GUN_RIFLE_SHOOT, SoundCategory.MASTER, 1, 1);
			
		}
		
		
		
		return new ActionResult(EnumActionResult.PASS, itemstack);
	}
	
	
	
	@SideOnly(Side.CLIENT)
	@Override
	public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack stack) {
		
		int SingleFire = 8;
		int Automatic = 2;
		
		World worldIn = ((EntityPlayer)entityLiving).getEntityWorld();
		
		worldIn.playSound(((EntityPlayer)entityLiving),	((EntityPlayer)entityLiving).posX, ((EntityPlayer)entityLiving).posY, ((EntityPlayer)entityLiving).posZ, SoundHandler.RELOAD_FIREMODE, SoundCategory.MASTER, 1, 1);
		
		if(entityLiving instanceof EntityPlayer)
		{
			if(!entityLiving.world.isRemote)
			{
				if(Firerate == SingleFire)
				{
					((EntityPlayer)entityLiving).sendMessage(new TextComponentString("Firemode Set to " + TextFormatting.YELLOW + "AUTOMATIC"));
					Firerate = Automatic;
				}
				else
				{
					((EntityPlayer)entityLiving).sendMessage(new TextComponentString("Firemode Set to " + TextFormatting.YELLOW + "Semi-Automatic"));
					Firerate = SingleFire;
				}
			}
		}
		return super.onEntitySwing(entityLiving, stack);
	}
	
	@Override
	public void registerModels() 
	{
		main.proxy.registerItemRender(this, 0, "inventory");
		
	}

}

 

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.