Search in sources :

Example 6 with TargetPoint

use of cpw.mods.fml.common.network.NetworkRegistry.TargetPoint 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;
    }
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) PacketSpawnParticle(pneumaticCraft.common.network.PacketSpawnParticle) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint) TargetPoint(cpw.mods.fml.common.network.NetworkRegistry.TargetPoint) PacketPlaySound(pneumaticCraft.common.network.PacketPlaySound) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityItem(net.minecraft.entity.item.EntityItem) PacketSetEntityMotion(pneumaticCraft.common.network.PacketSetEntityMotion) EntityFireball(net.minecraft.entity.projectile.EntityFireball)

Aggregations

TargetPoint (cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)6 PlayerPointer (riskyken.armourersWorkshop.common.data.PlayerPointer)2 SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)1 FMLProxyPacket (cpw.mods.fml.common.network.internal.FMLProxyPacket)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 EntityFireball (net.minecraft.entity.projectile.EntityFireball)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 PacketPlaySound (pneumaticCraft.common.network.PacketPlaySound)1 PacketSetEntityMotion (pneumaticCraft.common.network.PacketSetEntityMotion)1 PacketSpawnParticle (pneumaticCraft.common.network.PacketSpawnParticle)1 MessageServerEntitySkinData (riskyken.armourersWorkshop.common.network.messages.server.MessageServerEntitySkinData)1 MessageServerSkinInfoUpdate (riskyken.armourersWorkshop.common.network.messages.server.MessageServerSkinInfoUpdate)1 MessageServerSkinWardrobeUpdate (riskyken.armourersWorkshop.common.network.messages.server.MessageServerSkinWardrobeUpdate)1 ItemJetpack (tonius.simplyjetpacks.item.ItemPack.ItemJetpack)1 Jetpack (tonius.simplyjetpacks.item.meta.Jetpack)1