-
-
Save anonymous/863a5cfada4e0566586463e4fbff346e to your computer and use it in GitHub Desktop.
AirhornItem class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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