Okay so this is what I have.
public class ItemRayGun extends Item
{
public ItemRayGun(String name)
{
this.setUnlocalizedName(name);
this.setMaxStackSize(1);
this.setMaxDamage(1000);
this.setRegistryName(new ResourceLocation(Reference.MODID, name));
}
@Override
public int getMaxItemUseDuration(ItemStack stack)
{
return 72000;
}
@Override
public EnumAction getItemUseAction(ItemStack stack)
{
return EnumAction.BOW;
}
@Override
public void onUsingTick(ItemStack stack, EntityLivingBase entityliving, int count)
{
if (entityliving.ticksExisted % 2 == 0)
{
EntityPlayer player = (EntityPlayer) entityliving;
World world = player.world;
DinocraftEntity dinoEntity = DinocraftEntity.getEntity(player);
DinocraftServer.getSide(world);
if (player.isCreative() || dinoEntity.hasAmmo(DinocraftItems.RAY_BULLET))
{
if (!player.isCreative())
{
dinoEntity.consumeAmmo(DinocraftItems.RAY_BULLET, 1);
stack.damageItem(1, player);
}
if (!world.isRemote)
{
EntityRayBullet ball = new EntityRayBullet(player, 0.001F);
Vec3d vector = player.getLookVec();
double x = vector.x;
double y = vector.y;
double z = vector.z;
ball.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 3.33F, 0.0F);
ball.setRotationYawHead(player.rotationYawHead);
ball.setPositionAndUpdate(player.posX - (x * 0.75D), player.posY + player.eyeHeight, player.posZ - (z * 0.75D));
world.spawnEntity(ball);
world.playSound(null, player.getPosition(), DinocraftSoundEvents.RAY_GUN_SHOT, SoundCategory.NEUTRAL, 3.0F, world.rand.nextFloat() + 0.5F);
}
DinocraftEntity.getEntity(player).recoil(0.1F, 1.25F, true);
}
else if (!world.isRemote)
{
dinoEntity.sendActionbarMessage(TextFormatting.RED + "Out of ammo!");
world.playSound(null, player.getPosition(), SoundEvents.BLOCK_DISPENSER_DISPENSE, SoundCategory.NEUTRAL, 0.5F, 5.0F);
}
super.onUsingTick(stack, player, count);
}
}
@Override
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
{
playerIn.setActiveHand(EnumHand.MAIN_HAND);
return super.onItemRightClick(worldIn, playerIn, handIn);
}
}
All goes well, but when I stop right-clicking, sometimes, the server thread doesn't get notified and it keeps running onUsingTick even though I'm not right clicking. The client side doesn't have this bug.
Also, when this fires, I get the following errors continuously. Not sure what they mean.
[22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Error in class 'ChannelLWJGL OpenAL'
[22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Invalid enumerated parameter value.
[22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Error in class 'ChannelLWJGL OpenAL'
[22:01:36] [Thread-6/ERROR] [minecraft/SoundManager]: Error creating buffers in method 'preLoadBuffers'