Skip to content

Commit c5d8d71

Browse files
committed
Fix #910
1 parent 1ac44e2 commit c5d8d71

File tree

9 files changed

+125
-47
lines changed

9 files changed

+125
-47
lines changed

src/main/java/com/flansmod/apocalypse/common/entity/EntityFlansModShooter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private void shoot(ItemStack stack, GunType gunType, World world, ItemStack bull
279279
Vector3f direction = new Vector3f(target.posX - posX, (target.posY + target.getEyeHeight()) - (posY + getEyeHeight()), target.posZ - posZ).normalise(null);
280280
Vector3f.add(direction, new Vector3f(rand.nextFloat() * direction.x * inaccuracy, rand.nextFloat() * direction.y * inaccuracy, rand.nextFloat() * direction.z * inaccuracy), direction);
281281
ItemShootable shootableItem = (ItemShootable)bulletStack.getItem();
282-
shootableItem.Shoot(world,
282+
shootableItem.shoot(world,
283283
origin,
284284
direction,
285285
gunType.getDamage(stack),

src/main/java/com/flansmod/client/ClientEventHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
1717
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
1818
import net.minecraftforge.fml.common.gameevent.TickEvent;
19+
import net.minecraftforge.fml.relauncher.Side;
20+
import net.minecraftforge.fml.relauncher.SideOnly;
1921

2022
import com.flansmod.client.model.InstantBulletRenderer;
2123
import com.flansmod.client.model.RenderFlag;
@@ -52,6 +54,7 @@ public void renderTick(TickEvent.RenderTickEvent event)
5254
}
5355

5456
@SubscribeEvent
57+
@SideOnly(Side.CLIENT)
5558
public void clientTick(TickEvent.ClientTickEvent event)
5659
{
5760
switch(event.phase)

src/main/java/com/flansmod/common/driveables/EntityDriveable.java

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,11 @@ public void updateKeyHeldState(int key, boolean held)
510510
}
511511
switch(key)
512512
{
513-
case 9: leftMouseHeld = held;
513+
case 9:
514+
leftMouseHeld = held;
514515
break;
515-
case 8: rightMouseHeld = held;
516+
case 8:
517+
rightMouseHeld = held;
516518
break;
517519
}
518520
}
@@ -553,7 +555,9 @@ private boolean driverIsCreative()
553555
if(driver != null)
554556
{
555557
return driver.capabilities.isCreativeMode;
556-
} else {
558+
}
559+
else
560+
{
557561
return false;
558562
}
559563
}
@@ -564,7 +568,8 @@ public EntityPlayer getDriver()
564568
{
565569
return ((EntityPlayer)seats[0].getControllingPassenger());
566570
}
567-
else {
571+
else
572+
{
568573
return null;
569574
}
570575
}
@@ -573,6 +578,7 @@ private void shootEach(DriveableType type, DriveablePosition shootPoint, int cur
573578
{
574579
//Rotate the gun vector to global axes
575580
Vector3f gunVec = getOrigin(shootPoint);
581+
Vector3f globalGunVec = Vector3f.add(new Vector3f(posX, posY, posZ), gunVec, null);
576582
Vector3f lookVector = getLookVector(shootPoint);
577583

578584
//If its a pilot gun, then it is using a gun type, so do the following
@@ -607,26 +613,28 @@ private void shootEach(DriveableType type, DriveablePosition shootPoint, int cur
607613
{
608614
for(int i = 0; i < gunType.numBullets * shootableType.numBullets; i++)
609615
{
610-
List<BulletHit> hits = FlansModRaytracer.Raytrace(world, driver, false, null, gunVec, lookVector, 0);
616+
List<BulletHit> hits = FlansModRaytracer.Raytrace(world, driver, false, null, globalGunVec, lookVector, 0);
611617
Entity victim = null;
612-
Vector3f hitPos = Vector3f.add(gunVec, lookVector, null);
618+
Vector3f hitPos = Vector3f.add(globalGunVec, lookVector, null);
613619
BulletHit firstHit = null;
614620
if(!hits.isEmpty())
615621
{
616622
firstHit = hits.get(0);
617-
hitPos = Vector3f.add(gunVec, (Vector3f)lookVector.scale(firstHit.intersectTime), null);
623+
hitPos = Vector3f.add(globalGunVec, (Vector3f)lookVector.scale(firstHit.intersectTime), null);
618624
victim = firstHit.GetEntity();
619625
}
620626

621627
if(FlansMod.DEBUG && world.isRemote)
622628
{
623-
world.spawnEntity(new EntityDebugDot(world, gunVec, 100, 1.0f, 1.0f, 1.0f));
629+
world.spawnEntity(new EntityDebugDot(world, globalGunVec, 100, 1.0f, 1.0f, 1.0f));
624630
}
625631

626632
if(driver != null)
627633
{
628-
ShotData shotData = new InstantShotData(-1, EnumHand.MAIN_HAND, type, shootableType, driver, gunVec, firstHit, hitPos, gunType.damage, i < gunType.numBullets * shootableType.numBullets - 1, false);
629-
((ItemGun)gunType.item).ServerHandleShotData(null, -1, world, this, false, shotData);
634+
ShotData shotData = new InstantShotData(-1, EnumHand.MAIN_HAND, type, shootableType, driver,
635+
globalGunVec, firstHit, hitPos, gunType.damage,
636+
i < gunType.numBullets * shootableType.numBullets - 1, false);
637+
((ItemGun)gunType.item).handleDriveableShotData(shootableStack, -1, world, this, false, shotData);
630638
}
631639
}
632640
}
@@ -636,7 +644,7 @@ private void shootEach(DriveableType type, DriveablePosition shootPoint, int cur
636644
if(driver != null)
637645
{
638646
ShotData shotData = new SpawnEntityShotData(-1, EnumHand.MAIN_HAND, type, shootableType, driver, lookVector);
639-
((ItemGun)gunType.item).ServerHandleShotData(null, -1, world, this, false, shotData);
647+
((ItemGun)gunType.item).handleDriveableShotData(shootableStack, -1, world, this, false, shotData);
640648
}
641649
}
642650

@@ -670,7 +678,7 @@ private void shootEach(DriveableType type, DriveablePosition shootPoint, int cur
670678
ItemStack bulletStack = driveableData.getStackInSlot(slot);
671679
ItemBullet bulletItem = (ItemBullet)bulletStack.getItem();
672680
EntityShootable bulletEntity = bulletItem.getEntity(world,
673-
new Vec3d(posX + gunVec.x, posY + gunVec.y, posZ + gunVec.z),
681+
new Vec3d(globalGunVec.x, globalGunVec.y, globalGunVec.z),
674682
axes.getYaw(),
675683
axes.getPitch(),
676684
motionX,
@@ -729,7 +737,7 @@ private void shootEach(DriveableType type, DriveablePosition shootPoint, int cur
729737
ItemStack bulletStack = driveableData.getStackInSlot(slot);
730738
ItemBullet bulletItem = (ItemBullet)bulletStack.getItem();
731739
EntityShootable bulletEntity = bulletItem.getEntity(world,
732-
Vector3f.add(new Vector3f(posX, posY, posZ), gunVec, null),
740+
globalGunVec,
733741
lookVector,
734742
(EntityLivingBase)seats[0].getControllingPassenger(),
735743
spread,
@@ -904,7 +912,7 @@ else if(passenger instanceof EntityWheel)
904912
{
905913
int eventOutcome = ForgeHooks.onBlockBreakEvent(world,
906914
driverIsCreative() ? GameType.CREATIVE : getDriver().capabilities.allowEdit
907-
? GameType.SURVIVAL : GameType.ADVENTURE,
915+
? GameType.SURVIVAL : GameType.ADVENTURE,
908916
(EntityPlayerMP)getDriver(), new BlockPos(blockX, blockY, blockZ));
909917
cancelled = eventOutcome == -1;
910918
}

src/main/java/com/flansmod/common/guns/ItemBullet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public InfoType getInfoType()
8686
}
8787

8888
@Override
89-
public void Shoot(World world, Vector3f origin, Vector3f direction, float damageModifier, float spreadModifier, float speedModifier, InfoType shotFrom, EntityLivingBase shooter)
89+
public void shoot(World world, Vector3f origin, Vector3f direction, float damageModifier, float spreadModifier, float speedModifier, InfoType shotFrom, EntityLivingBase shooter)
9090
{
9191
world.spawnEntity(getEntity(world, shooter, spreadModifier, damageModifier, speedModifier, false, shotFrom));
9292
}

src/main/java/com/flansmod/common/guns/ItemGrenade.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void addInformation(ItemStack stack, World world, List<String> lines, ITo
156156
}
157157
}
158158

159-
public void Shoot(World world,
159+
public void shoot(World world,
160160
Vector3f origin,
161161
Vector3f direction,
162162
float damageModifier,

src/main/java/com/flansmod/common/guns/ItemGun.java

Lines changed: 89 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.flansmod.common.FlansMod;
6363
import com.flansmod.common.PlayerData;
6464
import com.flansmod.common.PlayerHandler;
65+
import com.flansmod.common.driveables.EntityDriveable;
6566
import com.flansmod.common.guns.ShotData.InstantShotData;
6667
import com.flansmod.common.guns.ShotData.SpawnEntityShotData;
6768
import 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
}

src/main/java/com/flansmod/common/guns/ItemShootable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public abstract EntityShootable getEntity(World world, EntityLivingBase player,
3939
float bulletSpread, float damage, float bulletSpeed, boolean b,
4040
InfoType shotFrom);
4141

42-
public abstract void Shoot(World world,
42+
public abstract void shoot(World world,
4343
Vector3f origin,
4444
Vector3f direction,
4545
float damageModifier,

src/main/java/com/flansmod/common/network/PacketHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object
153153
}
154154
}
155155

156+
@SideOnly(Side.CLIENT)
156157
public void handleClientPackets()
157158
{
158159
for(PacketBase packet = receivedPacketsClient.poll(); packet != null; packet = receivedPacketsClient.poll())

0 commit comments

Comments
 (0)