public class Semi_rifle extends ItemBase implements IHasModel {
public Semi_rifle(String name) {
super(name);
this.setCreativeTab(rustmod.guns);
this.setMaxDamage(384);
this.setMaxStackSize(1);
}
private ItemStack findAmmo(EntityPlayer player)
{
if (this.isBullet(player.getHeldItem(EnumHand.OFF_HAND)))
{
return player.getHeldItem(EnumHand.OFF_HAND);
}
else if (this.isBullet(player.getHeldItem(EnumHand.MAIN_HAND)))
{
return player.getHeldItem(EnumHand.MAIN_HAND);
}
else
{
for (int i = 0; i < player.inventory.getSizeInventory(); ++i)
{
ItemStack itemstack = player.inventory.getStackInSlot(i);
if (this.isBullet(itemstack))
{
return itemstack;
}
}
return ItemStack.EMPTY;
}
}
protected boolean isBullet(ItemStack stack) {
return stack.getItem() instanceof Bulletak;
}
//playerIn.getCooldownTracker().setCooldown(this, 20);
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
ItemStack itemstack = playerIn.getHeldItem(handIn);
worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
if (!worldIn.isRemote) {
EntityBulletak entitysnowball = new EntityBulletak(worldIn, playerIn);
entitysnowball.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 2.5F, 2.0F);
worldIn.spawnEntity(entitysnowball);
playerIn.getCooldownTracker().setCooldown(this, 10);
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
public int getMaxItemUseDuration(ItemStack stack)
{
return 72000;
}
}
public class Semi_rifle extends ItemBase implements IHasModel {
public Semi_rifle(String name) {
super(name);
this.setCreativeTab(rustmod.guns);
this.setMaxDamage(384);
this.setMaxStackSize(1);
}
private ItemStack findAmmo(EntityPlayer player)
{
if (this.isBullet(player.getHeldItem(EnumHand.OFF_HAND)))
{
return player.getHeldItem(EnumHand.OFF_HAND);
}
else if (this.isBullet(player.getHeldItem(EnumHand.MAIN_HAND)))
{
return player.getHeldItem(EnumHand.MAIN_HAND);
}
else
{
for (int i = 0; i < player.inventory.getSizeInventory(); ++i)
{
ItemStack itemstack = player.inventory.getStackInSlot(i);
if (this.isBullet(itemstack))
{
return itemstack;
}
}
return ItemStack.EMPTY;
}
}
protected boolean isBullet(ItemStack stack) {
return stack.getItem() instanceof Bulletak;
}
//playerIn.getCooldownTracker().setCooldown(this, 20);
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
boolean flag = !this.findAmmo(playerIn).isEmpty();
ItemStack itemstack = playerIn.getHeldItem(handIn);
if (!playerIn.capabilities.isCreativeMode && !flag)
{
return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
}
else
{
playerIn.setActiveHand(handIn);
if (!worldIn.isRemote) {
EntityBulletak entitysnowball = new EntityBulletak(worldIn, playerIn);
entitysnowball.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 2.5F, 2.0F);
worldIn.spawnEntity(entitysnowball);
playerIn.getCooldownTracker().setCooldown(this, 10);
}
worldIn.playSound((EntityPlayer) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
public int getMaxItemUseDuration(ItemStack stack)
{
return 72000;
}
}