use of pneumaticCraft.common.network.PacketSetEntityMotion in project PneumaticCraft by MineMaarten.
the class TileEntityAirCannon method fire.
private synchronized boolean fire() {
Entity itemShot = getCloseEntityIfUpgraded();
if (getPressure(ForgeDirection.UNKNOWN) >= PneumaticValues.MIN_PRESSURE_AIR_CANNON && (itemShot != null || inventory[0] != null)) {
double[] velocity = getVelocityVector(heightAngle, rotationAngle, getForce());
addAir((int) (-500 * getForce()), ForgeDirection.UNKNOWN);
boolean shootingInventory = false;
if (itemShot == null) {
shootingInventory = true;
itemShot = getPayloadEntity();
if (itemShot instanceof EntityItem) {
inventory[0] = null;
if (getUpgrades(ItemMachineUpgrade.UPGRADE_BLOCK_TRACKER) > 0) {
trackedItems.add((EntityItem) itemShot);
}
} else {
inventory[0].stackSize--;
if (inventory[0].stackSize <= 0)
inventory[0] = null;
}
} else if (itemShot instanceof EntityPlayer) {
EntityPlayerMP entityplayermp = (EntityPlayerMP) itemShot;
if (entityplayermp.playerNetServerHandler.func_147362_b().isChannelOpen()) {
entityplayermp.setPositionAndUpdate(xCoord + 0.5D, yCoord + 1.8D, zCoord + 0.5D);
}
}
if (itemShot.isRiding()) {
itemShot.mountEntity((Entity) null);
}
itemShot.setPosition(xCoord + 0.5D, yCoord + 1.8D, zCoord + 0.5D);
NetworkHandler.sendToAllAround(new PacketSetEntityMotion(itemShot, velocity[0], velocity[1], velocity[2]), new TargetPoint(worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 64));
if (itemShot instanceof EntityFireball) {
velocity[0] *= 0.05D;
velocity[1] *= 0.05D;
velocity[2] *= 0.05D;
}
itemShot.motionX = velocity[0];
itemShot.motionY = velocity[1];
itemShot.motionZ = velocity[2];
itemShot.onGround = false;
itemShot.isCollided = false;
itemShot.isCollidedHorizontally = false;
itemShot.isCollidedVertically = false;
if (itemShot instanceof EntityLivingBase)
((EntityLivingBase) itemShot).setJumping(true);
if (shootingInventory && !worldObj.isRemote)
worldObj.spawnEntityInWorld(itemShot);
for (int i = 0; i < 10; i++) {
double velX = velocity[0] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
double velY = velocity[1] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
double velZ = velocity[2] * 0.4D + (rand.nextGaussian() - 0.5D) * 0.05D;
NetworkHandler.sendToAllAround(new PacketSpawnParticle("largesmoke", xCoord + 0.5D, yCoord + 0.7D, zCoord + 0.5D, velX, velY, velZ), worldObj);
}
NetworkHandler.sendToAllAround(new PacketPlaySound(Sounds.CANNON_SOUND, xCoord, yCoord, zCoord, 1.0F, rand.nextFloat() / 4F + 0.75F, true), worldObj);
return true;
} else {
return false;
}
}
Aggregations