6262import com .flansmod .common .FlansMod ;
6363import com .flansmod .common .PlayerData ;
6464import com .flansmod .common .PlayerHandler ;
65+ import com .flansmod .common .driveables .EntityDriveable ;
6566import com .flansmod .common .guns .ShotData .InstantShotData ;
6667import com .flansmod .common .guns .ShotData .SpawnEntityShotData ;
6768import com .flansmod .common .guns .raytracing .FlansModRaytracer ;
@@ -141,6 +142,10 @@ public ItemGun(GunType type)
141142 setCreativeTab (FlansMod .tabFlanGuns );
142143 }
143144
145+ public List <ShotData > getShotsFiredServer () {
146+ return shotsFiredServer ;
147+ }
148+
144149 /**
145150 * Get the bullet item stack stored in the gun's NBT data (the loaded magazine / bullets)
146151 */
@@ -565,34 +570,95 @@ else if(shouldShootThisTick)
565570 }
566571 }
567572
568- public void ServerHandleShotData (ItemStack gunstack , int gunSlot , World world , Entity entity , boolean isOffHand , ShotData shotData )
573+ public void handleDriveableShotData (ItemStack shootableStack , int gunSlot , World world , EntityDriveable driveable ,
574+ boolean isOffHand , ShotData shotData )
569575 {
570- // Get useful things
571- if (!(entity instanceof EntityPlayerMP ))
576+ boolean isExtraBullet = shotData instanceof InstantShotData && ((InstantShotData )shotData ).isExtraBullet ;
577+
578+ // We have no bullet stack. So we need to reload. The player will send us a message requesting we do a reload
579+ if (shootableStack .isEmpty ())
572580 {
573581 return ;
574582 }
575- EntityPlayerMP player = (EntityPlayerMP )entity ;
576- PlayerData data = PlayerHandler .getPlayerData (player , Side .SERVER );
577- if (data == null )
583+
584+ if (shootableStack .getItem () instanceof ItemShootable )
578585 {
579- return ;
586+ ShootableType bullet = ((ItemShootable )shootableStack .getItem ()).type ;
587+
588+ if (!isExtraBullet )
589+ {
590+ //Damage the bullet item
591+ shootableStack .setItemDamage (shootableStack .getItemDamage () + 1 );
592+
593+ if (type .consumeGunUponUse && gunSlot != -1 )
594+ driveable .getDriveableData ().ammo [gunSlot ] = ItemStack .EMPTY .copy ();
595+ }
596+
597+ // Spawn an entity, classic style
598+ if (shotData instanceof SpawnEntityShotData )
599+ {
600+ // Play a sound if the previous sound has finished
601+ if (soundDelay <= 0 && type .shootSound != null )
602+ {
603+ PacketPlaySound .sendSoundPacket (driveable .posX , driveable .posY , driveable .posZ , FlansMod .soundRange ,
604+ driveable .dimension , type .shootSound , type .distortSound , false );
605+ soundDelay = type .shootSoundLength ;
606+ }
607+
608+ // Shoot
609+ // Spawn the bullet entities
610+ for (int k = 0 ; k < type .numBullets * bullet .numBullets ; k ++)
611+ {
612+ // Actually shoot the bullet
613+ ((ItemShootable )shootableStack .getItem ()).shoot (world ,
614+ new Vector3f (driveable .posX , driveable .posY + driveable .getEyeHeight (), driveable .posZ ),
615+ new Vector3f (driveable .getLookVec ()),
616+ 1 ,
617+ 1 ,
618+ 1 ,
619+ type ,
620+ driveable .getDriver ());
621+ }
622+ }
623+ // Do a raytrace check on what they've sent us.
624+ else if (shotData instanceof InstantShotData )
625+ {
626+ // Play a sound if the previous sound has finished
627+ if (soundDelay <= 0 && type .shootSound != null )
628+ {
629+ PacketPlaySound .sendSoundPacket (driveable .posX , driveable .posY , driveable .posZ , FlansMod .soundRange ,
630+ driveable .dimension , type .shootSound , type .distortSound , false );
631+ soundDelay = type .shootSoundLength ;
632+ }
633+
634+ InstantShotData instantData = (InstantShotData )shotData ;
635+ doInstantShot (world , driveable .getDriver (), type , (BulletType )bullet ,
636+ instantData .origin , instantData .hitPos , instantData .hitData ,
637+ type .damage , isExtraBullet , false );
638+ shotsFiredServer .add (shotData );
639+
640+ }
580641 }
581-
582-
642+ }
643+
644+ public void handlePlayerShotData (ItemStack gunStack , int gunSlot , World world , EntityPlayerMP player ,
645+ boolean isOffHand , ShotData shotData )
646+ {
583647 boolean isExtraBullet = shotData instanceof InstantShotData && ((InstantShotData )shotData ).isExtraBullet ;
584648
585649 //Go through the bullet stacks in the gun and see if any of them are not null
586650 int bulletID = 0 ;
587651 ItemStack bulletStack = ItemStack .EMPTY .copy ();
588- for (; bulletID < type .numAmmoItemsInGun ; bulletID ++ )
652+ while ( bulletID < type .numAmmoItemsInGun )
589653 {
590- ItemStack checkingStack = getBulletItemStack (gunstack , bulletID );
654+ ItemStack checkingStack = getBulletItemStack (gunStack , bulletID );
591655 if (checkingStack != null && checkingStack .getItemDamage () < checkingStack .getMaxDamage ())
592656 {
593657 bulletStack = checkingStack ;
594658 break ;
595659 }
660+
661+ bulletID ++;
596662 }
597663
598664 // We have no bullet stack. So we need to reload. The player will send us a message requesting we do a reload
@@ -623,7 +689,7 @@ public void ServerHandleShotData(ItemStack gunstack, int gunSlot, World world, E
623689 bulletStack .setItemDamage (bulletStack .getItemDamage () + 1 );
624690
625691 //Update the stack in the gun
626- setBulletItemStack (gunstack , bulletStack , bulletID );
692+ setBulletItemStack (gunStack , bulletStack , bulletID );
627693
628694 if (type .consumeGunUponUse && gunSlot != -1 )
629695 player .inventory .setInventorySlotContents (gunSlot , ItemStack .EMPTY .copy ());
@@ -635,24 +701,24 @@ public void ServerHandleShotData(ItemStack gunstack, int gunSlot, World world, E
635701 // Play a sound if the previous sound has finished
636702 if (soundDelay <= 0 && type .shootSound != null )
637703 {
638- AttachmentType barrel = type .getBarrel (gunstack );
704+ AttachmentType barrel = type .getBarrel (gunStack );
639705 boolean silenced = barrel != null && barrel .silencer ;
640706 //world.playSoundAtEntity(entityplayer, type.shootSound, 10F, type.distortSound ? 1.0F / (world.rand.nextFloat() * 0.4F + 0.8F) : 1.0F);
641707 PacketPlaySound .sendSoundPacket (player .posX , player .posY , player .posZ , FlansMod .soundRange , player .dimension , type .shootSound , type .distortSound , silenced );
642708 soundDelay = type .shootSoundLength ;
643709 }
644710
645- //Shoot
711+ //shoot
646712 // Spawn the bullet entities
647713 for (int k = 0 ; k < type .numBullets * bullet .numBullets ; k ++)
648714 {
649715 // Actually shoot the bullet
650- ((ItemShootable )bulletStack .getItem ()).Shoot (world ,
716+ ((ItemShootable )bulletStack .getItem ()).shoot (world ,
651717 new Vector3f (player .posX , player .posY + player .getEyeHeight (), player .posZ ),
652718 new Vector3f (player .getLookVec ()),
653- type .getDamage (gunstack ),
654- (player .isSneaking () ? 0.7F : 1F ) * type .getSpread (gunstack ) * bullet .bulletSpread ,
655- type .getBulletSpeed (gunstack ),
719+ type .getDamage (gunStack ),
720+ (player .isSneaking () ? 0.7F : 1F ) * type .getSpread (gunStack ) * bullet .bulletSpread ,
721+ type .getBulletSpeed (gunStack ),
656722 type ,
657723 player );
658724 }
@@ -672,10 +738,10 @@ else if(shotData instanceof InstantShotData)
672738 //targetPoint.scale(0.5f);
673739 //float radius = Vector3f.sub(instantData.origin, instantData.hitPos, null).length();
674740 //radius += 50.0f;
675- AttachmentType barrel = type .getBarrel (gunstack );
741+ AttachmentType barrel = type .getBarrel (gunStack );
676742 boolean silenced = barrel != null && barrel .silencer ;
677743
678- DoInstantShot (world , player , type , (BulletType )bullet , instantData .origin , instantData .hitPos , instantData .hitData , type .getDamage (gunstack ), isExtraBullet , silenced );
744+ doInstantShot (world , player , type , (BulletType )bullet , instantData .origin , instantData .hitPos , instantData .hitData , type .getDamage (gunStack ), isExtraBullet , silenced );
679745
680746 shotsFiredServer .add (shotData );
681747 }
@@ -684,7 +750,7 @@ else if(shotData instanceof InstantShotData)
684750 }
685751
686752 @ SideOnly (Side .CLIENT )
687- private void PlayShotSound (World world , boolean silenced , float x , float y , float z )
753+ private void playShotSound (World world , boolean silenced , float x , float y , float z )
688754 {
689755 FMLClientHandler .instance ().getClient ().getSoundHandler ().playSound (
690756 new PositionedSoundRecord (FlansModResourceHandler .getSoundEvent (type .shootSound ),
@@ -694,7 +760,7 @@ private void PlayShotSound(World world, boolean silenced, float x, float y, floa
694760 x , y , z ));
695761 }
696762
697- public void DoInstantShot (World world , EntityLivingBase shooter , InfoType shotFrom , BulletType shotType , Vector3f origin , Vector3f hit , BulletHit hitData , float damage , boolean isExtraBullet , boolean silenced )
763+ public void doInstantShot (World world , EntityLivingBase shooter , InfoType shotFrom , BulletType shotType , Vector3f origin , Vector3f hit , BulletHit hitData , float damage , boolean isExtraBullet , boolean silenced )
698764 {
699765 if (EntityBullet .OnHit (world , origin , hit , shooter , shotFrom , shotType , null , damage , hitData ))
700766 {
@@ -707,7 +773,7 @@ public void DoInstantShot(World world, EntityLivingBase shooter, InfoType shotFr
707773 // Play a sound if the previous sound has finished
708774 if (!isExtraBullet && soundDelay <= 0 && type .shootSound != null && shooter != null )
709775 {
710- PlayShotSound (world , silenced , (float )shooter .posX , (float )shooter .posY , (float )shooter .posZ );
776+ playShotSound (world , silenced , (float )shooter .posX , (float )shooter .posY , (float )shooter .posZ );
711777
712778 soundDelay = type .shootSoundLength ;
713779 }
0 commit comments