1

How to make my gun aim?!

Ubalube's Avatar Ubalube12/2/18 6:34 pm history
1 emeralds 131
So I have 2 Json Files:

One for the normal gun (Not aiming)

and another for the aiming version.



How would I go to switching between the models?

Code
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");

}

}


Posted by Ubalube's Avatar
Ubalube
Level 60 : High Grandmaster Pyro
85

Create an account or sign in to comment.

Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome