Skip to content

Instantly share code, notes, and snippets.

Created May 6, 2016 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/863a5cfada4e0566586463e4fbff346e to your computer and use it in GitHub Desktop.
Save anonymous/863a5cfada4e0566586463e4fbff346e to your computer and use it in GitHub Desktop.
AirhornItem class
import java.time.Instant;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
public class AirhornItem extends Item
{
private long nextTimeSoundCanPlay = 0;
public AirhornItem(String unlocalizedName)
{
super();
this.nextTimeSoundCanPlay = Instant.now().getEpochSecond();
this.setUnlocalizedName(unlocalizedName);
this.setCreativeTab(CreativeTabs.tabTools);
}
public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
{
if (!worldIn.isRemote)
{
long the_now = Instant.now().getEpochSecond();
if (the_now >= this.nextTimeSoundCanPlay)
{
worldIn.playSoundAtEntity(playerIn, "airhorn:airhorn_sound", 1.0F, 1.0F);
this.nextTimeSoundCanPlay = the_now + 5;
}
}
return itemStackIn;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment