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 = this.findAmmo(playerIn);
boolean flag1 = playerIn.capabilities.isCreativeMode || (itemstack.getItem() instanceof ItemArrow && ((Bulletak) itemstack.getItem()).isInfinite(itemstack, itemstack, playerIn));
if (!playerIn.capabilities.isCreativeMode && !flag) {
return flag ? new ActionResult(EnumActionResult.PASS, itemstack) : new ActionResult(EnumActionResult.FAIL, itemstack);
} else {
if (!worldIn.isRemote) {
// Bulletak bulletak = (Bulletak) (itemstack.getItem() instanceof Bulletak ? itemstack.getItem() : initItems.Bulletak);
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);
/* if (!itemstack.isEmpty() || flag) {
if (itemstack.isEmpty()) {
itemstack = new ItemStack(initItems.Bulletak);
}
}*/
itemstack.damageItem(1,playerIn);
}
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 (!flag1 && !playerIn.capabilities.isCreativeMode)
{
//itemstack.shrink(1);
if (itemstack.isEmpty())
{
playerIn.inventory.deleteStack(itemstack);
}
}
return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, itemstack);
}
}
}